mxqz pb_ds
查看原帖
mxqz pb_ds
483928
Z1qqurat楼主2022/11/23 16:57

锰锌初学 pb_ds,8pts 求助

#include<bits/stdc++.h>
#include<bits/extc++.h>
#define ll long long
using namespace std;
using namespace __gnu_pbds;
int n, k, op, ans;
tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> tr;

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> op >> k;
        if(op == 1) tr.insert(k);
        if(op == 2) tr.erase(k);
        if(op == 3) ans = tr.order_of_key(k), cout << ans << "\n";
        if(op == 4) ans = *tr.find_by_order(k - 1), cout << ans << "\n";
        if(op == 5) ans = *--tr.lower_bound(k - 1), cout << ans << "\n";
        if(op == 6) ans = *tr.upper_bound(k), cout << ans << "\n";
    }
    return 0;
}
2022/11/23 16:57
加载中...