pbds求调
查看原帖
pbds求调
488448
py_practice楼主2024/8/27 22:48

在 #8 ~ #13 数据点 RE 了,下载下来运行却没问题。求看看代码

链接:提交链接


#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;

constexpr int N = 1e7 + 10;

typedef pair<int, int> PII;

tree<PII, null_type, less<PII>, rb_tree_tag, tree_order_statistics_node_update> Tree;
int n, cnt[N];

void solve()
{
    cin >> n;
    while(n -- ) {
        int op, x; cin >> op >> x;
        if(op == 1) {
            cnt[x] ++ ;
            Tree.insert({x, cnt[x]});
        }
        if(op == 2) {
            Tree.erase({x, cnt[x]});
            cnt[x] -- ;
        }
        if(op == 3) {
            cout << Tree.order_of_key({x, 0}) + 1 << '\n';
        }
        if(op == 4) {
            auto it = Tree.find_by_order(x - 1);
            if(it == Tree.end()) {
                cout << -1 << '\n';
            } else {
                cout << it -> first << '\n';
            }
        }
        if(op == 5) {
            auto it = Tree.lower_bound({x, 0});
            if(it == Tree.begin()) {
                cout << -1 << '\n';
            } else {
                cout << prev(it) -> first << '\n';
            }
        }
        if(op == 6) {
            auto it = Tree.upper_bound({x, cnt[x]});
            if(it == Tree.end()) {
                cout << -1 << '\n';
            } else {
                cout << it -> first << '\n';
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);

    solve();


    return 0;
}
2024/8/27 22:48
加载中...