zoukankan      html  css  js  c++  java
  • Codeforces Round #366 (Div. 2)_C. Thor

    C. Thor
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't).

    q events are about to happen (in chronological order). They are of three types:

    1. Application x generates a notification (this new notification is unread).
    2. Thor reads all notifications generated so far by application x (he may re-read some notifications).
    3. Thor reads the first t notifications generated by phone applications (notifications generated in first t events of the first type). It's guaranteed that there were at least t events of the first type before this event. Please note that he doesn't read first t unread notifications, he just reads the very first t notifications generated on his phone and he may re-read some of them in this operation.

    Please help Thor and tell him the number of unread notifications after each event. You may assume that initially there are no notifications in the phone.

    Input

    The first line of input contains two integers n and q (1 ≤ n, q ≤ 300 000) — the number of applications and the number of events to happen.

    The next q lines contain the events. The i-th of these lines starts with an integer typei — type of the i-th event. If typei = 1 or typei = 2then it is followed by an integer xi. Otherwise it is followed by an integer ti (1 ≤ typei ≤ 3, 1 ≤ xi ≤ n, 1 ≤ ti ≤ q).

    Output

    Print the number of unread notifications after each event.

    Examples
    input
    3 4
    1 3
    1 1
    1 2
    2 3
    output
    1
    2
    3
    2
    input
    4 6
    1 2
    1 4
    1 2
    3 3
    1 3
    1 3
    output
    1
    2
    3
    0
    1
    2
    Note

    In the first sample:

    1. Application 3 generates a notification (there is 1 unread notification).
    2. Application 1 generates a notification (there are 2 unread notifications).
    3. Application 2 generates a notification (there are 3 unread notifications).
    4. Thor reads the notification generated by application 3, there are 2 unread notifications left.

    In the second sample test:

    1. Application 2 generates a notification (there is 1 unread notification).
    2. Application 4 generates a notification (there are 2 unread notifications).
    3. Application 2 generates a notification (there are 3 unread notifications).
    4. Thor reads first three notifications and since there are only three of them so far, there will be no unread notification left.
    5. Application 3 generates a notification (there is 1 unread notification).
    6. Application 3 generates a notification (there are 2 unread notifications).

    题意:

    让你模拟一下这个产生信息和看信息的过程

    题解:

    首先我们看到一共只有30W个操作,意思就是操作信息就最多只有30W次,所以我们开一个vector 来存每个APP的信息编号,set来存未读信息的编号,遇到2操作就在set里删除,因为最多只有30W的信息,所以怎么也不会超时,遇到3操作就直接在set里把小于t的编号信息全部删掉

     1 #include<bits/stdc++.h>
     2 #define pb push_back
     3 #define F(i,a,b) for(int i=a;i<=b;++i)
     4 using namespace std;
     5 typedef pair<int,int>P;
     6 
     7 const int N=3e5+7;
     8 int n,q,x,y,ed,v[N];
     9 vector<int>Q[N];
    10 set<int>cnt;
    11 set<int>::iterator it;
    12 
    13 int main(){
    14     scanf("%d%d",&n,&q);
    15     F(i,1,q)
    16     {
    17         scanf("%d%d",&x,&y);
    18         if(x==1)Q[y].pb(++ed),cnt.insert(ed);
    19         else if(x==2){
    20             int sz=Q[y].size();
    21             F(j,0,sz-1)cnt.erase(Q[y][j]);
    22             Q[y].clear();
    23         }
    24         else{
    25             int ved=0;
    26             for(it=cnt.begin();it!=cnt.end();it++)
    27             {
    28                 if(*it>y)break;
    29                 v[++ved]=*it;
    30             }
    31             F(j,1,ved)cnt.erase(v[j]);
    32         }
    33         printf("%d
    ",cnt.size());
    34     }
    35     return 0;
    36 }
    View Code
  • 相关阅读:
    debug: if (va=1) 和 if (va==1)的区别
    必定管用!关于如何在电脑上恢复itunes中的音乐库(Mac Windows统统适用)
    关于Matlab中自动生成的asv文件
    LaTeX表格字体大小控制
    ANSYS中应力强度因子与J积分的计算
    Notepad++取消输入单词时出现提示
    notepad++的apdl高亮xml文件
    Power Graphics
    19个必须知道的Visual Studio快捷键
    APDL命令流:将ansys分析结果输出为tecplot格式
  • 原文地址:https://www.cnblogs.com/bin-gege/p/5749189.html
Copyright © 2011-2022 走看看