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 ...
随机推荐
- Perl6 Bailador框架(7):模版编写
先看一个例子: use v6; use Bailador; my $data = ' <form action="", method="get"> ...
- Bzoj-2301 [HAOI2011]Problem b 容斥原理,Mobius反演,分块
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2301 题意:多次询问,求有多少对数满足 gcd(x,y)=k, a<=x<=b ...
- Makefile系列之一 : 书写规则
1. 规则 target : prerequisites command 2. example excute 为最终生成的可执行文件. 可以通过命令 make clean来删除所有编译时产生的中间文 ...
- Jmeter性能测试示例
这次成功做了一个jmeter借口性能测试的简单测试示例,分享一下给大家. jmeter作为一个简单的开源工具,基于java的性能测试工具,使用起来很简单. 也可以作为二次开发,复杂的情形可以自己写代码 ...
- leetcode 之Partition List(16)
思路就是定义两个链表,一个放大的,一个放小的,最后将两个连起来,注意细节问题. ListNode *partionList(ListNode *head, int value) { ListNode ...
- redis 的优化
1.pipeling “请求-响应”模式的服务器在处理完一个请求后就开始处理下一个请求,不管客户端是否读取到前一个请求的响应结果.这让客户端不需要发一个请求等一个响应的串行,可以一次发送多个请求,再最 ...
- jenkins构建触发器定时任务Build periodically和Poll SCM【转载】
转至博客:上海-悠悠 前言 跑自动化用例每次用手工点击jenkins出发自动化用例太麻烦了,我们希望能每天固定时间跑,这样就不用管了,坐等收测试报告结果就行. 一.定时构建语法 * * * * * ( ...
- Unique Binary Search Trees I&&II(II思路很棒)——动态规划(II没理解)
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For exa ...
- AC日记——Mato的文件管理 bzoj 3289
3289 思路: 莫队求区间逆序对个数,树状数组维护: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 500 ...
- ELK系列--实时日志分析系统ELK 部署与运行中的问题汇总
前记: 去年测试了ELK,今年测试了Storm,最终因为Storm需要过多开发介入而放弃,选择了ELK.感谢互联网上各路大神,目前总算是正常运行了. logstash+elasticsearch+ki ...