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.

分析

  这题其实不是很难,蒟蒻的我都一眼找出了规律,首先,它不管是顺着排序还是倒着排序,如果某次操作比前边的一次操作范围大,那么前边的那次操作其实是无效的,另外,如果操作中最大的右端点到r,那么r再往后的区间是不会被修改的。因为操作的时候是修改1~r,所以前边的区间会被多次修改,而后边的区间则只会被最后那次不重叠的修改,如下图。

假如从1到i有很多次操作,从i到j有且仅有一次操作,那么我区间(i,j]的值就能确定,如果是由大到小排,那么j的位置一定是1,反之亦然,所以定义一个头指针和尾指针,倒着扫描一遍整个序列就好。

 #include<iostream>
#include<algorithm>
using namespace std;
const int N=2e5+;
int a[N],ans[N],idx[N],typ[N];
int main(){
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++)
cin>>a[i];
int mx=;
for(int i=;i<=m;i++){
int t,r;
cin>>t>>r;
idx[r]=i;
typ[r]=t;
mx=max(mx,r);
}
sort(a+,a+mx+);
int flag,now=,hh=,tt=mx;
for(int i=mx;i;i--){
if(now<idx[i]){
now=idx[i];
flag=typ[i];
}
if(flag==)
ans[i]=a[tt--];
else ans[i]=a[hh++];
}
for(int i=;i<=mx;i++)
cout<<ans[i]<<" ";
for(int i=mx+;i<=n;i++)
cout<<a[i]<<" ";
return ;
}

CF 631C report的更多相关文章

  1. Codeforces 631C. Report 模拟

    C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

  2. codeforces 631C. Report

    题目链接 按题目给出的r, 维护一个递减的数列,然后在末尾补一个0. 比如样例给出的 4 21 2 4 32 31 2 递减的数列就是3 2 0, 操作的时候, 先变[3, 2), 然后变[2, 0) ...

  3. Codeforces 631C Report【其他】

    题意: 给定序列,将前a个数进行逆序或正序排列,多次操作后,求最终得到的序列. 分析: 仔细分析可以想到j<i,且rj小于ri的操作是没有意义的,对于每个i把类似j的操作删去(这里可以用mult ...

  4. Spring Boot 入门(十二):报表导出,对比poi、jxl和esayExcel的效率

    本片博客是紧接着Spring Boot 入门(十一):集成 WebSocket, 实时显示系统日志写的 关于poi.jxl和esayExcel的介绍自行百度. jxl最多支持03版excel,所以单个 ...

  5. codeforces每日一题1-10

    目录: 1.1093D. Beautiful Graph(DFS染色) 2.514C - Watto and Mechanism(Tire) 3.69E.Subsegments(STL) 4.25C. ...

  6. codeforces 631C C. Report

    C. Report time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  7. CF #CROC 2016 - Elimination Round D. Robot Rapping Results Report 二分+拓扑排序

    题目链接:http://codeforces.com/contest/655/problem/D 大意是给若干对偏序,问最少需要前多少对关系,可以确定所有的大小关系. 解法是二分答案,利用拓扑排序看是 ...

  8. Report CodeForces - 631C (栈)

    题目链接 题目大意:给定序列, 给定若干操作, 每次操作将$[1,r]$元素升序或降序排列, 求操作完序列 首先可以发现对最后结果有影响的序列$r$一定非增, 并且是升序降序交替的 可以用单调栈维护这 ...

  9. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

随机推荐

  1. 深度视觉盛宴——CVPR 2016

    小编按: 计算机视觉和模式识别领域顶级会议CVPR 2016于六月末在拉斯维加斯举行.微软亚洲研究院在此次大会上共有多达15篇论文入选,这背后也少不了微软亚洲研究院的实习生的贡献.大会结束之后,小编第 ...

  2. ECMA5中定义的对象属性特性和方法

    ECMA5规定了只有内部才有的特性,描述了属性的各种特征,这些特性用于实现JavaScript引擎,因此在Js中不能直接访问他们.为了标识特性,我们一般会他们放入两对方括号中. ECMAScript中 ...

  3. 《N诺机试指南》(八)日期、字符串、排序问题

    1.日期问题: 输入: 例题: 代码: #include <stdio.h> #include <bits/stdc++.h> struct node{ int year, m ...

  4. 达拉草201771010105《面向对象程序设计(java)》第十五周学习总结

    达拉草201771010105<面向对象程序设计(java)>第十四周学习总结 第一部分:理论知识 JAR文件: 1.Java程序的打包:程序编译完成后,程序员 将.class文件压缩打包 ...

  5. linux同步当前网络时间

    [root@root ~]# yum install -y ntpdate 执行:ntpdate[root@root ~]# ntpdate 120.24.81.91或[root@root ~]# n ...

  6. 网站开发---js与java实现的一些小功能

    记录一下网站开发过程中的一些小功能 1.js获取当前年份: <span>Copyright © 2017-<script>document.write( new Date(). ...

  7. .Net Core项目中整合Serilog

    前言:Serilog是.NET应用程序的诊断日志记录库.它易于设置,具有简洁的API,并且可以在所有最新的.NET平台上运行.尽管即使在最简单的应用程序中它也很有用,但当对复杂的,分布式的和异步的应用 ...

  8. new Date在IOS下面的兼容问题

    此问题坑爹啊,着实坑爹,要不是本宝宝鬼机灵再次进行了测试,不然测试都测不出来的问题,问题源头,有两个时间: let start =  "2018-08-08 00:00:00" ; ...

  9. 第四篇(1):企业常用Linux web环境安装配置(apache、php、mysql)

    上篇我们讲了基本的软件包管理和文件操作什么的,现在也要动手安装点有用的东西了吧! 本篇我会写出一个用yum安装apache.php.mysql的方法,最后再运行phpMyAdmin来管理数据库. 1. ...

  10. [android]R.class里有ID,onCreate方法里调用findViewById返回空

    在做android练习,一个新手错误,记录一下: 在练习android权威编程指南时,第5章 第二个Activity部分练习,出现标题问题,代码还原如下: protected void onCreat ...