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的更多相关文章

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

    C. Report 题目连接: http://www.codeforces.com/contest/631/problem/C Description Each month Blake gets th ...

  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. Java自学成长路线(转载)

    JAVA自学之路 一:学会选择  决心做软件的,大多数人选的是java,或是.net,也有一些选择了手机.嵌入式.游戏.3G.测试等.  JAVA是一种平台,也是一种程序设计语言,如何学好程序设计不仅 ...

  2. Linux下用dump实现备份和还原 ux下用dump实现备份和还原

    对于系统而言,我们可以有很多种办法去备份(还原)系统或文件,之所以要去做备份,就是为了在系统或文件遭到损害时,能及时恢复,把损失减小到最小.当然,对于企业服务器而言,备份的重要性是举足轻重.咱们今天就 ...

  3. android 下载instagram动态中图片的demo

    最近迷上了刷instagram,里面的很多照片都特别喜欢,于是就想分享到朋友圈或者微博,奈何墙外不知墙内苦啊.于是只能想办法将它们保存到本地,既可以做壁纸也能分享给别人. 我发现每条ins的动态在ap ...

  4. multithread synchronization use mutex and semaphore

    #include <malloc.h> #include <pthread.h> #include <semaphore.h> struct job { /* Li ...

  5. SpringMVC Controller详解

    SpringMVC Controller 介绍 一.简介 在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理 ...

  6. oracle学习总结4

    1:三范式a:一张表里必须要有主键,列不可分.b:如果一张表里面,两个字段作为主键,那么其他字段不能够部分依赖这两个字段. 2:pl sql:Procedural language(过程语言) 写一个 ...

  7. windows server 2012R2 网络慢的那些事

    前段时间公司新采购了一台ibm的服务器,装的是 windows server 2012R2, 在做完项目迁移后,发现项目访问数据库缓慢,于是逐项查找原因,最后终于找到解决办法 以Administrat ...

  8. 面试之SQL

    1. 查询性能优化:从数据库查询数据时,你一定遇到过查询很慢的情况,请问你是怎么处理的. 答: 遇到的问题描述:是遇到过这种情况,我们给客户做过一款软件,日志库搜集了6000万条数据,显示.查询时候慢 ...

  9. SpringMVC注册拦截器

    方法1: 拦截所有URL <mvc:interceptors> <bean class="cn.ciss.interceptor.LoginInterceptor" ...

  10. PHP使用缓存生成静态页面

    http://www.cnblogs.com/lh460795/archive/2013/04/06/3003105.html 在apache / bin/ab.exe  可以做压力测试,该工具可以模 ...