题目链接

题目大意:给定序列, 给定若干操作, 每次操作将$[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. Python2 和Python3 的差异总结

    一.基本语法差异 1.1 核心类差异 Python3对Unicode字符的原生支持 Python2中使用 ASCII 码作为默认编码方式导致string有两种类型str和unicode,Python3 ...

  2. Nginx启动SSL功能

    Nginx启动SSL功能,并进行功能优化,你看这个就足够了 一:开始Nginx的SSL模块 1.1 Nginx如果未开启SSL模块,配置Https时提示错误 nginx: [emerg] the &q ...

  3. JDBC报错记录

    用JDBC连接oracle时 有如下问题: 问题一.java.lang.ClassNotFoundException: oracle.jdbc.driver.oracledriver 解决: 可以在环 ...

  4. C/C++中的位运算

    位运算     位运算的运算分量只能是整型或字符型数据,位运算把运算对象看作是由二进位组成的位串信息,按位完成指定的运算,得到位串信息的结果. 位运算符有:     &(按位与).|(按位或) ...

  5. Django框架介绍之cookie与session

    cookie http请求时无状态的,一个客户端第一次,第二次,第n次访问同一个服务器都是一样的,服务器都会按照一个新的连接处理.但是,有时候客户端需要服务器记住客户端的登录状态,譬如离开一会,回来之 ...

  6. 一个风控计算负载过高到mysql主从拆分暴露的各种设计复杂性问题以及解决方法总结

    在很多系统(包括金融类和非金融类)中,其实有大量的系统在很长的一段时间内(具体多长时间视业务的成功与否而定)都是混合型系统,也就是同时具有OLTP+OLAP的业务.我们说任何形式的存在在特定阶段都是合 ...

  7. Django框架(四) Django之视图层

    视图函数 一个视图函数,简称视图,是一个简单的Python 函数,它接受Web请求并且返回Web响应.响应可以是一张网页的HTML内容,一个重定向,一个404错误,一个XML文档,或者一张图片. . ...

  8. 风景区的面积及道路状况分析问题 test

    参考文献:   https://wenku.baidu.com/view/b6aed86baf1ffc4ffe47ac92.html #include <bits/stdc++.h> us ...

  9. Avito Cool Challenge 2018

    考挂了.. A - Definite Game 直接看代码吧. #include<cstdio> #include<cstring> #include<algorithm ...

  10. 关于 Local feature 和 Global feature 的组合

     关于  Local feature 和 Global feature 的组合     1.全局上下文建模: