Submission #385261

#TimeUsernameProblemLanguageResultExecution timeMemory
385261ritul_kr_singhCake (CEOI14_cake)C++17
0 / 100
2089 ms26220 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define nl << '\n' #define sp << ' ' << struct SegmentTree{ vector<int> a; int sz = 1, ID = -1e18; SegmentTree(vector<int> &v){ while(sz < (int)v.size()) sz += sz; a.resize(2*sz, ID); build(v, 0, 0, sz); } void build(vector<int> &v, int x, int lx, int rx){ if(rx-lx==1){ if(lx<(int)v.size()) a[x] = v[lx]; return; } int mx = (lx+rx)/2; build(v, 2*x+1, lx, mx); build(v, 2*x+2, mx, rx); a[x] = max(a[2*x+1], a[2*x+2]); } void update(int i, int val, int x, int lx, int rx){ if(rx-lx==1) return void(a[x] = val); int mx = (lx+rx)/2; if(i<mx) update(i, val, 2*x+1, lx, mx); else update(i, val, 2*x+2, mx, rx); a[x] = max(a[2*x+1], a[2*x+2]); } void update(int i, int val){ update(i, val, 0, 0, sz); } int get0(int r, int val, int x, int lx, int rx){ if(r<=lx) return -1; if(rx-lx==1) return (a[x] > val ? lx : -1); int mx = (lx+rx)/2; int res; if(a[2*x+2]>val){ res = get0(r, val, 2*x+2, mx, rx); if(res>=0) return res; } if(a[2*x+1]>val){ res = get0(r, val, 2*x+1, lx, mx); if(res>=0) return res; } return -1; } int get0(int r, int val){ return get0(r+1, val, 0, 0, sz); } int get1(int l, int val, int x, int lx, int rx){ if(rx<=l) return -1; if(rx-lx==1) return (a[x] > val ? lx : -1); int mx = (lx+rx)/2; int res; if(a[2*x+1]>val){ res = get1(l, val, 2*x+1, lx, mx); if(res>=0) return res; } if(a[2*x+2]>val){ res = get1(l, val, 2*x+2, mx, rx); if(res>=0) return res; } return -1; } int get1(int l, int val){ return get1(l, val, 0, 0, sz); } }; signed main(){ cin.tie(0)->sync_with_stdio(0); int n, s; cin >> n >> s; --s; vector<int> a(n); set<int> b; for(int &i : a){ cin >> i; b.insert(i *= 1e7); } SegmentTree st(a); int q, x, y; cin >> q; char type; for(int i=1; i<=q; ++i){ cin >> type >> x; --x; if(type=='E'){ cin >> y; b.erase(a[x]); auto f = b.rbegin(); for(int j=1; j<y; ++j) --f; a[x] = (*f)+1; st.update(x, a[x]); }else{ if(x==s) cout << 0 nl; else if(x>s){ if(s==0) cout << x nl; else{ int res = st.get0(s-1, a[x]) + 1; cout << x - res nl; } }else{ if(s==n-1) cout << n-1-x nl; else{ int res = st.get1(s+1, a[x]) - 1; if(res<0) res = n-1; cout << res-x nl; } } } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...