You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
#include <cstdio>
|
|
#include <queue>
|
|
using namespace std;
|
|
int n, q, op, x, unread;
|
|
int rem[300001], msg[300001], pre, msgi;
|
|
queue<int> app[300001];
|
|
bool vis[300001];
|
|
int main()
|
|
{
|
|
scanf("%d%d", &n, &q);
|
|
for (int i = 1; i <= q; i++)
|
|
{
|
|
scanf("%d%d", &op, &x);
|
|
if (op == 1)
|
|
{
|
|
unread++;
|
|
rem[x]++;
|
|
msgi++;
|
|
msg[msgi] = x;
|
|
app[x].push(msgi);
|
|
}
|
|
else if (op == 2)
|
|
{
|
|
unread -= rem[x];
|
|
rem[x] = 0;
|
|
while (!app[x].empty())
|
|
{
|
|
vis[app[x].front()] = true;
|
|
app[x].pop();
|
|
}
|
|
}
|
|
else if (op == 3)
|
|
{
|
|
if (x > pre)
|
|
{
|
|
for (int j = pre + 1; j <= x; j++)
|
|
if (vis[j])
|
|
continue;
|
|
else
|
|
{
|
|
unread--;
|
|
rem[msg[j]]--;
|
|
app[msg[j]].pop();
|
|
}
|
|
pre = x;
|
|
}
|
|
}
|
|
printf("%d\n", unread);
|
|
}
|
|
return 0;
|
|
} |