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 ...
随机推荐
- Database and models
Database and models The database Now that we have the Album module set up with controller action met ...
- java8 之java.time
Java 8 之 java.time 包 标签: java java8 | 发表时间:2013-10-15 08:29 | 作者:coderbee 分享到: 出处:http://coderbee.ne ...
- A.prototype.b=22和A.b=22的区别
// A.prototype.b=22和A.b=22有什么区别 <script> function A(){ this.b=11; }A.b=22;//A.prototype.b=2 ...
- Redis常见问题及处理方法
一.Redis状态检查 唯一标记一个redis实例的是ip和端口,前端是用tcp方式来访问redis的,我们提供给应用访问的是一个ip+63379(一般使用63379) 端口.因此我们执行如下命令检查 ...
- 【总结】教你怎么将centos7打造成桌面系统
http://tieba.baidu.com/p/3379447850 centos吧
- 用Cookie记住上次登录用户名
一个登录页面设置查看Cookie中的数据(Cookie不为null);然后将页面提交到另一个页面去,在这个页面中的到是否选择记住用户名,如果选择了, 就创建Cookie对象,将用户名存储起来,下次登录 ...
- Controller中利用RedirectToRoute重定向的问题
先看看我们例子用到的路由表 routes.MapRouteWithName( name: "ProductDetail", url: "{Platform}/Produc ...
- C#学习笔记3:提示“截断字符串或二进制数据”错误解决方法
1.调试程序如出现“截断字符串或二进制数据”的关于数据库的错误,可以先试一试修改数据库中字符定义的长度. 2.使用ManualResetEvent前需导入 命名空间System.Threading; ...
- Android开发之Service
什么是Service? Android中的服务与Activity不同,他是不能与用户进行交互,自己也不能启动在后台运行的程序,当我们退出应用时,Service应用并没有结束,它仍然在后台运行. 例子: ...
- Android更改桌面应用程序launcher的两种方式
http://blog.csdn.net/mdx20072419/article/details/9632779/ launcher,也就是android的桌面应用程序.下图是我正在使用的魅族手机的l ...