题目:Report

题意:有两种操作:

        1)t = 1,前r个数字按升序排列;
          2)t = 2,前r个数字按降序排列;

       求执行m次操作后的排列顺序。

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <cmath>
  6. #include <cstdio>
  7. #include <string>
  8. #include <cstring>
  9. #include <vector>
  10. #include <queue>
  11. #include <stack>
  12. #include <set>
  13.  
  14. #define c_false ios_base::sync_with_stdio(false); cin.tie(0)
  15. #define INF 0x3f3f3f3f
  16. #define INFL 0x3f3f3f3f3f3f3f3f
  17. #define zero_(x,y) memset(x , y , sizeof(x))
  18. #define zero(x) memset(x , 0 , sizeof(x))
  19. #define MAX(x) memset(x , 0x3f ,sizeof(x))
  20. using namespace std;
  21. #define N 200005
  22. const int M = 1e9 +;
  23. typedef long long LL;
  24. int a[N];
  25. struct manager{
  26. int t,r;
  27. }ma[N];
  28. int b[N];
  29. int main(){
  30. //freopen("in.txt","r",stdin);
  31. //freopen("out.txt","w",stdout);
  32. int n, m;
  33. scanf("%d%d",&n,&m);
  34. for(int i = ; i < n;i++){
  35. scanf("%d",a+i);
  36. }
  37. int k = ,x,y;
  38. while (m--){
  39. scanf("%d%d", &x, &y);
  40. while(k > && ma[k-].r <= y) k--;
  41. if(k > && x == ma[k-].t) continue;
  42. ma[k].t = x;
  43. ma[k].r = y;
  44. k++;
  45. }
  46. ma[k].t = ;
  47. ma[k].r = ;
  48. for(int i = ; i < ma[].r; i++)
  49. b[i] = a[i];
  50. sort(b, b+ma[].r);
  51. int l = ,r = ma[].r;
  52. int p = r;
  53. for(int i = ; i < k; i++){
  54. //printf("%5d%5d \n",ma[i].t,ma[i].r);
  55. while(p > ma[i+].r){
  56. p--;
  57. if(ma[i].t == ) a[p] = b[--r];
  58. else if(ma[i].t == )a[p] = b[l++];
  59. }
  60. }
  61. for(int i = ;i < n;i++){
  62. printf("%d ",a[i]);
  63. }
  64. printf("\n");
  65. return ;
  66. }

贪心+构造( Codeforces Round #344 (Div. 2))的更多相关文章

  1. 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation

    题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...

  2. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

  3. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 /* 题意:在n^n的海洋里是否有k块陆地 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 输出完k个L后,之后全部输出S:) 5 10 的例子可以是这样的: LSLS ...

  4. 贪心/数学 Codeforces Round #212 (Div. 2) A. Two Semiknights Meet

    题目传送门 /* 贪心/数学:还以为是BFS,其实x1 + 4 * k = x2, y1 + 4 * l = y2 */ #include <cstdio> #include <al ...

  5. 构造 Codeforces Round #310 (Div. 2) B. Case of Fake Numbers

    题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少 ...

  6. 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library

    题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...

  7. 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns

    题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...

  8. 构造 Codeforces Round #275 (Div. 2) C. Diverse Permutation

    题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /*** ...

  9. 构造 Codeforces Round #135 (Div. 2) B. Special Offer! Super Price 999 Bourles!

    题目传送门 /* 构造:从大到小构造,每一次都把最后不是9的变为9,p - p MOD 10^k - 1,直到小于最小值. 另外,最多len-1次循环 */ #include <cstdio&g ...

  10. 构造 Codeforces Round #107 (Div. 2) B. Phone Numbers

    题目传送门 /* 构造:结构体排个序,写的有些啰嗦,主要想用用流,少些了判断条件WA好几次:( */ #include <cstdio> #include <algorithm> ...

随机推荐

  1. ThinkPHP 3.2.3集成uploadify上传控件

    uploadify控件有一个坑爹的问题,就是文件上传时会session丢失,官方解释http://www.uploadify.com/documentation/uploadify/using-ses ...

  2. Array,ArrayList、List<T>、HashSet<T>、LinkedList<T>与Dictionary<K,V>

    Array: 数组在C#中最早出现的.在内存中是连续存储的,所以它的索引速度非常快,而且赋值与修改元素也很简单. 但是数组存在一些不足的地方.在数组的两个数据间插入数据是很麻烦的,而且在声明数组的时候 ...

  3. Aquarium Cycling

    http://www.fishyou.com/aquarium-cycling.php Aquarium Cycling Aquarium cycling actually refers to the ...

  4. Chap6: question38 - 42

    38. 数字 k 在有序数组中出现的次数 二分查找:找出第一个 k 和最后一个 k . #include <iostream> using namespace std; int getFi ...

  5. springMVC下载FTP上的文件

    springMVC下载FTP上的文件 今天没时间写.先上传 一个工具类 工具类 package com.utils; import java.io.File; import java.io.FileO ...

  6. 初识UML

    最近的学习中,遇到几次UML图,很是迷糊,确切的说,看不太懂.查阅UML相关资料,基本解决了这个问题.UML看起来还是相当深奥,这里只提一下解决问题的部分知识.(以下知识来自网络) Unified M ...

  7. linux文件上传

    租了个服务器,要把自己打的war包打上去发布,服务器是linux的(本机是mac).以前都是用wget命令,把需要上传的东西先放到github上面再在服务器上用wget命令下载.最近不知道什么原因,w ...

  8. myeclipse自动排版

    myeclipse代码排版方式有两种: 1. ctr+f 实现自动排版: 2. myeclipse->Preference->Java->Editor->Sava Action ...

  9. nohup输入密码后继续后台运行

    Linux/Unix 是真正的多用户,多任务.Linux 提供了 fg 和bg 命令,让你轻松调度正在运行的任务. 假设你发现前台运行的一个程序需要很长的时间,但是需要干其他的事情,你就可以用 Ctr ...

  10. C++中关于string类型究竟能不能用cout输出的问题

    先让我讲下故事哈 一次在MFC中用cout输出一个string类型字符串,编译时出现这样一个错误: error C2679: binary '<<' : no operator defin ...