P1001 A+B Problem

makingtimefor @ 2024-03-10 19:48:41

重中之重


by donnieguo @ 2024-03-10 20:02:16

wyy,jbl


by xingcode @ 2024-03-17 17:50:45

wyy,jbl

by RSDL @ 2024-04-15 15:09:21

wyy,jbl

by aochiao @ 2024-05-02 17:33:05

@makingtimefor 难啥呀??


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

by crz_qwq @ 2024-11-13 10:38:10

@aochiao bu shi ni xiang de na mo jian dan

zhe shi yi dao fei chang fu za de jie lun ti

ru guo bu xiang yong jie lun guo ke yi shi shi zhe ge dai ma

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
mt19937 rng(time(0));
int root,tot;
struct node{
    int val,pri,ls,rs,sz;
    int sum,maxn;
    int rev,add;
}tr[N];
int New(int x)
{
    ++tot;
    tr[tot].sum=tr[tot].maxn=tr[tot].val=x;
    tr[tot].pri=rng();
    tr[tot].rev=tr[tot].add=tr[tot].ls=tr[tot].rs=0;
    tr[tot].sz=1;
    return tot;
}
void pushup(int p)
{
    tr[p].sum=tr[tr[p].ls].sum+tr[tr[p].rs].sum+tr[p].val;
    tr[p].maxn=tr[p].val;
    if(tr[p].ls)tr[p].maxn=max(tr[p].maxn,tr[tr[p].ls].maxn);
    if(tr[p].rs)tr[p].maxn=max(tr[p].maxn,tr[tr[p].rs].maxn);
    tr[p].sz=tr[tr[p].ls].sz+tr[tr[p].rs].sz+1;
}
void addtag(int p,int d)
{
    tr[p].val+=d;
    tr[p].add+=d;
    tr[p].sum+=tr[p].sz*d;
    tr[p].maxn+=d;
}
void pushdown(int p)
{
    if(tr[p].rev)
    {
        swap(tr[p].ls,tr[p].rs);
        if(tr[p].ls)tr[tr[p].ls].rev^=1;
        if(tr[p].rs)tr[tr[p].rs].rev^=1;
        tr[p].rev=0;
    }
    if(tr[p].add)
    {
        if(tr[p].ls)addtag(tr[p].ls,tr[p].add);
        if(tr[p].rs)addtag(tr[p].rs,tr[p].add);
        tr[p].add=0;
    }   
}
void split(int p,int k,int &L,int &R)
{
    if(!p)
    {
        L=R=0;
        return ;
    }
    pushdown(p);
    if(tr[tr[p].ls].sz<k)
    {
        L=p;
        split(tr[p].rs,k-tr[tr[p].ls].sz-1,tr[p].rs,R);
    }
    else
    {
        R=p;
        split(tr[p].ls,k,L,tr[p].ls);
    }
    pushup(p);
}
int merge(int L,int R)
{
    if(!L||!R)
        return L|R;
    if(tr[L].pri<=tr[R].pri)
    {
        pushdown(L);
        tr[L].rs=merge(tr[L].rs,R);
        pushup(L);
        return L;
    }
    pushdown(R);
    tr[R].ls=merge(L,tr[R].ls);
    pushup(R);
    return R;
}
void REVERSE(int l,int r)
{
    int L,R,p; 
    split(root,l-1,L,R);
    split(R,r-l+1,R,p);
    tr[R].rev^=1;
    root=merge(L,merge(R,p)); 
}
void ADD(int l,int r,int d)
{
    int L,R,p;
    split(root,l-1,L,R);
    split(R,r-l+1,R,p);
    addtag(R,d);
    root=merge(L,merge(R,p));
}
int GETSUM(int l,int r)
{
    int L,R,p;
    split(root,l-1,L,R);
    split(R,r-l+1,R,p);
    int res=tr[R].sum;
    root=merge(L,merge(R,p));
    return res;
} 
int GETMAX(int l,int r)
{
    int L,R,p;
    split(root,l-1,L,R);
    split(R,r-l+1,R,p);
    int res=tr[R].maxn;
    root=merge(L,merge(R,p));
    return res;
}
signed main()
{
    int x,y;
    cin>>x>>y;
    for(int i=1;i<=4;++i)
        root=merge(root,New(0));
    ADD(1,2,x);
    ADD(3,4,y);
    REVERSE(1,2);
    REVERSE(3,4);
    cout<<GETSUM(1,2)-GETMAX(1,2)+GETSUM(3,4)-GETMAX(3,4);
}

|