主题链接:点击打开链接

特定n一个操作,m长序列a

下列n的数量

if(co>=0)向字符串加入一个co (開始是空字符串)

else 删除字符串中有a的下标的字符

直接在序列上搞。简单模拟

  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<string.h>
  4. #include<set>
  5. #include<vector>
  6. #include<map>
  7. #include<math.h>
  8. #include<string>
  9. #include<stdlib.h>
  10. #include<algorithm>
  11. using namespace std;
  12. #define N 1000005
  13. bool use[N], b[N];
  14. int top;
  15. int n, m;
  16. int a[N];
  17. int c[N], maxn;
  18. inline int lowbit(int x){return x&(-x);}
  19. void change(int pos, int val){
  20. while(pos<=maxn){
  21. c[pos]+=val;
  22. pos+=lowbit(pos);
  23. }
  24. }
  25. int sum(int pos){
  26. int ans = 0;
  27. while(pos)ans+=c[pos], pos-=lowbit(pos);
  28. return ans;
  29. }
  30. set<int>myset;
  31. set<int>::iterator p;
  32. void Erase(int pos, int r){
  33. int l = 1;
  34. while(l<=r) {
  35. int mid = (l+r)>>1;
  36. int tmp = sum(mid);
  37. if(tmp==pos) {
  38. p = myset.upper_bound(mid);
  39. p--;
  40. mid = *p;
  41. change(mid, -1);
  42. use[mid] = 1;
  43. myset.erase(p);
  44. return ;
  45. }
  46. if(tmp>pos) r = mid-1;
  47. else l = mid+1;
  48. }
  49. }
  50. void init(){myset.clear(); memset(c, 0, sizeof c); maxn = n+10; top = 0;}
  51. int main(){
  52. int i,j,co;
  53. while(~scanf("%d %d",&n,&m)){
  54. init();
  55. for(i=0;i<m;i++)scanf("%d",&a[i]);
  56. int len = 0;
  57. for(i = 1; i <= n; i++) {
  58. scanf("%d",&co);
  59. if(co>=0)
  60. use[i] = 0, b[i] = co, change(i,1), len++, myset.insert(i);
  61. else {
  62. use[i] = 1;
  63. int j = lower_bound(a, a+m, len) - a;
  64. if(j==0 && len<a[0])continue;
  65. if(len!=a[j])j--;
  66. while(j>=0) {
  67. Erase(a[j], i);
  68. j--;
  69. len--;
  70. }
  71. }
  72. }
  73.  
  74. if(!len)puts("Poor stack!");
  75. else {
  76. for(i = 1; i <= n; i++) if(!use[i])
  77. printf("%d",b[i]);
  78. puts("");
  79. }
  80. }
  81. return 0;
  82. }

Codeforces 374D Inna and Sequence 二分法+树状数组的更多相关文章

  1. codeforces 374D. Inna and Sequence 线段树

    题目链接 给m个数, n个操作, 一个数列, 初始为空.一共有3种操作, 在数列末尾加0, 加1, 或删除位置为a[i]的数, a[i]为初始给的m个数, 如果a[i]大于数列长度, 那么什么也不发生 ...

  2. Codeforces 374D - Inna and Sequence

    374D - Inna and Sequence 思路: 树状数组+二分 因为被删的点最多N=1e6个,所以复杂度N*logN*logN 前段时间做过一道一样的题,这类题基本套路二分找没删除前的位置 ...

  3. Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes 树状数组s

    C. Inna and Candy Boxes   Inna loves sweets very much. She has n closed present boxes lines up in a ...

  4. Codeforces Gym 100114 H. Milestones 离线树状数组

    H. Milestones Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descripti ...

  5. Codeforces - 828E DNA Evolution —— 很多棵树状数组

    题目链接:http://codeforces.com/contest/828/problem/E E. DNA Evolution time limit per test 2 seconds memo ...

  6. Codeforces Round #365 (Div. 2) D 树状数组+离线处理

    D. Mishka and Interesting sum time limit per test 3.5 seconds memory limit per test 256 megabytes in ...

  7. Educational Codeforces Round 10 D. Nested Segments (树状数组)

    题目链接:http://codeforces.com/problemset/problem/652/D 给你n个不同的区间,L或者R不会出现相同的数字,问你每一个区间包含多少个区间. 我是先把每个区间 ...

  8. CodeForces - 314C Sereja and Subsequences (树状数组+dp)

    Sereja has a sequence that consists of n positive integers, a1, a2, ..., an. First Sereja took a pie ...

  9. Codeforces Gym 100269F Flight Boarding Optimization 树状数组维护dp

    Flight Boarding Optimization 题目连接: http://codeforces.com/gym/100269/attachments Description Peter is ...

随机推荐

  1. 第1周 SQL Server 如何执行一个查询

    原文:第1周 SQL Server 如何执行一个查询 大家好,欢迎来到第1周的SQL Server性能调优培训.在我们进入SQL Server性能调优里枯燥难懂的细节内容之前,我想通过讲解SQL Se ...

  2. WPF 3D: MeshGeometry3D纹理坐标的正确定义

    原文 WPF 3D: MeshGeometry3D纹理坐标的正确定义 为了使基于2D的纹理显示在3D对象中,我们必须定义3D Mesh对象的纹理贴图坐标.在WPF中,此项功能则通过MeshGeomet ...

  3. Code-Based Configuration (EF6 onwards)

    https://msdn.microsoft.com/en-us/data/jj680699#Using

  4. Java引进和应用的包装类

    Java介绍包装类: 于Java它设计主张的想法,也就是说,一切都是对象.但是,我们知道,,Java数据类型分为基本数据类型和引用数据类型,但基本的数据怎么能成对象?为了解决这个问题,对需要8一个类的 ...

  5. twrp gui/actions.cpp 中的功能实现 tw_action ,tw_action_param ,第二章

    继续分析 twrp ui.xml中的相关内容,以<page name="reboot">为讲解内容 <object type="button" ...

  6. define a class for a linked list and write a method to delete the nth node.

    1.问题 define a class for a linked list and write a method to delete the nth node. 2.算法 template <t ...

  7. JTable demo

    简单讲就是在没有使用layout manager的时候用setSize,在使用了layout manager 的时候用setPreferredSize 并且setPreferredSize通常和set ...

  8. CentOS配置smaba与Windows共享文件

    操作环境:CentOS 6.5 64bit Linux与Linux间通过什么共享文件呢--NFS,Windows与Windows之间呢--共享文件功能就OK了,那Windows与Linux之间呢? 这 ...

  9. Asp.NET MVC3 使用 SignalR 实现推(持续)

    一,Persistent Connection 演示示例教程 1.实现server端代码 1),编写server PersistentConnection 代码 项目中 SignalR 文件夹下创建 ...

  10. OutputCache说明

    当用户访问该页面,整个页面会server存储在内存中,因此,该页面缓存.当用户再次访问该页面,页面不会再次运行数据操作,页面首先检查server中是否存在缓存.假设缓存存在,则直接从缓存中获取页面信息 ...