# include <bits/stdc++.h>
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
const int _(3e5 + 10), INF(2e9), PF(1e5);
inline long long Read(){
char c = '%'; long long x = 0, z = 1;
for(; c > '9' || c < '0'; c = getchar()) if(c == '-') z = -1;
for(; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
return x * z;
}
int n, m, t[_], id[_], a[_];
char opt[10];
inline void Add(register int x, register int v){ for(; x <= PF * 3; x += x & -x) t[x] += v; }
inline int Query(register int x){ register int cnt = 0; for(; x; x -= x & -x) cnt += t[x]; return cnt; }
inline int Find(register int x){
register int l = 1, r = PF * 3;
while(l < r){
register int mid = (l + r) >> 1;
if(Query(mid) >= x) r = mid;
else l = mid + 1;
}
return l;
}
int main(register int argc, register char *argv[]){
n = Read(); m = Read();
for(register int i = 1; i <= n; ++i) a[PF + i] = Read(), Add(PF + i, 1), id[a[PF + i]] = PF + i;
while(m--){
scanf(" %s", opt); register int x = Read(), y, p, q;
if(opt[0] == 'T'){
p = Find(1);
a[id[x]] = 0; Add(id[x], -1);
id[x] = p - 1;
a[id[x]] = x; Add(id[x], 1);
}
else if(opt[0] == 'B'){
p = Find(n);
a[id[x]] = 0; Add(id[x], -1);
id[x] = p + 1;
a[id[x]] = x; Add(id[x], 1);
}
else if(opt[0] == 'I'){
y = Read(); q = Query(id[x]);
p = Find(q + y); register int t = a[p];
swap(a[p], a[id[x]]); swap(id[x], id[t]);
}
else if(opt[0] == 'A') printf("%d\n", Query(id[x]) - 1);
else printf("%d\n", a[Find(x)]);
}
return 0;
}
标签:int,register,mid,long,char,Read,P2596
From: https://www.cnblogs.com/zan-mei-tai-yang/p/18408743