#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()
int n, s, q, gl, gr, t, k, x, p, z;
int seg[2][1000005], a[250005];
char ch;
vector<pii> v;
map<int, int> r; map<int, int>::iterator i;
void up(int L, int R, int N){
if (L>gl || R<gl) return;
if (L==R){
seg[t][N]=x;
return;
}
up(lseg); up(rseg);
seg[t][N]=max(seg[t][N*2+1], seg[t][N*2+2]);
}
int query(int L, int R, int N){
if (L==R){
return L-1;
}
if (seg[t][N*2+1]>x) query(lseg);
else query(rseg);
}
void change(int P){
if (P<s){
gl=s-P; x=a[P]; t=0;
up(1, s+1, 0);
}
if (P>s){
gl=P-s; x=a[P]; t=1;
up(1, n-s, 0);
}
}
int hi(int L, int R, int N){
if (L>gr) return 0;
if (R<=gr) return seg[t][N];
return max(hi(lseg), hi(rseg));
}
int main(){
//freopen("new.txt", "w", stdout);
scanf("%i%i",&n, &s); --s;
gl=s+1; x=(1 << 30); t=0;
up(1, s+1, 0);
gl=n-s; x=(1 << 30); t=1;
up(1, n-s, 0);
fox(l, n){
scanf("%i", &a[l]);
change(l);
r[a[l]]=l;
}
scanf("%i", &q);
//cout << q << endl;
int c=0;
fox(l, q){
//cout << "*";
scanf(" %c%i", &ch, &p); --p;
if (ch=='E'){
scanf("%i", &z);
r.erase(a[p]);
i=r.end();
fox(l, z){
--i;
if (i==--r.lb(a[p])) return 1;
}
k=a[p]=i->x+1;
change(p);
//cout << "*" << k << endl;
//continue;
v.clear();
for (++i, ++k; i!=r.end(); ++i, ++k){
//cout << i->y << ' ';
v.pb(mp(i->x, i->y));
a[i->y]=k;
change(i->y);
//cout << "*";
}
//if (v.size()!=z-1) return 1;
//cout << endl;
fox(l, z-1){
//cout << v[l].x << ":" << a[v[l].y] << ' ';
r.erase(v[l].x);
}
fox(l, z-1){
//cout << v[l].x << ":" << a[v[l].y] << ' ';
r[a[v[l].y]]=v[l].y;
}
r[a[p]]=p;
//cout << endl;
//for (auto i:r) cout << i.x << ' '; cout << endl;
//cout << p << ' ' << z << ' ' << r.size() << endl;
//fox(l, 20) cout << a[l] << ' '; cout << endl;
} else {
//cout << p << ' ' << s << ' ';
if (p==s){
printf("0\n");
} else if (p<s){
t=0; gr=s-p; x=hi(1, s+1, 0);
//cout << x << "*";
t=1;
printf("%i\n", s-p+query(1, n-s, 0));
} else {
t=1; gr=p-s; x=hi(1, n-s, 0);
t=0;
//cout << x << ' ';
printf("%i\n", p-s+query(1, s+1, 0));
}
c++;
}
//if (c==112) while(1);
}
//cout << "*";
return 0;
}
Compilation message
cake.cpp: In function 'int query(int, int, int)':
cake.cpp:47:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
cake.cpp: In function 'int main()':
cake.cpp:66:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i%i",&n, &s); --s;
^
cake.cpp:72:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i", &a[l]);
^
cake.cpp:76:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i", &q);
^
cake.cpp:81:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c%i", &ch, &p); --p;
^
cake.cpp:83:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i", &z);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
10812 KB |
Output is correct |
2 |
Correct |
0 ms |
10812 KB |
Output is correct |
3 |
Correct |
0 ms |
10812 KB |
Output is correct |
4 |
Correct |
6 ms |
10812 KB |
Output is correct |
5 |
Correct |
26 ms |
11340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
986 ms |
11208 KB |
Output is correct |
2 |
Correct |
426 ms |
11340 KB |
Output is correct |
3 |
Correct |
623 ms |
11340 KB |
Output is correct |
4 |
Correct |
326 ms |
11340 KB |
Output is correct |
5 |
Correct |
1203 ms |
12000 KB |
Output is correct |
6 |
Correct |
906 ms |
12000 KB |
Output is correct |
7 |
Correct |
703 ms |
12000 KB |
Output is correct |
8 |
Correct |
443 ms |
12000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
196 ms |
15564 KB |
Output is correct |
2 |
Correct |
119 ms |
15564 KB |
Output is correct |
3 |
Correct |
113 ms |
15564 KB |
Output is correct |
4 |
Correct |
0 ms |
10812 KB |
Output is correct |
5 |
Correct |
496 ms |
22560 KB |
Output is correct |
6 |
Correct |
403 ms |
22560 KB |
Output is correct |
7 |
Correct |
189 ms |
22560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
10944 KB |
Output is correct |
2 |
Correct |
59 ms |
11076 KB |
Output is correct |
3 |
Correct |
159 ms |
13188 KB |
Output is correct |
4 |
Correct |
206 ms |
13188 KB |
Output is correct |
5 |
Correct |
229 ms |
10944 KB |
Output is correct |
6 |
Correct |
303 ms |
13848 KB |
Output is correct |
7 |
Correct |
223 ms |
11340 KB |
Output is correct |
8 |
Correct |
433 ms |
15564 KB |
Output is correct |
9 |
Correct |
1889 ms |
22560 KB |
Output is correct |
10 |
Correct |
773 ms |
10944 KB |
Output is correct |
11 |
Correct |
1046 ms |
11736 KB |
Output is correct |
12 |
Correct |
1889 ms |
20184 KB |
Output is correct |
13 |
Correct |
1483 ms |
22560 KB |
Output is correct |