#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int n,q,a,d[300005];
set<pii> s;
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;
cin>>q;
while(q--)
{
char c;
cin>>c;
if(c=='F')
{
int poz;
cin>>poz;
if(poz==a)
{
cout<<0<<'\n';
continue;
}
int st=a-1;
int dr=a+1;
int cnt=1;
while(true)
{
cnt++;
if(d[st]<d[dr])
{
if(st==poz)
{
cout<<cnt-1<<'\n';
break;
}
st--;
}
else
{
if(dr==poz)
{
cout<<cnt-1<<'\n';
break;
}
dr++;
}
}
}
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});
}
}
}
return 0;
}
Compilation message
cake.cpp: In function 'int main()':
cake.cpp:62:17: warning: unused variable 'old' [-Wunused-variable]
62 | int old=d[poz];
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
8 ms |
340 KB |
Output is correct |
5 |
Correct |
31 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
443 ms |
3460 KB |
Output is correct |
2 |
Correct |
228 ms |
2480 KB |
Output is correct |
3 |
Correct |
285 ms |
3124 KB |
Output is correct |
4 |
Correct |
135 ms |
2380 KB |
Output is correct |
5 |
Correct |
470 ms |
5272 KB |
Output is correct |
6 |
Correct |
391 ms |
5296 KB |
Output is correct |
7 |
Correct |
328 ms |
5432 KB |
Output is correct |
8 |
Correct |
190 ms |
5172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2076 ms |
5708 KB |
Time limit exceeded |
2 |
Execution timed out |
2061 ms |
5652 KB |
Time limit exceeded |
3 |
Execution timed out |
2059 ms |
5728 KB |
Time limit exceeded |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Execution timed out |
2094 ms |
13164 KB |
Time limit exceeded |
6 |
Execution timed out |
2090 ms |
13160 KB |
Time limit exceeded |
7 |
Execution timed out |
2092 ms |
13240 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
468 KB |
Output is correct |
2 |
Correct |
75 ms |
620 KB |
Output is correct |
3 |
Correct |
819 ms |
3368 KB |
Output is correct |
4 |
Correct |
830 ms |
3132 KB |
Output is correct |
5 |
Correct |
168 ms |
676 KB |
Output is correct |
6 |
Execution timed out |
2075 ms |
4972 KB |
Time limit exceeded |
7 |
Correct |
548 ms |
1736 KB |
Output is correct |
8 |
Correct |
261 ms |
6936 KB |
Output is correct |
9 |
Execution timed out |
2096 ms |
13324 KB |
Time limit exceeded |
10 |
Correct |
557 ms |
1408 KB |
Output is correct |
11 |
Execution timed out |
2066 ms |
5076 KB |
Time limit exceeded |
12 |
Execution timed out |
2080 ms |
11120 KB |
Time limit exceeded |
13 |
Execution timed out |
2080 ms |
13392 KB |
Time limit exceeded |