题目链接

题目大意:给定序列, 给定若干操作, 每次操作将$[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. iOS可执行文件__TEXT段限制 以及 Android 65K函数限制

    1.先看下苹果关于 .ipa上传的大小规定: 最大构建版本文件大小 解压 XXX.ipa size Payload/xxx.app/xxx  32位  32位 + 64位 有些2dx.u3d游戏 或是 ...

  2. QQ在线客服,默认到要加好友,授权也不起作用需要先开通QQ营销服务

    QQ在线客服,默认到要加好友,授权也不起作用需要先开通QQ营销服务http://wpa.qq.com/msgrd?v=3&uin=你的客服QQ号码&site=qq&menu=y ...

  3. 学写网页 #04# w3school

    索引: HTML 输入类型 XHTML HTML5 HTML5 样式指南和代码约定 WHO 成立于 1948 年. 对缩写进行标记能够为浏览器.翻译系统以及搜索引擎提供有用的信息. code 元素不保 ...

  4. awk之match函数

    功能:match函数是用于个性化定制搜索模式. 例子: 文件内容: this is wang ,not wan that is chen, not che this is chen ,and wang ...

  5. 20144303石宇森《网络对抗》注入shellcode和Return-to-libc攻击

    20144303石宇森<网络对抗>PC平台逆向破解 实验1:shellcode注入 实验基础 1.Linux下有两种基本构造攻击buf的方法:retaddr+nop+shellcode,n ...

  6. TCP 的连接建立:采用三报文握手

  7. C#中的基本类型理解

    1.C#把所有基本类型都封装成自己的类型了,如下图,int被封装成了一个struct结构体.如果定义一个int对象,是可以调用int结构体里的函数的 2.和C\C++不同,C#的char就是单纯的代表 ...

  8. 自己写操作系统---bootsector篇

    其实博主本来想在寒假自己写一个OSkernal的,高高兴兴的影印了本<一个操作系统的实现>. 然后又去图书馆借来<30天自制操作系统>和<X86/X64体系探索编程> ...

  9. Chromosome coordinate systems: 0-based, 1-based

    From: https://arnaudceol.wordpress.com/2014/09/18/chromosome-coordinate-systems-0-based-1-based/ I’v ...

  10. animate动画回调函数

    对非动画的实现排队,比如这个css()是要放在回调函数里才能,让前面的动画执行完成后在进行实现 $('button').click(function(event) { $(this).next().a ...