题意:

给定序列,将前a个数进行逆序或正序排列,多次操作后,求最终得到的序列。

分析:

仔细分析可以想到j<i,且rj小于ri的操作是没有意义的,对于每个i把类似j的操作删去(这里可以用multiset或者直接模拟栈的操作),最后我们会获得一个严格下降的序列即ri>rj && i<j,并且相邻的t不相等。

那么对于ri,ri+1,对[0,ri)进行排序后,又对其子序列[0,ri+1)进行相反的排序,其实只有区间[ri+1,ri−1]]内的数是按照ti规定的排序的,并且不会再改变。所以我们只需要根据ti获取[ri+1,ri−1]]之间的值即可。

那么如何获取呢?在头尾两头设两个指针,如果对应区间要求升序,则用大的数填,否则用小的数填上。

代码:

用multiset做(做题太少第一次用set的erase)

#include <cstdio>
#include<set>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn = 200005;
int a[maxn], b[maxn];
typedef pair<int, int>p;
#define fi first
#define se second
multiset<p>ms;
int main (void)
{
int n, m;scanf("%d%d", &n, &m);
for(int i = 0; i < n; i++){
scanf("%d", &a[i]);
b[i] = a[i];
}
int maxr = 0;
int r, t;
multiset<p>::iterator pos;
multiset<p>::iterator rp;
for(int i = 0; i < m; i++){
scanf("%d%d", &t, &r);
p tp = p(r, t);
maxr = max(maxr, r);
rp = ms.begin();
while(rp ->first <= tp.first && rp!=ms.end())
ms.erase(rp++);
ms.insert(tp);
}
sort(b, b + maxr);
int u = maxr - 1, l = 0;
pos = ms.end();
pos--;
int cnt = 0;
while(cnt < ms.size()){
int tmp = pos->se;
cnt++;
if(cnt == ms.size()){
for(int j = (pos->fi) - 1; j >=0; j--){
if(tmp == 1) a[j] = b[u--];
else a[j] = b[l++];
}
}
else{
rp = pos--;
for(int j = (rp->fi) - 1; j >= pos->fi; j--){
if(tmp == 1) a[j] = b[u--];
else a[j] = b[l++];
}
}
}
for(int i = 0; i < n; i++){
printf("%d%c", a[i], i == n - 1?'\n':' ' );
}
return 0;
}

模拟栈的操作

#include <cstdio>
#include<algorithm>
using namespace std;//区间递减且t交叉
const int maxn = 200005;
int a[maxn], b[maxn], t[maxn], r[maxn];
int main (void)
{
int n, m;scanf("%d%d", &n, &m);
for(int i = 0; i < n; i++){
scanf("%d", &a[i]);
b[i] = a[i];
}
int s = 0;
for(int i = 0; i < m; i++){
scanf("%d%d", &t[i], &r[i]);
while(s > 0 && r[i] >= r[s - 1]){
s--;
}
t[s] = t[i], r[s] = r[i]; s++;
}
sort(b, b + r[0]);
int l = r[0] - 1, u = 0;
r[s] = 0;
for(int i = 1; i < s + 1; i++){
for(int j = r[i - 1] - 1; j >= r[i]; j--){
if(t[i - 1] == 2) a[j] = b[u++];
else a[j] = b[l--];
}
}
//for(int i = 0; i < n; i++) printf("%d",b[i]);
for(int i = 0; i < n; i++)
printf("%d%c", a[i], i==n-1?'\n':' ');
return 0;
}

智商捉急。。。。比赛的时候就是想不到怎么保存有意义的操作, 就断定这题是一定是要用到自己没学过的数据结构。。真的要对自己自信呀~~思考思考!!

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

    题目链接 按题目给出的r, 维护一个递减的数列,然后在末尾补一个0. 比如样例给出的 4 21 2 4 32 31 2 递减的数列就是3 2 0, 操作的时候, 先变[3, 2), 然后变[2, 0) ...

  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. 防止系统页面被加载进 iframe 子窗口

    在controller的返回的响应头中添加 response.addHeader("x-frame-options", "DENY");  即可

  2. Windows下的一个Nginx 批处理命令行控制台

    其实作用很简单,就是为了少输入几个字母,完成对Nginx的控制而已,同时也算是练习了一把bat批处理吧. @echo off&color e&Title Nginx 命令行控制台 cl ...

  3. js实现表单checkbox的单选,全选

    全选&单选 //<input type="checkbox" name="" class="quan" value=" ...

  4. (2)《Head First HTML与CSS》学习笔记---img与基于标准的HTML5

    1.浏览器处理图像的过程: 1.服务器获取文件,显示出文本结构,以及预留默认的大小给<img>(如果该<img>有width-1值和height-1值,则根据这个值提前设好页面 ...

  5. Android开源项目:GifView——Android显示GIF动画

    下载:http://code.google.com/p/gifview/downloads/list 简介:android中现在没有直接显示gif的view,只能通过mediaplay来显示,且还常常 ...

  6. axis2客户端的几种调用方式

    (1)使用RPC方式调用WebService // 使用RPC方式调用WebService RPCServiceClient serviceClient = new RPCServiceClient( ...

  7. jQuery之Validation表单验证插件使用

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> <met ...

  8. Sass的的使用二

    1.嵌套输出方式 nested Sass 提供了一种嵌套显示 CSS 文件的方式.例如 nav { ul { margin: 0; padding: 0; list-style: none; } li ...

  9. C/C++ 数组、字符串、string

    1.定义数组时,数组中元素的个数不能是动态的,不能用变量表示(const变量可以),必须是已知的. 2.引用数组时只能引用数组中某个元素,不能引用整个数组. 3.定义二维数组时,若同时全部初始化,则可 ...

  10. leetcode_357. Count Numbers with Unique Digits

    https://leetcode.com/problems/count-numbers-with-unique-digits/ 给定一个n,计算[0,10^n]中十进制中每一位都不相同的数的数目. c ...