码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces 420D. Cup Trick

时间:2017-11-07 21:00:49      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:scan   code   rb_tree   upd   ons   include   auto   val   while   

平衡树板子题,虽然似乎有着高妙的树状数组搞法,但本着用用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

标签:scan   code   rb_tree   upd   ons   include   auto   val   while   

原文地址:http://www.cnblogs.com/ichn/p/7800827.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!