题目链接

按题目给出的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. 简述Linq中.ToList(), .AsEnumerable(), AsQueryable()的区别和用法

    [TOC] 这3个方法的功能完全不同, 应按照具体业务场景使用. AsQueryable() 先说说什么是 IQueryable IQueryable 是当前的 data provider 返回的类型 ...

  2. vb.net常用函数

    当然,这些都可以从MSDN查到,但是有时候打开帮助老慢的,所以先放到这里放一放,查个函数什么的比较快一点.都是从网上搜来的.Abs(number) 取得数值的绝对值. Asc(String) 取得字符 ...

  3. NSThread 的用法

    一.线程的注意点: 1.不要同时开太多的线程(最多不要超过5条,其中包括主线程) 2.线程概念 2.1.主线程:UI 线程,显示.刷新 UI 界面,处理 UI 控件的事件 2.2.子线程:后台线程,异 ...

  4. shell 比较

    整数比较 -eq 等于,如:if [ "$a" -eq "$b" ] -ne 不等于,如:if [ "$a" -ne "$b&qu ...

  5. java打包/命令行方式运行jar(命令行进行程序测试)

    public class Testtmp { public static void main(String[] args) { // TODO Auto-generated method stub f ...

  6. python 杨辉三角 算法实现

    def triangles(level): n = 1 L = [] while n <=level: if n <= 2: L.append(1) yield L elif n > ...

  7. poco vs Boost[ZZ]

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

  8. IE 第三方设置cookie失效

    公司的产品,采用多服务分摊压力,中间必须涉及的当然是单点登陆.一般的单点登陆都是通过去用户中心登陆,302或页面回调的方式,返回到登陆前的页面. 公司项目,想用户体验更好些,采用弹框登陆,可以考虑if ...

  9. raphael 支持group(简)

    raphael 不支持group,里面有的set方法,只是把对象数组存起来,方法调用的时候,遍历都调用下,但是在实际需求上面感觉group还是瞒有用处的,可以控制group下面的节点的交互 比如地图区 ...

  10. C 中注意的小问题

    输入:char ch[100],gets(ch); scanf("%d",&in); char ch,ch=getchar(); VC:  所有变量声明放在所有操作前面: ...