Submission #992574

#TimeUsernameProblemLanguageResultExecution timeMemory
992574AbitoWeirdtree (RMI21_weirdtree)C++17
13 / 100
63 ms38644 KiB
#include "weirdtree.h" #include <bits/stdc++.h> #define ll long long using namespace std; const int NN=3e5+5; ll n,a[NN]; struct node{ ll mx,sum,idx; }; node seg[4*NN+5]; node merge(node x,node y){ node z; z.mx=max(x.mx,y.mx); z.sum=x.sum+y.sum; if (x.mx>=y.mx) z.idx=x.idx; if (x.mx<y.mx) z.idx=y.idx; return z; } void build(int x,int l,int r){ if (l==r){ seg[x]={a[l],a[l],l}; return; }int mid=(l+r)/2; build(x*2,l,mid); build(x*2+1,mid+1,r); seg[x]=merge(seg[x*2],seg[x*2+1]); return; } void edit(int x,int l,int r,int idx,int d){ if (l==r){ seg[x].mx+=d; seg[x].sum+=d; return; }int mid=(l+r)/2; if (idx<=mid) edit(x*2,l,mid,idx,d); else edit(x*2+1,mid+1,r,idx,d); seg[x]=merge(seg[x*2],seg[x*2+1]); } node query(int x,int l,int r,int lx,int rx){ if (l>=lx && r<=rx) return seg[x]; if (l>rx || r<lx) return {LLONG_MIN,0,-1}; int mid=(l+r)/2; return merge(query(x*2,l,mid,lx,rx),query(x*2+1,mid+1,r,lx,rx)); } void initialise(int N, int Q, int h[]) { n=N; for (int i=1;i<=n;i++) a[i]=h[i]; build(1,1,n); return; } void cut(int l, int r, int k) { int idx=query(1,1,n,l,r).idx; if (a[idx]) edit(1,1,n,idx,-1),a[idx]--; return; } void magic(int i, int x) { edit(1,1,n,i,x-a[i]); a[i]=x; return; } long long int inspect(int l, int r) { return query(1,1,n,l,r).sum; }
#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...