CF 631C report
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的更多相关文章
- Codeforces 631C. Report 模拟
C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
- codeforces 631C. Report
题目链接 按题目给出的r, 维护一个递减的数列,然后在末尾补一个0. 比如样例给出的 4 21 2 4 32 31 2 递减的数列就是3 2 0, 操作的时候, 先变[3, 2), 然后变[2, 0) ...
- Codeforces 631C Report【其他】
题意: 给定序列,将前a个数进行逆序或正序排列,多次操作后,求最终得到的序列. 分析: 仔细分析可以想到j<i,且rj小于ri的操作是没有意义的,对于每个i把类似j的操作删去(这里可以用mult ...
- Spring Boot 入门(十二):报表导出,对比poi、jxl和esayExcel的效率
本片博客是紧接着Spring Boot 入门(十一):集成 WebSocket, 实时显示系统日志写的 关于poi.jxl和esayExcel的介绍自行百度. jxl最多支持03版excel,所以单个 ...
- codeforces每日一题1-10
目录: 1.1093D. Beautiful Graph(DFS染色) 2.514C - Watto and Mechanism(Tire) 3.69E.Subsegments(STL) 4.25C. ...
- codeforces 631C C. Report
C. Report time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- CF #CROC 2016 - Elimination Round D. Robot Rapping Results Report 二分+拓扑排序
题目链接:http://codeforces.com/contest/655/problem/D 大意是给若干对偏序,问最少需要前多少对关系,可以确定所有的大小关系. 解法是二分答案,利用拓扑排序看是 ...
- Report CodeForces - 631C (栈)
题目链接 题目大意:给定序列, 给定若干操作, 每次操作将$[1,r]$元素升序或降序排列, 求操作完序列 首先可以发现对最后结果有影响的序列$r$一定非增, 并且是升序降序交替的 可以用单调栈维护这 ...
- 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 ...
随机推荐
- 一款属于自己的笔记本【vue+gin+elementUI前后端分离开发部署开源项目】
前言 我为什么要写一个个人的云笔记? (⊙o⊙)-额额额
- python3.5以及scrapy,selenium,等 安装
一.python3.5安装和配置 在安装的时候无意间发现了,python3.6没有给我自定义安装的机会,直接就C盘见:因此我选择了python3.5.<安装部分跳过,至于一条吃过痛苦的建议:不要 ...
- Java 线程基础知识
前言 什么是线程?线程,有时被称为轻量进程(Lightweight Process,LWP),是程序执行流的最小单元.一个标准的线程由线程 ID,当前指令指针 (PC),寄存器集合和堆栈组成.另外,线 ...
- JZOJ 3927. 【NOIP2014模拟11.6】可见点数
3927. [NOIP2014模拟11.6]可见点数 (Standard IO) Time Limits: 1000 ms Memory Limits: 65536 KB Description ZP ...
- nor flash之4字节地址模式
背景 容量低于 16M bytes 的 nor,一般使用 3 字节地址模式,即命令格式是 cmd + addr[2] + addr[1] + addr[0] + ... 使用超过 16M bytes ...
- SuperBenchmarker一个用.NET编写的压测工具
0x01 前言 在这之前想必大家对ab(http)与abs(https)也有一些了解,我们今天不去看ab和abs,SuperBenchmarker(sb.exe)是一个压测工具,他是一个受Apache ...
- 没想到MySQL还会问这些...
前言 文本已收录至我的GitHub精选文章,欢迎Star:https://github.com/ZhongFuCheng3y/3y 在前一阵子,大哥问过我:"你知道MySQL的原子性是怎么保 ...
- JavaScript的自调用函数
函数表达式可以 "自调用". 自调用表达式会自动调用. 如果表达式后面紧跟 () ,则会自动调用. 不能自调用声明的函数. 通过添加括号,来说明它是一个函数表达式: <scr ...
- plantUML最佳实践
plantUML 使用plantUML中的活动图用来画流程图很好用; 但类图等就不很好用; 个人体会如下: • 时序图 推荐 • 用例图 一般 • 类 图 不推荐, 用Visual Paradigm或 ...
- vue项目 github 上传项目并链接地址
git init git init: 通过命令git init把这个文件夹变成Git可管理的仓库git status git status:查看当前仓库状态 git add . 这里提示你虽然把项目粘 ...