pbds 20 pts 求调

P6136 【模板】普通平衡树(数据加强版)

NightTide @ 2022-08-12 20:02:28

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> tr;
ll n, m, ans, lst;
int main(){
    scanf("%lld%lld",&n,&m);
    for(int i = 1; i <= n; i++){
        ll x; scanf("%lld",&x);
        tr.insert((x << 31) + i);
    }
    for(int i = 1; i <= m; i++){
        ll op, x;
        scanf("%lld%lld",&op,&x);
        x ^= lst;
        if(op == 1) tr.insert((x << 31) + i);
        if(op == 2) tr.erase(tr.lower_bound(x << 31));
        if(op == 3) lst = tr.order_of_key(x << 31) + 1, ans ^= lst;
        if(op == 4) lst = *tr.find_by_order(x - 1), ans ^= (lst >> 31);
        if(op == 5) lst = *(--tr.lower_bound(x << 31)), ans ^= (lst >> 31);
        if(op == 6) lst = *tr.upper_bound((x << 31) + n), ans ^= (lst >> 31);
    }
    printf("%lld\n",ans);
    return 0;
}

|