zoukankan      html  css  js  c++  java
  • 2018 Multi-University Training Contest 1

    set维护

    预处理很巧妙,对于完全被大范围包含的小范围我们不用考虑,要处理的只有不完全重合的区间。

    因为一个区间可能被下一个区间的一部分包含,所以我们所能选择的数是在变化的,用一个集合来维护,每次取最小值即可。

    在读入区间范围的时候,可以用pre数组来存每个区间r对应的最大的区间长度的l,然后再反着用pre[i+1]更新pre[i],可以得到包含每个点的最大区间的l。

    在填数字的时候考虑是否在下一个区间,用pl来维护两个区间不重叠的数,pl从l[i-1]移动到l[i+1]-1的过程中,经过的值我们可以再重新插入集合。

    #include <bits/stdc++.h>
    #define INF 0x3f3f3f3f
    #define full(a, b) memset(a, b, sizeof a)
    using namespace std;
    typedef long long ll;
    inline int lowbit(int x){ return x & (-x); }
    inline int read(){
        int X = 0, w = 0; char ch = 0;
        while(!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }
        while(isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
        return w ? -X : X;
    }
    inline int gcd(int a, int b){ return b ? gcd(b, a % b) : a; }
    inline int lcm(int a, int b){ return a / gcd(a, b) * b; }
    template<typename T>
    inline T max(T x, T y, T z){ return max(max(x, y), z); }
    template<typename T>
    inline T min(T x, T y, T z){ return min(min(x, y), z); }
    template<typename A, typename B, typename C>
    inline A fpow(A x, B p, C lyd){
        A ans = 1;
        for(; p; p >>= 1, x = 1LL * x * x % lyd)if(p & 1)ans = 1LL * x * ans % lyd;
        return ans;
    }
    const int N = 100005;
    int _, n, m, ret[N], pre[N], l, r;
    
    int main(){
    
        for(_ = read(); _; _ --){
            n = read(), m = read();
            set<int> s;
            for(int i = 1; i <= n; i ++)
                pre[i] = i, s.insert(i);
            for(int i = 1; i <= m; i ++){
                l = read(), r = read();
                pre[r] = min(pre[r], l);
            }
            for(int i = n - 1; i >= 1; i --)
                pre[i] = min(pre[i], pre[i + 1]);
            int pl = 1;
            for(int i = 1; i <= n; i ++){
                while(pl < pre[i]) s.insert(ret[pl ++]);
                ret[i] = *(s.begin());
                s.erase(ret[i]);
            }
            for(int i = 1; i <= n; i ++){
                printf("%d%c", ret[i], " 
    "[i==n]);
            }
        }
        return 0;
    }
    
  • 相关阅读:
    移动开发 Native APP、Hybrid APP和Web APP介绍
    urllib与urllib2的学习总结(python2.7.X)
    fiddler及postman讲解
    接口测试基础
    UiAutomator2.0 和1.x 的区别
    adb shell am instrument 命令详解
    GT问题记录
    HDU 2492 Ping pong (树状数组)
    CF 567C Geometric Progression
    CF 545E Paths and Trees
  • 原文地址:https://www.cnblogs.com/onionQAQ/p/10891326.html
Copyright © 2011-2022 走看看