题目链接:

  http://codeforces.com/problemset/problem/704/A

  http://codeforces.com/problemset/problem/705/C

题目大意:

  雷神有N个应用,接下来Q个操作,操作分三种

  1.应用X增加一个未读消息。

  2.把应用X的未读消息全都读了。(可能重复读了已读的)

  3.把前X个1操作的未读消息全都读了。(可能重复读了已读的)

  求每一个操作后当前的未读消息总数。

题目思路:

  【模拟】

  一开始看错题目,以为操作二是把后X个消息读了就以为是队列。。WA了两发纪念一下我的英语水平。

  直接暴力模拟就行,但是一开始想错了想往后统计答案,发现肯定会T。

  其实这题只要换一个方向,往前统计被读掉的消息对上一个答案的影响。

  操作1就把应用X的最后一个消息出现位置修改为当前操作,链表接上上一个。

  操作2就从X的最后一个消息开始往前把所有的未读都标记为已读,答案减去未读数。

  操作3就把前X个消息扫一遍统计未读数,改标记。(可以扫到上次操作3的位置)

  这样就不会T了。

  1. //
  2. //by coolxxx
  3. //#include<bits/stdc++.h>
  4. #include<iostream>
  5. #include<algorithm>
  6. #include<string>
  7. #include<iomanip>
  8. #include<map>
  9. #include<memory.h>
  10. #include<time.h>
  11. #include<stdio.h>
  12. #include<stdlib.h>
  13. #include<string.h>
  14. //#include<stdbool.h>
  15. #include<math.h>
  16. #define min(a,b) ((a)<(b)?(a):(b))
  17. #define max(a,b) ((a)>(b)?(a):(b))
  18. #define abs(a) ((a)>0?(a):(-(a)))
  19. #define lowbit(a) (a&(-a))
  20. #define sqr(a) ((a)*(a))
  21. #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
  22. #define mem(a,b) memset(a,b,sizeof(a))
  23. #define eps (1e-8)
  24. #define J 10
  25. #define mod 1000000007
  26. #define MAX 0x7f7f7f7f
  27. #define PI 3.14159265358979323
  28. #define N 300004
  29. using namespace std;
  30. typedef long long LL;
  31. int cas,cass;
  32. int n,m,lll,ans;
  33. int pre[N],last[N];
  34. bool mark[N];
  35. int main()
  36. {
  37. #ifndef ONLINE_JUDGE
  38. // freopen("1.txt","r",stdin);
  39. // freopen("2.txt","w",stdout);
  40. #endif
  41. int i,j,k;
  42. int head,x,y;
  43. // for(scanf("%d",&cas);cas;cas--)
  44. // for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
  45. // while(~scanf("%s",s+1))
  46. while(~scanf("%d",&n))
  47. {
  48. //lll=0;mem(last,0);ans=0;
  49. head=;
  50. scanf("%d",&m);
  51. for(i=;i<=m;i++)
  52. {
  53. scanf("%d%d",&x,&y);
  54. if(x==)
  55. {
  56. pre[++lll]=last[y];
  57. last[y]=lll;
  58. ans++;
  59. }
  60. else if(x==)
  61. {
  62. for(j=last[y];j;j=pre[j])
  63. if(!mark[j])
  64. ans--,mark[j]=;
  65. last[y]=;
  66. }
  67. else if(x==)
  68. {
  69. for(j=head;j<=y;j++)
  70. {
  71. if(!mark[j])
  72. mark[j]=,ans--;
  73. }
  74. head=max(head,j);
  75. }
  76. printf("%d\n",ans);
  77. }
  78. }
  79. return ;
  80. }
  81. /*
  82. //
  83.  
  84. //
  85. */

【模拟】Codeforces 704A & 705C Thor的更多相关文章

  1. CodeForces 705C Thor (模拟+STL)

    题意:给定三个操作,1,是x应用产生一个通知,2,是把所有x的通知读完,3,是把前x个通知读完,问你每次操作后未读的通知. 析:这个题数据有点大,但可以用STL中的队列和set来模拟这个过程用q来标记 ...

  2. Codeforces 704A Thor 队列模拟

    题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...

  3. codeforces 704A (队列模拟) Thor

    题目:这里 题意:n个app,q个操作,当操作数type为1的时候表示y这个app推送了你一条消息,当操作数type为2的时候表示将y这个app已推送的所有消息都读完,当操作数为3的时候 表示将已经推 ...

  4. CodeForces 705C Thor

    开30W个vector将数字归类,每一类数字开一个指针P,记录已经阅读到哪一个了,还可以开一个优先队列维护这些指针P. #pragma comment(linker, "/STACK:102 ...

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

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

  6. 模拟 Codeforces Round #203 (Div. 2) C. Bombs

    题目地址:http://codeforces.com/problemset/problem/350/C /* 题意:机器人上下左右走路,把其他的机器人都干掉要几步,好吧我其实没读懂题目, 看着样例猜出 ...

  7. 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram

    题目地址:http://codeforces.com/contest/435/problem/C /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...

  8. 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie

    题目传送门 /* 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 题目倒是很长:) */ #include <cstdio> #include <algorithm> ...

  9. queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards

    题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...

随机推荐

  1. VS2010在WIN7 64位系统下架设网站及路由器配置

    步骤一:安装IIS 打开[控制面板]-[程序和功能],在左侧进入[打开或关闭windows功能],按照下图选择Internet信息项目下的子选项并安装: 步骤二:配置应用程序池 打开[控制面板]-[管 ...

  2. dnw for linux: Ubuntu下可用,无需编译驱动,mini2440可用

    1.安装所需库文件 sudo apt-get install libusb-dev 2.源代码如下 /* dnw2 linux main file. This depends on libusb. * ...

  3. 【转】《我的WCF之旅》博文系列汇总

    转自:http://www.cnblogs.com/artech/archive/2007/09/15/893838.html WCF是构建和运行互联系统的一系列技术的总称,它是建立在Web Serv ...

  4. C++函数二义性问题,我怎么感觉编译器有偷懒嫌疑!!!

    瞎扯一段,讲得不一定对.纯属学习! struct BB{ void a(){ cout << "bb's a()\n"; }}; struct B1 : public ...

  5. C++ STL的基本基本原理

    STL都是在内存的堆区分配的,但是其析构也是STL帮我们做好的,不用手动去delete. 1.vector 逻辑地址连续的一片内存空间,当空间不足,重新申请新的地址空间,将原有的数据复制过去,而新的地 ...

  6. iframe中在父窗口打开子页面

    我们在做页面框架的时候,通常会采用一个iframe来显示子页面,但有这么种情况,就是session失效时,登录页面就会显示在iframe中,这不符合常理,一般应该显示在顶部才对. 下面的js代码可以解 ...

  7. js定位navigator.geolocation

    一.简介 html5为window.navigator提供了geolocation属性,用于获取基于浏览器的当前用户地理位置. window.navigator.geolocation提供了3个方法分 ...

  8. Connect mysql on Linux from Windows

    ON LINUX: 1 sudo apt-get install mysql-server 2 sudo apt-get install python-dev 3 sudo apt-get insta ...

  9. Unable to find the ncurses libraries or the required header files解决

    问题: 解决方法: sudo apt-get install ncurses-dev 参考:Unable to find the ncurses libraries or the required h ...

  10. objective-c 错题

    //1, NSString *name = [[NSString alloc]initWithString:@"张三"]; NSLog(@"%d",[name ...