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("\n");
}

Codeforces Round #344 (Div. 2) C. Report 其他的更多相关文章

  1. Codeforces Round #344 (Div. 2) C. Report

    Report 题意:给长度为n的序列,操作次数为m:n and m (1 ≤ n, m ≤ 200 000) ,操作分为t r,当t = 1时表示将[1,r]序列按非递减排序,t = 2时表示将序列[ ...

  2. Codeforces Round #344 (Div. 2) 631 C. Report (单调栈)

    C. Report time limit per test2 seconds memory limit per test256 megabytes inputstandard input output ...

  3. Codeforces Round #344 (Div. 2) A. Interview

    //http://codeforces.com/contest/631/problem/Apackage codeforces344; import java.io.BufferedReader; i ...

  4. Codeforces Round #344 (Div. 2)

    水 A - Interview 注意是或不是异或 #include <bits/stdc++.h> int a[1005], b[1005]; int main() { int n; sc ...

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

    题目:Report 题意:有两种操作: 1)t = 1,前r个数字按升序排列:   2)t = 2,前r个数字按降序排列: 求执行m次操作后的排列顺序. #include <iostream&g ...

  6. Codeforces Round #344 (Div. 2) A

    A. Interview time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  7. Codeforces Round #344 (Div. 2) E. Product Sum 维护凸壳

    E. Product Sum 题目连接: http://www.codeforces.com/contest/631/problem/E Description Blake is the boss o ...

  8. Codeforces Round #344 (Div. 2) D. Messenger kmp

    D. Messenger 题目连接: http://www.codeforces.com/contest/631/problem/D Description Each employee of the ...

  9. Codeforces Round #344 (Div. 2) B. Print Check 水题

    B. Print Check 题目连接: http://www.codeforces.com/contest/631/problem/B Description Kris works in a lar ...

随机推荐

  1. TCP之listen&backlog

    1. listen函数: #include <sys/socket.h> int listen(int sockfd, int backlog); ret-成功返回0 失败返回- list ...

  2. Keepalived 安装与简单配置

    Keepalived 安装与简单配置 http://sivxy.lofter.com/post/1d21ebb9_7e15000

  3. PXC 避免加入集群时发生SST

    环境 现有集群节点: 192.168.99.210:3101 新加入节点: 192.168.99.211:3101 通过xtrabackup备份还原实例,并通过同步方式追数据: 已有节点情况: roo ...

  4. C#通过反射获取类中的方法和参数个数,反射调用方法带参数

    using System; using System.Reflection; namespace ConsoleApp2 { class Program { static void Main(stri ...

  5. git - 使用原理

    对git操作最大的功臣就是.git目录下的HEAD HEAD是什么 HEAD其实是一个类似于指针的东西,只不过这个指针的含义是指向当前的分支,当你再[ git checkout 分支 ] 的时候这个分 ...

  6. Struts2学习笔记03 之 Result组件

    二.Result原理 1.stream 2.redirectAction 3.Json

  7. 机器学习方法(四):决策树Decision Tree原理与实现技巧

    欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld. 技术交流QQ群:433250724,欢迎对算法.技术.应用感兴趣的同学加入. 前面三篇写了线性回归,lass ...

  8. Graph Cut

    转自:http://blog.csdn.net/zouxy09/article/details/8532111 Graph Cut,下一个博文我们再学习下Grab Cut,两者都是基于图论的分割方法. ...

  9. 关于Sphinx中使用 RealTime Index的问题

    我们有了完整索引和增量索引,为什么还需要研究实时索引? 1.完整索引每个晚上空闲时执行一次,时间较长,但问题不大,因为IO慢,CPU累,但那个时间段基本没有人使用平台,比如凌晨2点. 2.增量索引:目 ...

  10. CentOS7.5更改grub2菜单背景&开机动态画面

    Grub2菜单背景 红帽企业版 Linux 7 的引导装载程序是“GRUB 2”.您可以更改“GRUB 2”外观的几个部分.以下几小节将向您展示如何改变 Linux 发行版名称.菜单颜色,和背景图片. ...