# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
101445 |
2019-03-19T02:14:37 Z |
ShaneOng |
Cake (CEOI14_cake) |
C++14 |
|
856 ms |
50560 KB |
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int n,st,q,arr[250009],flag;
struct node{
int s,e,m,v=0;
node *l,*r;
node(int a,int b){
s=a,e=b,m=(s+e)/2;
if(s!=e){
l=new node(s,m);
r=new node(m+1,e);
v=max(l->v,r->v);
}else{
v=arr[s];
}
}
void up(int a,int b){
if(s==e&&s==a){
v=b;
return;
}
if(a<=m)
l->up(a,b);
else
r->up(a,b);
v=max(l->v,r->v);
}
int qu(int a,int b){
if(s==a&&b==e){
return v;
}
if(b<=m)
return l->qu(a,b);
if(a>m)
return r->qu(a,b);
return max(l->qu(a,m),r->qu(m+1,e));
}
int bs1(int a){
if(s==e)
return s+(v<a);
if(a>l->v)
return r->bs1(a);
return l->bs1(a);
}
int bs2(int a){
if(s==e)
return s+(v<a);
if(a>r->v)
return l->bs1(a);
return r->bs1(a);
}
}*root[2];
int main(){
scanf("%d%d",&n,&st);
priority_queue<ii,vector<ii>,greater<ii> > pq[2];
for(int x=0;x<n;x++){
scanf("%d",&arr[x]);
if(arr[x]>n-10)
pq[flag].push(ii(arr[x],x));
}
int ctr=n;
if(st>1)
root[0]=new node(0,st-2);
if(st<n)
root[1]=new node(st,n-1);
scanf("%d",&q);
for(int x=0,b,c;x<q;x++){
char a;
scanf(" %c",&a);
if(a=='E'){
scanf("%d%d",&b,&c);
pq[flag].pop();
while(!pq[flag].empty()){
ii temp=pq[flag].top();
pq[flag].pop();
if(temp.first>ctr-c+1){
temp.first++;
if(temp.second>st){
root[1]->up(temp.second,temp.first);
}
if(temp.second<st)
root[0]->up(temp.second,temp.first);
}
pq[1-flag].push(temp);
}
if(b>st)
root[1]->up(b-1,ctr-c+2);
if(b<st)
root[0]->up(b-1,ctr-c+2);
pq[1-flag].push(ii(ctr-c+2,b-1));
flag=1-flag;
ctr++;
}else{
scanf("%d",&b);
if(b!=st){
if(b>st){
//printf("%d,%d\n",root[1]->qu(st,b-1),root[0]->bs2(root[1]->qu(st,b-1)));
printf("%d\n",(b-1-(root[0]->bs2(root[1]->qu(st,b-1))+1)));
}
if(b<st){
//printf("%d,%d\n",root[0]->qu(b-1,st-2),root[1]->bs1(root[0]->qu(b-1,st-2)));
printf("%d\n",(root[1]->bs1(root[0]->qu(b-1,st-2))-b));
}
}else
printf("0\n");
}
}
}
Compilation message
cake.cpp: In function 'int main()':
cake.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&st);
~~~~~^~~~~~~~~~~~~~~
cake.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&arr[x]);
~~~~~^~~~~~~~~~~~~~
cake.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&q);
~~~~~^~~~~~~~~
cake.cpp:73:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c",&a);
~~~~~^~~~~~~~~~
cake.cpp:76:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&b,&c);
~~~~~^~~~~~~~~~~~~~
cake.cpp:99:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&b);
~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
384 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
124 ms |
2276 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Runtime error |
7 ms |
2432 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Runtime error |
140 ms |
2496 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Incorrect |
243 ms |
1280 KB |
Output isn't correct |
5 |
Runtime error |
17 ms |
5376 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Runtime error |
12 ms |
5376 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
193 ms |
5468 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Incorrect |
267 ms |
2936 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
106 ms |
10676 KB |
Output isn't correct |
2 |
Runtime error |
41 ms |
20096 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Runtime error |
49 ms |
20036 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Runtime error |
3 ms |
384 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Incorrect |
171 ms |
25444 KB |
Output isn't correct |
6 |
Incorrect |
147 ms |
25464 KB |
Output isn't correct |
7 |
Runtime error |
103 ms |
49552 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
1152 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Runtime error |
10 ms |
1536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Runtime error |
68 ms |
10408 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Runtime error |
21 ms |
10240 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Runtime error |
5 ms |
896 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Incorrect |
169 ms |
7212 KB |
Output isn't correct |
7 |
Incorrect |
154 ms |
1912 KB |
Output isn't correct |
8 |
Incorrect |
204 ms |
10164 KB |
Output isn't correct |
9 |
Runtime error |
607 ms |
50560 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Runtime error |
12 ms |
896 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
11 |
Runtime error |
167 ms |
4728 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Incorrect |
856 ms |
21612 KB |
Output isn't correct |
13 |
Incorrect |
554 ms |
26524 KB |
Output isn't correct |