zoukankan      html  css  js  c++  java
  • Codeforces Round #344 (Div. 2) C. Report 其他

    C. Report

    题目连接:

    http://www.codeforces.com/contest/631/problem/C

    Description

    Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are n commodities produced by the company. For each of them there is exactly one integer in the final report, that denotes corresponding revenue. Before the report gets to Blake, it passes through the hands of m managers. Each of them may reorder the elements in some order. Namely, the i-th manager either sorts first ri numbers in non-descending or non-ascending order and then passes the report to the manager i + 1, or directly to Blake (if this manager has number i = m).

    Employees of the "Blake Technologies" are preparing the report right now. You know the initial sequence ai of length n and the description of each manager, that is value ri and his favourite order. You are asked to speed up the process and determine how the final report will look like.

    Input

    The first line of the input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the number of commodities in the report and the number of managers, respectively.

    The second line contains n integers ai (|ai| ≤ 109) — the initial report before it gets to the first manager.

    Then follow m lines with the descriptions of the operations managers are going to perform. The i-th of these lines contains two integers ti and ri (, 1 ≤ ri ≤ n), meaning that the i-th manager sorts the first ri numbers either in the non-descending (if ti = 1) or non-ascending (if ti = 2) order.

    Output

    Print n integers — the final report, which will be passed to Blake by manager number m.

    Sample Input

    3 1
    1 2 3
    2 2

    Sample Output

    2 1 3

    Hint

    题意

    给你n个数,Q次操作

    每次操作会使得[1,r]呈升序或者[1,r]呈降序

    然后问你最后是什么样

    题解:

    对于每个端点,其实就最后一次操作有用

    于是我们就只用看这个数最后是什么操作就好了

    然后依旧记录一下时间戳,倒着跑一遍就好了

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 2e5+7;
    int a[maxn];
    int ans[maxn];
    int flag[maxn],T[maxn];
    vector<int> V1;
    int main()
    {
        int n,q;
        scanf("%d%d",&n,&q);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        for(int i=1;i<=q;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            flag[y]=x;
            T[y]=i;
        }
        int st = n+1;
        for(int i=n;i>=1;i--)
        {
            st=i;
            if(flag[i]==0)ans[i]=a[i];
            else break;
            st=0;
        }
        if(st==0)return 0;
        for(int i=st;i>=1;i--)
            V1.push_back(a[i]);
        sort(V1.begin(),V1.end());
        int t1 = 0,t2 = V1.size()-1;
        int now = flag[st],time = T[st];
        for(int i=st;i>=1;i--)
        {
            if(flag[i]!=0&&time<T[i])
                now = flag[i],time=T[i];
            if(now==2)
            {
                ans[i]=V1[t1];
                t1++;
            }
            else
            {
                ans[i]=V1[t2];
                t2--;
            }
        }
        for(int i=1;i<=n;i++)
            printf("%d ",ans[i]);
        printf("
    ");
    }
  • 相关阅读:
    [导入]动态内存管理
    再看一个直播帖子,一个上午混没了
    这个帖子不错
    基于STM32 8通道ADC采样实现源代码(转) 以后设计参考使用
    天气基本恢复正常,可以玩了
    开始学习了
    安静的看了2天书
    慎度职场“35危机”
    书买了,估计这个星期就到了
    C语言循环的小艺术(转)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5243213.html
Copyright © 2011-2022 走看看