CodeForces705C、Thor (STL)

                                                               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

Copy

3 4
1 3
1 1
1 2
2 3

output

Copy

1
2
3
2

input

Copy

4 6
1 2
1 4
1 2
3 3
1 3
1 3

output

Copy

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).

 

一、原题地址

点我传送

 

二、大致题意

有一个只能手机上有 n 个软件,这些软件会时不时产生一些未读信息。

现在手机上发生了q 件事情,事情分为三类:

  1. 软件 x 产生了一条未读信息。
  2. 软件 x 的所有信息都被读了。
  3. 前 t 条产生的信息都被读了。已读的也算在t条中。

询问在每个事件发生后输出所有未读信息的总数。

 

三、大致思路

用队列来维护每种信息当前有多少未读。再用一个vector来记录信息到来的先后顺序。

操作1就是简单的插入;

操作2就是遍历队列弹出信息;

操作3就是找出那些未被弹出的信息删除;

 

四、代码

#include<iostream>
#include<cstring>
#include<vector>
#include<deque>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;


int n,Q;
const int N=3e5+5;
deque<int>q[N];
vector<int>S;
int From[N];
int ans,tot,p;
int main()
{
    p=tot=ans=0;
    scanf("%d %d",&n,&Q);
    while(Q--)
    {
        int ty,val;
        scanf("%d %d",&ty,&val);
        if(ty==1)
        {
            ++tot;
            q[val].push_back(tot);
            S.push_back(tot);
            From[tot]=val;
            ans++;
        }
        else if(ty==2)
        {
            while(!q[val].empty())
            {
                q[val].pop_front();
                ans--;
            }
        }
        else
        {
            for(int i=p;i<S.size();i++)
            {
                if(p>=val)break;
                int to=From[S[i] ];
                ++p;
                if(!q[to].empty()&&q[to].front()<=val)
                {
                    ans--;
                    q[to].pop_front();
                }
            }
        }
        printf("%d\n",ans);
        //printf("Size:%d   p:%d\n",S.size(),p);
    }
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值