Submission #871076

#TimeUsernameProblemLanguageResultExecution timeMemory
871076Ahmed57Weirdtree (RMI21_weirdtree)C++17
13 / 100
85 ms38552 KiB
#include <bits/stdc++.h> using namespace std; #define int long long long long arr[300001],n; struct node{ long long ma =0 , id = 0 , sum = 0; }seg[1200001]; node combine(node a,node b){ node res; res.sum = a.sum+b.sum; if(a.ma>=b.ma)res.ma = a.ma , res.id = a.id; else res.ma = b.ma , res.id = b.id; return res; } void build(int p,int l,int r){ if(l==r){ seg[p].ma = arr[l]; seg[p].id = l; seg[p].sum = arr[l]; return ; } int md = (l+r)/2; build(p*2,l,md); build(p*2+1,md+1,r); seg[p] =combine(seg[p*2],seg[p*2+1]); } void update(int p,int l,int r,int idx,int val,int op){ if(l==r){ if(op==0){ seg[p].ma = val; seg[p].sum = val; }else{ seg[p].ma = max(0ll,seg[p].ma+val); seg[p].sum = max(0ll,seg[p].sum+val); } return ; } int md = (l+r)/2; if(idx<=md)update(p*2,l,md,idx,val,op); else update(p*2+1,md+1,r,idx,val,op); seg[p] = combine(seg[p*2],seg[p*2+1]); } node query(int p,int l,int r,int lq,int rq){ if(l>=lq&&r<=rq){ return seg[p]; } int md = (l+r)/2; if(rq<=md)return query(p*2,l,md,lq,rq); else if(lq>md)return query(p*2+1,md+1,r,lq,rq); else return combine(query(p*2,l,md,lq,rq),query(p*2+1,md+1,r,lq,rq)); } void initialise(int32_t N, int32_t Q,int32_t h[]){ n = N; for(int i = 1;i<=n;i++){ arr[i] = h[i]; } build(1,1,n); } void cut(int32_t l, int32_t r, int32_t k){ node res = query(1,1,n,l,r); update(1,1,n,res.id,-1,1); } void magic(int32_t i, int32_t x){ update(1,1,n,i,x,0); } long long inspect(int32_t l, int32_t r){ node res = query(1,1,n,l,r); return res.sum; } /* signed main(){ ios_base::sync_with_stdio(false);cin.tie(0); initialise(6,1,{0,1,2,3,1,2,3}); cut(1,6,3); cout<<inspect(1,6)<<endl; }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...