Submission #1284162

#TimeUsernameProblemLanguageResultExecution timeMemory
1284162trandangquangTriangle Collection (CCO23_day2problem3)C++20
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;

#define foru(i,a,b) for(int i=(a); i<=(b); ++i)
#define ford(i,a,b) for(int i=(a); i>=(b); --i)
#define rep(i,a) for(int i=0; i<(a); ++i)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define bit(s,i) (((s)>>(i))&1)
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define ll long long
#define _ << " " <<

template <class X, class Y> bool maxi(X &x, Y y){return x<y?x=y,true:false;}
template <class X, class Y> bool mini(X &x, Y y){return x>y?x=y,true:false;}

const int N=2e5+5;

int n,q,c[N]; ll tot;

void init(){
    cin>>n>>q;
    foru(i,1,n) cin>>c[i], tot+=c[i];
}

struct Node{
    ll open,close,num;
    Node(){
        open=close=num=0;
    }
} st[N<<3];

Node combine(Node a, Node b){
    Node tmp;
    ll t=min(a.open,b.close);
    tmp.num=a.num+b.num+t;
    tmp.open=a.open-t+b.open;
    tmp.close=a.close+b.close-t;
    return tmp;
}

void upd(int x, ii val){
    int id=1, l=1, r=2*n-1;
    while(true){
        if(l==r) break;
        int mid=(l+r)>>1;
        if(x<=mid){
            r=mid;
            id=id<<1;
        } else{
            l=mid+1;
            id=id<<1|1;
        }
    }
    int &t=st[id].num;
    st[id].open+=val.fi+t;
    st[id].close+=val.se+t;

    t=min(st[id].open, st[id].close);
    st[id].open-=t;
    st[id].close-=t;

    while(id>1){
        id/=2;
        st[id]=combine(st[id<<1], st[id<<1|1]);
    }
}

void buildSegtree(){
    foru(i,1,n){
        int open=c[i]&1, close=c[i]/2;
        upd(i,{open,0});
        upd(2*i-1,{0,close});
    }
}

void answerQueries(){
    foru(_q,1,q){
        int l,d; cin>>l>>d;

        int lstOpen=c[l]&1, lstClose=c[l]/2;
        c[l]+=d; tot+=d;
        int open=c[l]&1, close=c[l]/2;

        upd(l,{open-lstOpen,0});
        upd(2*l-1,{0,close-lstClose});

        cout<<st[1].num + (tot-st[1].open-st[1].num*3)/3<<'\n';
    }
}

void process(){
    init();
    buildSegtree();
    answerQueries();
}

int main(){
    #ifdef doramii
        freopen("test.inp","r",stdin);
        freopen("test.out","w",stdout);
    #endif // doramii

    cin.tie(0)->sync_with_stdio(0);

    process();
}

Compilation message (stderr)

Main.cpp: In function 'void upd(int, std::pair<int, int>)':
Main.cpp:59:19: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'long long int'
   59 |     int &t=st[id].num;
      |            ~~~~~~~^~~