Report CodeForces - 631C (栈)
题目大意:给定序列, 给定若干操作, 每次操作将$[1,r]$元素升序或降序排列, 求操作完序列
首先可以发现对最后结果有影响的序列$r$一定非增, 并且是升序降序交替的
可以用单调栈维护这些序列, 再考虑最后如何通过这些序列恢复数组
因为序列是升降交替的, 保存一个排序好的序列, 每次从两端取出元素添加即可
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define x first
#define y second
using namespace std; typedef pair<int,int> pii;
const int N = 4e5+;
int n, m;
int a[N], b[N];
vector<pii> s; int main() {
scanf("%d%d", &n, &m);
REP(i,,n) scanf("%d", a+i);
REP(i,,m) {
int op, pos;
scanf("%d%d", &op, &pos);
while (!s.empty()&&pos>=s.back().y) s.pop_back();
if (s.empty()||op!=s.back().x) s.push_back(pii(op,pos));
}
int L=, R=s[].y;
if (s[].x==) sort(a+,a++R);
else sort(a+,a++R,greater<int>());
REP(i,,R) b[i]=a[i];
int now = R;
s.push_back(pii(,));
REP(i,,s.size()-) {
REP(j,,s[i].y-s[i+].y) {
a[now--]=(i&?b[L++]:b[R--]);
}
}
REP(i,,n) printf("%d%c", a[i]," \n"[i==n]);
}
Report CodeForces - 631C (栈)的更多相关文章
- Codeforces 631C. Report 模拟
C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
- codeforces 631C C. Report
C. Report time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #344 (Div. 2) 631 C. Report (单调栈)
C. Report time limit per test2 seconds memory limit per test256 megabytes inputstandard input output ...
- Codeforces 631C Report【其他】
题意: 给定序列,将前a个数进行逆序或正序排列,多次操作后,求最终得到的序列. 分析: 仔细分析可以想到j<i,且rj小于ri的操作是没有意义的,对于每个i把类似j的操作删去(这里可以用mult ...
- codeforces 631C. Report
题目链接 按题目给出的r, 维护一个递减的数列,然后在末尾补一个0. 比如样例给出的 4 21 2 4 32 31 2 递减的数列就是3 2 0, 操作的时候, 先变[3, 2), 然后变[2, 0) ...
- CodeForces - 631C (截取法)
C. Report time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- Nikita and stack CodeForces - 756C (栈,线段树二分)
大意: 给定m个栈操作push(x)或pop(), 栈空时pop()无作用, 每个操作有执行的时间$t$, 对于每个$0 \le i \le m$, 输出[1,i]的栈操作按时间顺序执行后栈顶元素. ...
- CodeForces - 631C ——(思维题)
Each month Blake gets the report containing main economic indicators of the company "Blake Tech ...
- Codeforces 631C
题意:给定n和m. 给定一个长度为n的序列,m次操作. 接下来m次操作,每行第一个数若为1,则增序排列,若为2则降序排列,第二个数是排列的范围,即从第一个数排序到第某个数. 思路: 首先,对于其中范围 ...
随机推荐
- 数据仓库基础(十二)Informatica组件(2)
本文转载自:http://www.cnblogs.com/evencao/p/3152708.html 1.Router Transformation:在filter 组件中只能写一个过滤条件.而在R ...
- zendstudio中加入对tpl文件的支持,用HTML Editor编辑器编辑
zendstudio中加入对tpl文件的支持,用HTML Editor编辑器编辑:ThinkPHP中默认使用的tpl在zendstudio中默认打开都是文本编辑器的,没有语法提示开发效率很低,直接设置 ...
- C++结构体字节对齐
转自:http://www.cnblogs.com/JensenCat/p/4770171.html 这里是头文件结构的定义: 一个非字节对齐结构体_tagTest2 一个字节对齐_tagTest3 ...
- MySQL Crash Course #12# Chapter 18. Full-Text Searching
INDEX 由于性能.智能结果等多方面原因,在搜索文本时,全文搜索一般要优于通配符和正则表达式,前者为指定列建立索引,以便快速找到对应行,并且将结果集智能排序.启用查询扩展可以让我们得到未必包含关键字 ...
- bootstrap 日期控件常用选项
使用bootstrap作为UI基础之后,为了尽可能的保持系统风格的一致性,通常我们不太会考虑再引入My97DatePicker作为日期控件. 作为潜在实现的选择之一,http://www.bootcs ...
- Python3基础 assert 断言 确保程序的正确运行条件
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- ubuntu下转换flv格式为mp4格式
一.环境 ubuntu 16.04 二.安装工具 sudo apt install libav-tools 三.开始转换 avconv -i input.flv -codec copy output. ...
- 关于jquery所有动画都有速度和动画的方向(在宽度方向上的动画)?
不只是jquery的 animate 动画, 才有时间的 参数, 实际上, 在所有的动画中, 包括: show/hide/toggle, slideup/slidedown/slidetoggle, ...
- 获取Spring项目配置文件元素
在开发中有时候要获取配置文件里的值,通常可以利用如下方式来读取: public class PropertyUtil { private static Properties p = new Prope ...
- redhat 7.2更新yum源时踩的坑
一.update yum .先查看redhat7.2中yum的包版本 [root@localhost jiayimeng]# rpm -qa | grep yum -.el7.noarch -.el7 ...