Submission #676458

#TimeUsernameProblemLanguageResultExecution timeMemory
676458vjudge1Cake (CEOI14_cake)C++17
51.67 / 100
2093 ms17096 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; int n,q,a,d[300005],where[300005]; set<pii> s; 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}); } d[0]=d[n+1]=1e9; compute(); cin>>q; while(q--) { char c; cin>>c; if(c=='F') { int poz; cin>>poz; cout<<where[poz]-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}); for(auto i:mypoz) { s.erase({d[i],i}); d[i]++; s.insert({d[i],i}); } compute(); } } return 0; }

Compilation message (stderr)

cake.cpp: In function 'int main()':
cake.cpp:55:17: warning: unused variable 'old' [-Wunused-variable]
   55 |             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...