题目链接

题目大意:给定序列, 给定若干操作, 每次操作将$[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. bzoj1704 / P2882 [USACO07MAR]面对正确的方式Face The Right Way

    P2882 [USACO07MAR]面对正确的方式Face The Right Way $n<=5000$?枚举翻转长度,顺序模拟就ok了 对于每次翻转,我们可以利用差分的思想,再搞搞前缀和. ...

  2. 20145122《敏捷开发与XP实践 》实验三实验报告

    实验名称 敏捷开发与XP实践 实验内容 1.团队代码要使用git在实验楼中托管,要使用结对同学中的一个同学的账号托管. 2.使用git推送代码并对结对同学的代码修改完成后再git推送. 3.掌握重构流 ...

  3. 利用RNN(lstm)生成文本【转】

    本文转载自:https://www.jianshu.com/p/1a4f7f5b05ae 致谢以及参考 最近在做序列化标注项目,试着理解rnn的设计结构以及tensorflow中的具体实现方法.在知乎 ...

  4. Faster-RCNN-TensorFlow-Python3.5 在Ubuntu16.04下的配置方法

    目录 Faster-RCNN-TensorFlow-Python3.5 在Ubuntu16.04下的配置方法 安装过程 1. 深度学习环境Tensorflow的安装 2. 安装python包 3.   ...

  5. HDU 5877 Weak Pair(树状数组+dfs+离散化)

    http://acm.hdu.edu.cn/showproblem.php?pid=5877 题意: 给出一棵树,每个顶点都有权值,现在要你找出满足要求的点对(u,v)数,u是v的祖先并且a[u]*a ...

  6. 【Python】【元编程】【二】【描述符】

    """ #描述符实例是托管类的类属性:此外,托管类还有自己实例的同名属性 #20.1.1 LineItem类第三版:一个简单的描述符#栗子20-1 dulkfood_v3 ...

  7. React Native API之 ActionSheetIOS

    ok!先来演示是下效果: 官网教程:http://reactnative.cn/docs/0.31/actionsheetios.html#content 上代码:引入API组件: import Re ...

  8. hdu 2874 Connections between cities 带权lca判是否联通

    Connections between cities Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

  9. python网络编程之TCP通信实例

    一. server.py import socket host="localhost" port= s=socket.socket(socket.AF_INET,socket.SO ...

  10. 将正在使用的Ubuntu14.04 制作成镜像文件

    remastersys 是一个能够备份你的ubuntu系统的工具. 源码在github上能找到:Remastersys Source 可以直接 apt 安装: sudo add-apt-reposit ...