Submission #613654

#TimeUsernameProblemLanguageResultExecution timeMemory
613654andrei_boaca케이크 (CEOI14_cake)C++14
100 / 100
1683 ms21972 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; int n,q,a,d[300005],where[300005],arb[1200005]; int nr=0; set<pii> s; void update(int nod,int st,int dr,int poz,int val) { if(st==dr) { arb[nod]=val; return; } int mij=(st+dr)/2; if(poz<=mij) update(nod*2,st,mij,poz,val); else update(nod*2+1,mij+1,dr,poz,val); arb[nod]=max(arb[nod*2],arb[nod*2+1]); } int query(int nod,int st,int dr,int a,int b) { if(st>=a&&dr<=b) return arb[nod]; int rez=0; int mij=(st+dr)/2; if(a<=mij) rez=max(rez,query(nod*2,st,mij,a,b)); if(b>mij) rez=max(rez,query(nod*2+1,mij+1,dr,a,b)); return rez; } void compute() { where[a]=1; int st=a-1; int dr=a+1; int cnt=1; while(st>0||dr<=n) { cnt++; if(d[st]<d[dr]) { where[st]=cnt; st--; } else { where[dr]=cnt; dr++; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n>>a; for(int i=1;i<=n;i++) { cin>>d[i]; s.insert({d[i],i}); update(1,0,n+1,i,d[i]); } d[0]=d[n+1]=1e9; update(1,0,n+1,0,d[0]); update(1,0,n+1,n+1,d[n+1]); compute(); cin>>q; while(q--) { char c; cin>>c; if(c=='F') { int poz; cin>>poz; if(nr<1000) { cout<<where[poz]-1<<'\n'; continue; } int maxim=0; if(poz==a) { cout<<0<<'\n'; continue; } if(poz<a) { maxim=query(1,0,n+1,poz,a-1); int rgt=n+1; int st=a+1; int dr=n+1; while(st<=dr) { int mij=(st+dr)/2; int val=query(1,0,n+1,a+1,mij); if(val>maxim) { rgt=mij; dr=mij-1; } else st=mij+1; } cout<<rgt-poz-1<<'\n'; } else { maxim=query(1,0,n+1,a+1,poz); int lft=0; int st=0; int dr=a-1; while(st<=dr) { int mij=(st+dr)/2; int val=query(1,0,n+1,mij,a-1); if(val>maxim) { lft=mij; st=mij+1; } else dr=mij-1; } cout<<poz-lft-1<<'\n'; } } else { int poz,val; cin>>poz>>val; int old=d[poz]; vector<int> mypoz; auto it=prev(s.end()); int cnt=0; int myval=0; while(cnt+1<val) { cnt++; int p=(*it).second; myval=(*it).first; mypoz.push_back(p); it--; } if(myval==0) myval=(*it).first+1; s.erase({d[poz],poz}); d[poz]=myval; s.insert({d[poz],poz}); update(1,0,n+1,poz,d[poz]); for(auto i:mypoz) { s.erase({d[i],i}); d[i]++; s.insert({d[i],i}); update(1,0,n+1,i,d[i]); } if(nr<100) { nr++; compute(); } else nr=10000; } } return 0; }

Compilation message (stderr)

cake.cpp: In function 'int main()':
cake.cpp:135:17: warning: unused variable 'old' [-Wunused-variable]
  135 |             int old=d[poz];
      |                 ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...