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. Maven项目中如何添加日志

  2. 分享一个字数限制和统计的UITextView分类方法

    - (NSUInteger)letterCountWithLimits:(NSInteger)limits { NSString *toBeString = self.text; NSUInteger ...

  3. Sharepoint 移动客户端 Rshare的特点

    1.随时随地快速访问SharePoint,和同事高效合作,实时浏览日历信息,完整日程安排.查看联系人信息.浏览公告,文档和图片等. 添加图片到相册,通过Email和他人分享. 2.新建.上传:新建日历 ...

  4. Map集合的两种遍历方式

    Map集合:即 接口Map<K,V> map集合的两种取出方式:    1.Set<k> keyset: 将map中所有的键存入到set集合(即将所有的key值存入到set中) ...

  5. 用jsp方式通知客户端下载文件

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  6. JAXB - Annotations, Top-level Elements: XmlRootElement

    A class that describes an XML element that is to be a top-level element, i.e., one that can function ...

  7. 偶尔会用到的有用的CMD命令

    1.解压CHM cd /d (如果你的chm文档在系统盘的话,就没有必要写这个/d) [你的chm文档的路径名] 回车 hh -decompile [源文件的保存路径] [要反编译的chm格式电子书] ...

  8. ###Linux基础 - 2

    点击查看Evernote原文. #@author: gr #@date: 2014-10-13 #@email: forgerui@gmail.com 一.Linux基础命令2 mount: 挂载U盘 ...

  9. ###《More Effective C++》- 基础议题

    More Effective C++ #@author: gr #@date: 2015-05-11 #@email: forgerui@gmail.com 一.仔细区别pointers和refere ...

  10. Ajax的概述与实现过程

    一.ajax概述 1.Ajax是Asynchronous([ə'sɪŋkrənəs) JavaScript XML的简写,不是一门新技术,而是对现有技术的综合利用.这一技术能够向服务器请求额外数据而无 ...