Submission #38626

#TimeUsernameProblemLanguageResultExecution timeMemory
38626MrPlanySimple game (IZhO17_game)C++14
22 / 100
189 ms6312 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e6, maxn=1e5+5; int t[N+5],a[maxn]; int n; void add(int k, int val){ while(k<=N){ t[k]+=val; k+=k&-k; } } void gosh(int a, int b, int val){ if(a>b) swap(a,b); add(a,val); add(b+1,-val); } int sum(int pos){ int s = 0; while(pos>0){ s+=t[pos]; pos-=pos&-pos; } return s; } int main(){ cin>>n; int q; cin>>q; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<n;i++) gosh(a[i],a[i+1],1); int pos, val, type; while(q--){ cin>>type; if(type==1){ cin>>pos>>val; if(pos>1) gosh(a[pos-1],a[pos],-1); if(pos<n) gosh(a[pos],a[pos+1],-1); a[pos] = val; if(pos>1) gosh(a[pos-1],a[pos],1); if(pos<n) gosh(a[pos],a[pos+1],1); } else{ cin>>pos; cout << sum(pos) << endl; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...