题目链接

题目大意:给定序列, 给定若干操作, 每次操作将$[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 (栈)的更多相关文章

  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 C. Report

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

  3. Codeforces Round #344 (Div. 2) 631 C. Report (单调栈)

    C. Report time limit per test2 seconds memory limit per test256 megabytes inputstandard input output ...

  4. Codeforces 631C Report【其他】

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

  5. codeforces 631C. Report

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

  6. CodeForces - 631C (截取法)

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

  7. Nikita and stack CodeForces - 756C (栈,线段树二分)

    大意: 给定m个栈操作push(x)或pop(), 栈空时pop()无作用, 每个操作有执行的时间$t$, 对于每个$0 \le i \le m$, 输出[1,i]的栈操作按时间顺序执行后栈顶元素. ...

  8. CodeForces - 631C ——(思维题)

    Each month Blake gets the report containing main economic indicators of the company "Blake Tech ...

  9. Codeforces 631C

    题意:给定n和m. 给定一个长度为n的序列,m次操作. 接下来m次操作,每行第一个数若为1,则增序排列,若为2则降序排列,第二个数是排列的范围,即从第一个数排序到第某个数. 思路: 首先,对于其中范围 ...

随机推荐

  1. Open-Falcon

    A Distributed and High-Performance Monitoring System Scalability Scalable monitoring system is neces ...

  2. win7 xampp 验证码,session出不来的问题

    win7 xampp 验证码,session出不来的问题 需要在前面加上全路径,如:"\xampp\tmp" 变成"D:\xampp\tmp" Warning: ...

  3. Java高并发高性能分布式框架从无到有微服务架构设计

    微服务架构模式(Microservice Architect Pattern).近两年在服务的疯狂增长与云计算技术的进步,让微服务架构受到重点关注 微服务架构是一种架构模式,它提倡将单一应用程序划分成 ...

  4. 20145106 java实验二

    1)复数类ComplexNumber的属性 m_dRealPart: 实部,代表复数的实数部分 m_dImaginPart: 虚部,代表复数的虚数部分 public class ComplexNumb ...

  5. 20145118 《Java程序设计》第6周学习总结

    20145118 <Java程序设计>第6周学习总结 教材学习内容总结 1.数据依靠串流在目的地与来源地之间传输,无论来去如何,只要取得InputStream或OutputStream的实 ...

  6. 20145329 《网络对抗技术》客户端Adobe阅读器渗透攻击

    两台虚拟机: kali ip:192.168.96.130 windows xp sp3 ip:192.168.96.133 1.kali下打开显示隐藏文件 2.在kali终端中开启msfconsol ...

  7. Spring Aop的理解和简单实现

    1.AOP概念 所说的面向切面编程其实就是在处理一系列业务逻辑的时候这一系列动作看成一个动作集合.比如连接数据库来说: 加载驱动-----获取class--------获取连接对象-------访问数 ...

  8. 权限管理,pymysql模块

    权限管理 权限管理重点 MySQL 默认有个root用户,但是这个用户权限太大,一般只在管理数据库时候才用.如果在项目中要连接 MySQL 数据库,则建议新建一个权限较小的用户来连接. 在 MySQL ...

  9. BZOJ 3992 【SDOI2015】 序列统计

    题目链接:序列统计 我来复习板子了……这道题也是我写的第一发求原根啊? 求原根方法: 从小到大依次枚举原根.设当前枚举的原根为\(x\),模数为\(p\),\(p-1\)的质因数分别为\(p_1,p_ ...

  10. Java中Arrays 与 Collections 的简单操作

    import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.C ...