RE 0pts求助

P1001 A+B Problem

crz_qwq @ 2024-07-25 12:42:50

rt

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n=2;
int tr[N<<2];
void pushup(int p){tr[p]=tr[p<<1]+tr[p<<1|1];}
void update(int p,int pl,int pr,int x,int d)
{
    if(pl==x&&pr==x)
    {
        tr[p]+=d;
        return ;
    }
    int mid=(pl+pr)>>1;
    update(p<<1,pl,mid,x,d);
    update(p<<1|1,mid+1,pr,x,d);
}
int query(int p,int pl,int pr,int L,int R)
{
    if(L<=pl&&pr<=R)
        return tr[p];
    if(R<pl||pr<L)
        return 0;
    int mid=(pl+pr)>>1;
    return query(p<<1,pl,mid,L,R)+query(p<<1|1,mid+1,pr,L,R);
}
vector<int>edge[N];
int son[N],sz[N],fa[N],dep[N];
int dfn[N],rnk[N],top[N],id;
void dfs1(int u,int ft)
{
    sz[u]=1;
    fa[u]=ft;
    dep[u]=dep[ft]+1;
    son[u]=-1;
    for(auto &v:edge[u])
    {
        if(v==ft)
            continue;
        dfs1(v,u);
        sz[u]+=sz[v];
        if(sz[v]>sz[son[u]])
            son[u]=v;
    }
}
void dfs2(int u,int t)
{
    top[u]=t;
    dfn[u]=++id;
    rnk[id]=u;
    dfs2(son[u],t);
    for(auto &v:edge[u])
    {
        if(v==fa[u])
            continue;
        dfs2(v,v);
    }
}
int qrange(int x,int y)
{
    int res=0;
    while(top[x]!=top[y])
    {
        if(dep[top[x]]<dep[top[y]])
            swap(x,y);
        res+=query(1,1,n,dfn[top[x]],dfn[x]);
        x=fa[top[x]];
    }
    return res+query(1,1,n,dfn[x],dfn[y]);
}
signed main()
{
    int x,y;
    cin>>x>>y;
    edge[1].emplace_back(2);
    edge[2].emplace_back(1);
    dfs1(1,0);
    dfs2(1,1);
    update(1,1,n,dfn[1],x);
    update(1,1,n,dfn[2],y);
    cout<<qrange(1,2);
}

by Stars_visitor_tyw @ 2024-07-25 13:10:35

@ran_qwq 哦看到了thx已关


by M15388049303 @ 2024-07-25 13:39:24

@crz_qwq 这道题用int足够了。

#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
    cin>>a>>b;
    cout<<a+b<<endl;
}

by qiaochu @ 2024-07-25 14:21:00

直接int a,b;

cin>>a>>b;

cout<<a+b;

头文件我就懒得写了


by lihongqian__int128 @ 2024-07-25 14:44:21

@crz_qwq 我的树剖也挂了……分块也挂了……


by crz_qwq @ 2024-07-25 14:45:30

@lihongqian__int128 %%%


by crz_qwq @ 2024-07-27 13:24:18

@M15388049303 你要不看看我写的是什么


by JOE_ZengYuQiao_0928 @ 2024-07-27 13:46:45

@crz_qwq @crz_qwq @crz_qwq @crz_qwq @crz_qwq @crz_qwq @crz_qwq @crz_qwq @crz_qwq @crz_qwq @crz_qwq @crz_qwq @crz_qwq @crz_qwq @crz_qwq @crz_qwq %%%


by 45haotong @ 2024-07-27 13:47:27


by 45haotong @ 2024-07-27 13:48:40

有必要吗?


by lihongqian__int128 @ 2024-07-27 16:20:53

@45haotong 有,好玩(


上一页 | 下一页