zoukankan      html  css  js  c++  java
  • codeforces 631C. Report

    题目链接

    按题目给出的r, 维护一个递减的数列,然后在末尾补一个0。 比如样例给出的

    4 2
    1 2 4 3
    2 3
    1 2

    递减的数列就是3 2 0, 操作的时候, 先变[3, 2), 然后变[2, 0), 具体的过程看代码。
     
    #include <iostream>
    #include <vector>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <map>
    #include <set>
    #include <string>
    #include <queue>
    #include <stack>
    #include <bitset>
    using namespace std;
    #define pb(x) push_back(x)
    #define ll long long
    #define mk(x, y) make_pair(x, y)
    #define lson l, m, rt<<1
    #define mem(a) memset(a, 0, sizeof(a))
    #define rson m+1, r, rt<<1|1
    #define mem1(a) memset(a, -1, sizeof(a))
    #define mem2(a) memset(a, 0x3f, sizeof(a))
    #define rep(i, n, a) for(int i = a; i<n; i++)
    #define fi first
    #define se second
    typedef pair<int, int> pll;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int mod = 1e9+7;
    const int inf = 1061109567;
    const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
    const int maxn = 2e5+5;
    int st[200005], a[maxn], b[maxn], c[maxn];
    int main()
    {
        int n, m, sign, pos;
        cin>>n>>m;
        for(int i = 1; i<=n; i++)
            scanf("%d", &a[i]);
        int r = 0;
        for(int i = 0; i<m; i++) {
            scanf("%d%d", &sign, &pos);
            while(r>0&&pos>=st[r-1])
                r--;
            st[r] = pos, b[r] = sign;
            r++;
        }
        st[r++] = 0;
        int l = 1, rr = st[0];
        for(int i = 1; i<=n; i++)
            c[i] = a[i];
        sort(c+1, c+1+rr);
        for(int i = 1; i<r; i++) {
            for(int j = st[i-1]; j>st[i]; j--) {
                a[j] = (b[i-1] == 2)?c[l++]:c[rr--];
            }
        }
        for(int i = 1; i<=n; i++)
            printf("%d ", a[i]);
        return 0;
    }



      

  • 相关阅读:
    CentOS7静默安装WebLogic 12c
    yocto:bitbake单独编译某个模块的方法
    git config 查看配置信息
    文件上传bypass jsp内容检测的一些方法
    开始
    阿里云在线扩容磁盘(踩坑)笔记
    ifort 编译报错
    C语言测试题
    【Linux】find笔记
    Add User Snippet to VS Code
  • 原文地址:https://www.cnblogs.com/yohaha/p/5241721.html
Copyright © 2011-2022 走看看