题目链接

按题目给出的r, 维护一个递减的数列,然后在末尾补一个0。 比如样例给出的

4 2
1 2 4 3
2 3
1 2 递减的数列就是3 2 0, 操作的时候, 先变[3, 2), 然后变[2, 0), 具体的过程看代码。
 
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = 2e5+;
int st[], a[maxn], b[maxn], c[maxn];
int main()
{
int n, m, sign, pos;
cin>>n>>m;
for(int i = ; i<=n; i++)
scanf("%d", &a[i]);
int r = ;
for(int i = ; i<m; i++) {
scanf("%d%d", &sign, &pos);
while(r>&&pos>=st[r-])
r--;
st[r] = pos, b[r] = sign;
r++;
}
st[r++] = ;
int l = , rr = st[];
for(int i = ; i<=n; i++)
c[i] = a[i];
sort(c+, c++rr);
for(int i = ; i<r; i++) {
for(int j = st[i-]; j>st[i]; j--) {
a[j] = (b[i-] == )?c[l++]:c[rr--];
}
}
for(int i = ; i<=n; i++)
printf("%d ", a[i]);
return ;
}

  

codeforces 631C. Report的更多相关文章

  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 Report【其他】

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

  3. codeforces 631C C. Report

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

  4. Report CodeForces - 631C (栈)

    题目链接 题目大意:给定序列, 给定若干操作, 每次操作将$[1,r]$元素升序或降序排列, 求操作完序列 首先可以发现对最后结果有影响的序列$r$一定非增, 并且是升序降序交替的 可以用单调栈维护这 ...

  5. CodeForces - 631C (截取法)

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

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

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

  7. CF 631C report

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

  8. Codeforces 631C

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

  9. CodeForces 631C Print Check

    排序+构造+预处理 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm ...

随机推荐

  1. TCP应用编程--套接字C#实现

     套接字之间的连接过程可以分为三个步骤: 1.服务器监听 2.客户端请求 3.连接确认 Ø服务器监听:是指服务器套接字并不定位具体的客户端套接字,而 是处于等待连接的状态,实时监控网络状态. Ø客户端 ...

  2. UTL_FILE 的用法

    UTL_FILE 的用法   UTL_FILE 是用来进行文件IO处理的专用包,使用这外包的注意事项如下: 1. 生成的文件好象只能放置在DATABASE所在的服务器路径中. 2. 生成的文件如何DO ...

  3. Java中如何把两个数组合并为一个

    在Java中,如何把两个String[]合并为一个? 看起来是一个很简单的问题.但是如何才能把代码写得高效简洁,却还是值得思考的.这里介绍四种方法,请参考选用. 一.apache-commons 这是 ...

  4. 开源一个监控数据采集Agent:OpenFalcon-SuitAgent

    OpenFalcon-SuitAgent 项目地址:github 版本说明 本系统版本划分如下 alpha:内部测试版(不建议使用于生产环境) beta:公开测试版(不建议使用于生产环境) final ...

  5. poco vs Boost[ZZ]

    http://wooce.iteye.com/blog/634395 POCO的优点: 1) 比boost更好的线程库,特别是一个活动的方法的实现,并且还可设置线程的优先级. 2) 比 boost:a ...

  6. phpStrom添加插件:php文档生成(phpDocumentor)

    1. 依次打开:Files => Settings => External Tools => +(add) 2. 填写信息:name:phpDoc; group:PHP插件; des ...

  7. Python的编码规范(PEP 8 & Google Python guide)

    PEP 8 Python 代码规范整理 click here Goole Python 风格指南 中文版 click here 大家有取舍的看吧. 因为文章不是原创的,所以只贴地址,给大家造成麻烦了, ...

  8. 添加EF上下文对象,添加接口、实现类以及无处不在的依赖注入(DI)

    添加EF上下文对象,添加接口.实现类以及无处不在的依赖注入(DI) 目录索引 [无私分享:ASP.NET CORE 项目实战]目录索引 简介 上一章,我们介绍了安装和新建控制器.视图,这一章我们来创建 ...

  9. delphi 7中使用idhttp抓取网页 解决假死现象

    在delphi 7中使用idhttp抓取网页,造成窗口无反应的假死状态.通过搜索获得两种方法. 1.写在线程中,但是调用比较麻烦 2.使用delphi 提供的idantifreeze(必须安装indy ...

  10. Centos6.8下安装oracle_11gr2版主要过程

    安装前准备 下载oracle版本 地址:http://docs.oracle.com/cd/E21901_01/index.html ,下载2个文件分别是 linux.x64_11gR2_databa ...