题目链接

按题目给出的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. NSIndexPath的初始化方法

    好几次用到了NSIndexPath,但是一直不知道怎么通过 row   section这两个参数来初始化 NSIndexPath *index = [NSIndexPath indexPathForR ...

  2. static和extern关键字 对函数的作用

    本文目录 • 一.extern与函数 • 二.static与函数 • 三.static.extern与函数的总结说明:这个C语言专题,是学习iOS开发的前奏.也为了让有面向对象语言开发经验的程序员,能 ...

  3. Some good questions

    (一)#include <stdio.h>#include <stdlib.h>void getmemory(char *p){ p=(char *) malloc(100); ...

  4. Microsoft Project 2010 简体中文专业版 + 永久激活密钥

    Microsoft Project 2010 简体中文专业版 + 永久激活密钥 (2014-02-17 11:44:16) 转载▼ 标签: 文化 分类: 学习 Microsoft Project已成为 ...

  5. HTML知识点摘记

    HTML HTML:(Hype Text Markup Language)超文本标记语言,是最基本的网页语言.代码由标签组成,不区分大小写. 由<html>开始,</html> ...

  6. Telnet RFC

    http://tools.ietf.org/html/rfc857 http://www.faqs.org/rfcs/rfc854.html 不错: http://blog.csdn.net/chao ...

  7. AspectJ AOP例子

    最近在学习Spring AOP,其中涉及到AspectJ的AOP框架.主要参考:http://howtodoinjava.com/spring/spring-aop/spring-aop-aspect ...

  8. BeanUtils\DBUtils

    BeanUtil: 需要导入 beanutil包和logging日志包 用于给对象属性赋值. setProperty与copyProperty区别: 这个问题搁置,还不会. 将map数据拷贝到对象中, ...

  9. 【菜鸟学习Linux】-第三章- Linux环境搭建-使用VMware9安装Ubuntu 12.04系统

    上一步,我们安装了VMware9虚拟机,现在我们就是用它来安装Ubuntu12.04系统,至于Ubuntu是什么,我就不废话了,大家google一下,比我讲的清楚,好了,开始干活! Ubuntu官网下 ...

  10. android-supporting-multiple-devices

    There are a few common questions asked whenever development begins on a new Android app. What assets ...