题目链接

按题目给出的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. iOS坐标转换

    // 将像素point由point所在视图转换到目标视图view中,返回在目标视图view中的像素值 - (CGPoint)convertPoint:(CGPoint)point toView:(UI ...

  2. 获取iOS设备属性

    通过使用UIDevice: [[UIDevice currentDevice] systemName]; [[UIDevice currentDevice] systemVersion];//os v ...

  3. JVM学习之强引用、弱引用、软引用、虚引用

    转自:http://my.oschina.net/ydsakyclguozi/blog/404389 多谢博主分享 1.强引用(StrongReference) 强引用是使用最普遍的引用.如果一个对象 ...

  4. php程序员的弱点

    今天在在知乎上看到一个问题,题目是<看了laravel的php框架怎么感觉很不靠谱?>,我最近也在想学习一下laravel,laravel听说是受到很大ruby on rails的影响. ...

  5. @RISK

    Price: AUD $3,295.00   Price: AUD $2,495.00   适用于项目管理的 @RISK 免费试用版下载 » 立即购买 » 价格对比 » 许可选项 (英文) » 教学计 ...

  6. Oracle EBS-SQL (SYS-12):查询各Profile的设置情况.sql

    SELECT pro.profile_option_name, pro.user_profile_option_name, lev.level_type TYPE, --lev.level_code, ...

  7. Oracle EBS-SQL (SYS-11):查询系统已打的PATCH.sql

    select a.patch_name,         b.DRIVER_FILE_NAME,         c.language,         b.creation_datefrom app ...

  8. 鼠标进入与离开的消息(覆盖CM_MOUSEENTER与CM_MOUSELEAVE消息)——Windows本身没有这样的消息

    unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ...

  9. Protection 5 ---- Priviliege Level Checking 2

    CPU不仅仅在程序访问数据段和堆栈段的时候进行权限级别检查,当程序控制权转换的时候也会进行权限级别检查.程序控制权转换的情况很多,各种情况下检查的方式以及涉及到的检查项都是不同的.这篇文章主要描述了各 ...

  10. nautilus-open-terminal右键随处打开终端

    Nautilus-Open-Terminal : 可随处打开终端的 Nautilus 插件 nautilus-open-terminal-0.17-4.el6.x86_64 是一个让你随处都可以打开终 ...