# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
595536 | UncoolAnon | Cake (CEOI14_cake) | C++14 | 4 ms | 596 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
using namespace std;
int n,si;
set<pii> order;
vector<int> a;
int query(int t){
int l=si,r=si;
while(t<l||t>r){
if(l==0) ++r;
else if(r==n-1) --l;
else if(a[l-1]<a[r+1]) --l;
else ++r;
}
return r-l;
}
void update(int i,int e){
order.erase(mp(-a[i],i));
vector<int> hold;
while(e--){
hold.push_back(order.begin()->second);
order.erase(order.begin());
}
int mn=1e9;
for(int&x:hold){
++a[x];
mn=min(mn,a[x]-1);
order.insert(mp(-a[x],x));
}
order.insert(mp(-mn,i));
a[i]=mn;
return ;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
cin>>n>>si; --si; a.resize(n);
for(int i=0;i<n;++i){
cin>>a[i];
order.insert(mp(-a[i],i));
}
int q;
cin>>q;
while(q--){
char x;
cin>>x ;
if(x=='F'){
int y;
cin>>y; --y;
cout<<query(y)<<'\n';
}
else{
int i,e;
cin>>i>>e; --i;
update(i,e);
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |