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 45haotong @ 2024-07-27 18:12:28

@lihongqian__int128

好玩个得(der)

(⊙o⊙)…


by 45haotong @ 2024-07-27 18:13:12

无语


by Ice_rnfmabj @ 2024-07-27 21:43:07

@45haotong 这就是那些大佬的乐趣,你别管。

%你们所有人!


by Braised_fish @ 2024-07-29 22:39:59

6

#include <iostream>
#include <cstring>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
int a,b,c;  
scanf("%d %d",&a,&b);
c=a+b;
printf("%d",c); 
    return 0;
}

上一页 |