[pb_ds + map] WA35pts on#5-#13 求助
查看原帖
[pb_ds + map] WA35pts on#5-#13 求助
422507
Fla_Akebono楼主2024/8/30 18:31
#include <bits/stdc++.h>
#include <bits/extc++.h>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;

int n;
unordered_map<ll, int> dic;
tree<pair<ll, int>, null_type,
     less<pair<ll, int>>, rb_tree_tag,
     tree_order_statistics_node_update>
    tr;

int main()
{
    int opt{};
    ll x;
    scanf("%d", &n);

    for (int i = 1; i <= n; i++)
    {
        scanf("%d %lld", &opt, &x);
        if (opt == 1)
        {
            tr.insert(make_pair(x, i));
            dic[x]++;
        }
        if (opt == 2)
        {
            tr.erase(make_pair(x, dic[x]));
            dic[x]--;
        }
        if (opt == 3)
        {
            auto it = tr.order_of_key(make_pair(x, 0));
            printf("%ld\n", ++it);
        }
        if (opt == 4)
        {
            auto it = tr.find_by_order(x - 1);
            printf("%lld\n", it->first);
        }
        if (opt == 5)
        {
            auto it = tr.lower_bound(make_pair(x, 0));
            printf("%lld\n", (--it)->first);
        }
        if (opt == 6)
        {
            auto it = tr.upper_bound(make_pair(x, dic[x]));
            printf("%lld\n", it->first);
        }
    }
    return 0;
}

RT,可过样例,求调

2024/8/30 18:31
加载中...