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("\n");
}
Codeforces Round #344 (Div. 2) C. Report 其他的更多相关文章
- 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时表示将序列[ ...
- Codeforces Round #344 (Div. 2) 631 C. Report (单调栈)
C. Report time limit per test2 seconds memory limit per test256 megabytes inputstandard input output ...
- Codeforces Round #344 (Div. 2) A. Interview
//http://codeforces.com/contest/631/problem/Apackage codeforces344; import java.io.BufferedReader; i ...
- Codeforces Round #344 (Div. 2)
水 A - Interview 注意是或不是异或 #include <bits/stdc++.h> int a[1005], b[1005]; int main() { int n; sc ...
- 贪心+构造( Codeforces Round #344 (Div. 2))
题目:Report 题意:有两种操作: 1)t = 1,前r个数字按升序排列: 2)t = 2,前r个数字按降序排列: 求执行m次操作后的排列顺序. #include <iostream&g ...
- Codeforces Round #344 (Div. 2) A
A. Interview time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- 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 ...
- Codeforces Round #344 (Div. 2) D. Messenger kmp
D. Messenger 题目连接: http://www.codeforces.com/contest/631/problem/D Description Each employee of the ...
- 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 ...
随机推荐
- 部署HBase系统(分布式部署)
1.简介 HBase系统主要依赖于zookeeper和hdfs系统,所以部署HBase需要先去部署zookeeper和hadoop 2.部署开始 IP或者HOSTNAME需要根据自身主机信息设定. 部 ...
- [New learn]讲解Objective-c的block知识
1.简介 OC的Block感觉就是C中饿函数指针,提供回调功能,但是OC中的block比C的函数指针要更加强大,甚至可以访问本地变量和修改本地变量. block在oc中是一个对象,它可以像一般的对象那 ...
- 12-5 NSSet
原文:http://rypress.com/tutorials/objective-c/data-types/nsset NSSet NSSet, NSArray, and NSDictionary ...
- python 作业
Linux day01 计算机硬件知识整理 作业要求:整理博客,内容如下 编程语言的作用及与操作系统和硬件的关系 应用程序->操作系统->硬件 cpu->内存->磁盘 cpu与 ...
- 【python】时间戳、字典列表排序
记录一下昨天学到的知识: 一.文件相关 文件追加:f = open("fname","a") 文件不存在时创建 二.时间戳相关 http://www.jb ...
- Mybatis插入数据返回自增主键
方法有很多,参考 mysql函数之六:mysql插入数据后返回自增ID的方法,last_insert_id(),selectkey 这里记录一下工作中自己用到的selectkey方法的详细过程. po ...
- beego学习笔记(1)
公司准备开发一个针对塔吊行业的APP. 后台采用微服务,docker容器部署. 准备采用go进行微服务的开发. 采用beego进行restful API的开发. 第一步,访问beego的官方网站: h ...
- [Android] 按钮单击事件的五种写法
在平时学习安卓的过程中,不论是看视频还是看博客,我发现每个人对代码的写法都有不同的偏好,比较明显的就是对控件响应事件的写法的不同.所以我想把这些写法总结一下,比较下各种写法的优劣,希望可以让自己可以灵 ...
- (翻译)在 Xamarin 应用中使用 MongoDB
原文地址:https://blog.xamarin.com/write-apps-using-mongodb-xamarin/ 在设计应用时,最重要的决定之一就是要使用什么类型的数据库. 不久之前,这 ...
- T-SQL备忘(6):常用内置函数
日期和时间函数: 1.获取当前时间:GETDATE() select GETDATE() 返回: 2015-04-27 20:52:06.700 2.返回时间的部分(日.月.年) a.获取日: sel ...