Codeforces 420D. Cup Trick

Posted ichneumon

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces 420D. Cup Trick相关的知识,希望对你有一定的参考价值。

平衡树板子题,虽然似乎有着高妙的树状数组搞法,但本着用用pb_ds这种bug库的存在,就没管了orz

#include <cstdio>
#include <ext/pb_ds/assoc_container.hpp>
#include <algorithm>
const int N = 2e6 + 100;
int n, m;
__gnu_pbds::tree<int,
__gnu_pbds::null_type,
       std::less<int>,
__gnu_pbds::rb_tree_tag,
__gnu_pbds::tree_order_statistics_node_update> pos;
int val[N], used[N], ans[N];

int main() {
    scanf("%d%d", &n, &m);
    for (int i = m + 1; i <= n + m; ++i)
        pos.insert(i);
    for (int i = 1; i <= m; ++i) {
        int x, y;
        scanf("%d%d", &x, &y);
        auto p = pos.find_by_order(y - 1);
        pos.erase(p);
        int t = *p;
        if (!val[t]) {
            ans[t - m] = x;
            if (used[x]) return puts("-1"), 0;
            used[x] = true;
            val[m - i] = x;
            t = m - i;
        } else {
            if (val[t] != x) return puts("-1"), 0;
            val[m - i] = val[t];
            t = m - i;
        }
        pos.insert(t);
    }
    int t = 1;
    for (int i = 1; i <= n; ++i)
        if (!ans[i]) {
            while (used[t]) ++t;
            ans[i] = t++;
        }
    for (int i = 1; i <= n; ++i)
        printf("%d ", ans[i]);
    puts("");

    return 0;
}

 

以上是关于Codeforces 420D. Cup Trick的主要内容,如果未能解决你的问题,请参考以下文章

[codeforces Mail.Ru Cup 2018 Round 1 D][ xor 操作]

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答

Codeforces Round #420 D题翻译(17.6.25)

codeforces VK cup 2016-round 1 D.Bear and Contribution

Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine)

Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) D - Travel Card(示