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;
}
时间: 2024-10-28 22:20:56

Codeforces 420D. Cup Trick的相关文章

cf 420D. Cup Trick (Splay树)

Splay  树的比较基本的序列维护操作, 用getSeg( int l, int r) 获取要操作的区间 若:获取区间[l,r],非空,getSeg(l,r),然后KT指向区间[l,r] 若:获取区间为空,如当要在l位置插入一个值时,则getSeg(l,l-2),然后可在KT赋值新节点 D. Cup Trick #include <iostream> #include <cstdio> #include <cstring> #include <string>

Codeforces VK Cup 2015 Wild Card Round 1 (AB)

比赛链接:http://codeforces.com/contest/522 A. Reposts time limit per test:1 second memory limit per test:256 megabytes One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started

Codeforces VK Cup Finals #424 Div.1 C. Bamboo Partition(数论)

题目要求符合以下条件的最大的d 化简得 注意到 最多只有2*sqrt(a[i]-1)种取值,也就是一共最多有n*sqrt(10^19)种取值,于是枚举一下d,计算出符合上上式的最大的d更新答案,然后d跳跃到下一个取值 效率O(n²sqrt(10^9)) #include<bits/stdc++.h> #define ll long long using namespace std; const int maxn=110,inf=1e9; ll n,k,ans,r; ll a[maxn]; vo

Codeforces VK Cup Finals #424 Div.1 A. Office Keys(DP)

显然是不可能交叉取钥匙的,于是把钥匙和人都按坐标排序就可以DP了 钥匙可以不被取,于是f[i][j]表示前i个钥匙被j个人拿的时间 f[i][j]=min(f[i-1][j],max(f[i-1][j-1],abs(b[i]-a[j])+abs(P-b[i])); #include<bits/stdc++.h> #define ll long long using namespace std; const int maxn=1010,inf=2e9; int n,k,p; int a[maxn

Codeforces Canda Cup 2016

A.B:模拟 C.构造下就行了 D.题意:n个参加ACM的队(n<=300000),每个队都有自己的初始气球数和重量,规定如果气球数>重量,那么此队就会飞起来,淘汰出局,你现在是第一组,你可以给其他组气球,问你最高能排名多少,你的排名是气球数严格大于你气球数的队伍数+1.  分析:贪心的想法,将那些气球数大于你的队伍放在优先队列里维护wi-ti的最小值,优先淘汰wi-ti小的队伍,给他气球的同时,你也会气球减少,也就可能有其他你后面的队伍比你高,这些队要新加入优先队列.  具体的操作是将所有队

codeforces Looksery Cup 2015 H Degenerate Matrix 二分 注意浮点数陷阱

#include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cmath> #include <iostream> using namespace std; bool fun(double l1,double r1,double l2,double r2){ return (l1 <= r2 && l1

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

题意大概就是有n个数字,要使至少有k个相同,可以花费b使一个数+5,可以花费c使一个数+1,求最小花费. 要对齐的数肯定是在[v,v+4]之间,所以分别枚举模为0~4的情况就可以了. 排序一下,然后化绝对为相对 例如有 3 6 8 14这4个数,模4, 耗费分别为c+2b 3c+b c+b 0 可以-2b(移动到14时=2*5+4,倍率2)变成c 3c-b c-b -2b 就是说每次都取倍率然后减其花费压入优先队列,若元素数量大于k就弹出最大的那个就可以了 /*没时间自己写个就把其他人的题解搞来

CodeForces 452C Magic Trick (排列组合)

#include <iostream> #include <cstdio> #include<cmath> #include<algorithm> using namespace std; double num[1000000]; void init_arrary(){ for (int i = 1; i <= 1000000; ++i) { num[i] = num[i - 1] + log(i); } } double Cn(int m,int n

【codeforces VK Cup Round 1】BDE题解

B. Group Photo 2 (online mirror version) time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Many years have passed, and n friends met at a party again. Technologies have leaped forward since the