int main(void){ ios::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; char op[n]; long long val[n]; for(long long i = 0; i < n; i++) cin >> op[i] >> val[i]; vector<long long> orig(val, val+n); sort(val, val+n); unordered_map<long long, long long> value, reval; long long cur = 1; value[val[0]] = cur; reval[cur] = val[0]; for(long long i = 1; i < n; i++){ if(val[i] == val[i-1]) continue; else { value[val[i]] = ++cur; reval[cur] = val[i]; } } for(long long i = 0; i < n; i++) orig[i] = value[orig[i]]; //for(long long i = 0; i < n; i++) cerr << orig[i] << endl; tree.build(n+2); for(long long i = 0; i < n; i++){ if(op[i] == 'I'){ //cerr << "inserting: " << orig[i] << endl; insert(orig[i]); }else if(op[i] == 'D'){ //cerr << "deleting: " << orig[i] << endl; erase(orig[i]); }else if(op[i] == 'K'){ long long ans = kth_smallest(reval[orig[i]]); //cerr << "Kth: " << reval[orig[i]] << endl; if(ans == -1) cout << "invalid" << endl; else cout << reval[ans] << endl; }else{ long long ans = Rank(orig[i]); //cerr << "Count" << endl; cout << ans << endl; } //tree.prlong long(); } }
int main(int argc, const char * argv[]) { int ff; int v1, v2, t; char query[20]; BIT bit; scanf("%d", &ff); for (int tt = 1; tt <= ff; tt++) { printf("Case %d:\n", tt); int n; scanf("%d", &n); bit.build(n+1); for (int i = 1; i <= n; i++) { scanf("%d", &t); bit.modify(i, t); } bool fl = true; while (fl) { scanf("%s", query); switch (query[0]) { case 'Q': scanf("%d %d", &v1, &v2); printf("%d\n", bit.sum(v1, v2)); break; case 'A': scanf("%d %d", &v1, &v2); bit.modify(v1, v2); break; case 'S': scanf("%d %d", &v1, &v2); bit.modify(v1, -v2); break; case 'E': fl = false; break; } } } }