Codeforces Round #344 (Div. 2) C. Report
题意:给长度为n的序列,操作次数为m;n and m (1 ≤ n, m ≤ 200 000) ,操作分为t r,当t = 1时表示将[1,r]序列按非递减排序,t = 2时表示将序列[1,r]按非递增排序;输出m次操作后的序列?
思路:由于排序是前缀排序,那么前面的操作ti,ri;如果 ri <= rj;那么第i次操作直接被覆盖了。这样我们可以知道有用的排序操作ri是按照严格递减的;并且这时在ri 与r(i + 1)之间的数与后面的操作无关了~~(线性处理),这就直接说明了只需要排序一次,即对于[1,max(ri)]排序,之后直接用双指针在排好序的数组中找到对应的值填到结果数组中即可;
#include<bits/stdc++.h>
using namespace std;
typedef __int64 ll;
template<typename T>
void read1(T &m)
{
T x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
m = x*f;
}
template<typename T>
void read2(T &a,T &b){read1(a);read1(b);}
template<typename T>
void read3(T &a,T &b,T &c){read1(a);read1(b);read1(c);}
const int N = ;
int a[N],b[N],t[N],r[N],p[N],q[N];
int main()
{
int n,m;
read2(n,m);
for(int i = ;i <= n;i++) read1(a[i]),b[i] = a[i];
for(int i = ;i <= m;i++) read2(t[i],r[i]);
int mx = , cnt = ;
for(int i = m;i >= ; i--){//逆序增加mx;压缩出有用的排序即可;
if(r[i] > mx)
mx = r[i],p[++cnt] = r[i],q[cnt] = t[i];
}
p[] = ;//完全处理;
sort(b + ,b + mx + );//a最终排序的元素在b中找即可;
int la = , ra = mx, lb = ,rb = mx;
for(int i = cnt;i > ;i--){
if(q[i] == )
for(;ra > p[i - ];ra--,rb--) a[ra] = b[rb];
else
for(;ra > p[i - ];ra--,lb++) a[ra] = b[lb];
}
for(int i = ;i <= n;i++)
printf("%d ",a[i]);
return ;
}
Codeforces Round #344 (Div. 2) C. Report的更多相关文章
- Codeforces Round #344 (Div. 2) C. Report 其他
		C. Report 题目连接: http://www.codeforces.com/contest/631/problem/C Description Each month Blake gets th ... 
- 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 ... 
随机推荐
- com.domain.bean
			package com.domain.bean; import java.util.LinkedHashMap; import java.util.Map; public class TmpBean ... 
- JAVA_FastJson
			package com.qf.mobiletrain01; import java.util.List; import com.alibaba.fastjson.JSON; class Student ... 
- Java栈实现
			栈数组实现一:优点:入栈和出栈速度快,缺点:长度有限(有时候这也不能算是个缺点) public class Stack { private int top = -1; private Object[] ... 
- 关于Git中的一些常用的命令
			深入了解git的checkout命令 检出命令(git checkout)是Git最常用的命令之一,同时也是一个很危险的命令. 因为这条命令会重写工作区.检出命令的用法如下: 用法一: git che ... 
- 怎样安装WIN7系统
			如何避免win7自动创建200M隐藏分区 1 安装win7到选择安装到哪个分区的时候,不能选择 unallocated diskspace ,也不能选 delete 已有的分区(例如C盘)安全的做法是 ... 
- ubuntu:configure error:cannot find ssl libraries
			安装SSL库,openssl或者libssl: sudo apt-get install openssl sudo apt-get install libssl configure的时辰加上选项: . ... 
- TFS2013 安装出现TF400102错误解决
			我是参照:http://www.cnblogs.com/zhibincai/archive/2013/11/25/3442285.html 进行安装的windows 2012 + sql 2012 S ... 
- tlb,tlh,tli文件的关系
			tlb文件:com类型库文件.在需要使用对应com类的模块里,“#import ...*.tlb”使用之. tlh.tli文件:他们是vc++编译器解析tlb文件生成的标准c++文件.因为odl和tl ... 
- ResourceManager高可用配置
			ResourceManager高可用配置 1. yarn-site.xml配置 <property> <name>yarn.resourcemanager.cluster-id ... 
- linux配置学习笔记(一):如何提高ssh连接的速度
			服务器端sshd配置文件 /etc/ssh/sshd_config 看是否有如下的两条配置条目 GSSAPIAuthentication no UseDNS no 如果前面带#,请把#删掉,或者新添加 ... 
