• 贪心+构造( Codeforces Round #344 (Div. 2))


    题目:Report

    题意:有两种操作:

            1)t = 1,前r个数字按升序排列;
              2)t = 2,前r个数字按降序排列;

           求执行m次操作后的排列顺序。

    #include <iostream>
    #include <algorithm>
    #include <stdlib.h>
    #include <time.h>
    #include <cmath>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <set>
    
    #define c_false ios_base::sync_with_stdio(false); cin.tie(0)
    #define INF 0x3f3f3f3f
    #define INFL 0x3f3f3f3f3f3f3f3f
    #define zero_(x,y) memset(x , y , sizeof(x))
    #define zero(x) memset(x , 0 , sizeof(x))
    #define MAX(x) memset(x , 0x3f ,sizeof(x))
    using namespace std;
    #define N 200005
    const int M = 1e9 +7;
    typedef long long LL;
    int a[N];
    struct manager{
        int t,r;
    }ma[N];
    int b[N];
    int main(){
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        int n, m;
        scanf("%d%d",&n,&m);
        for(int i = 0; i < n;i++){
            scanf("%d",a+i);
        }
        int k = 0,x,y;
        while (m--){
            scanf("%d%d", &x, &y);
            while(k > 0 && ma[k-1].r <= y) k--;
            if(k > 0 && x == ma[k-1].t) continue;
            ma[k].t = x;
            ma[k].r = y;
            k++;
        }
        ma[k].t = 1;
        ma[k].r = 0;
        for(int i = 0; i < ma[0].r; i++)
            b[i] = a[i];
        sort(b, b+ma[0].r);
        int l = 0,r = ma[0].r;
        int p = r;
        for(int i = 0; i < k; i++){
            //printf("%5d%5d 
    ",ma[i].t,ma[i].r);
            while(p > ma[i+1].r){
                p--;
                if(ma[i].t == 1) a[p] = b[--r];
                else if(ma[i].t == 2)a[p] = b[l++];
            }
        }
        for(int i = 0;i < n;i++){
            printf("%d ",a[i]);
        }
        printf("
    ");
        return 0;
    }
  • 相关阅读:
    Codeforces 716C[数论][构造]
    HDU 5808[数位dp]
    Codeforces 611d [DP][字符串]
    Codeforces 404D [DP]
    HDU 5834 [树形dp]
    HDU 5521 [图论][最短路][建图灵感]
    矩阵
    kruskal 处理最短路 问题 A: 还是畅通工程
    Dijastra最短路 + 堆优化 模板
    CodeForces
  • 原文地址:https://www.cnblogs.com/yoyo-sincerely/p/5259506.html
Copyright © 2020-2023  润新知