题意:有三个操作
1 x y,在第x秒插入一个y
2 x y,在第x秒移走一个y
3 x y, 问第x秒有多少个y
思路:听说是可持久化Treap...不过好像无脑树状数组也行
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+1;
map<int,int>c[maxn];
map<int,int>vis;
int tot = 0;
int lowbit(int x)
{
return x&(-x);
}
void update(int x,int t,int y)
{
for (int i = t;i<1e9+5;i+=lowbit(i))
c[x][i]+=y;
}
int query(int x,int t)
{
int ans = 0;
for (int i = t;i;i-=lowbit(i))
ans+=c[x][i];
return ans;
}
int main()
{
int n;
scanf("%d",&n);
for (int i = 1;i<=n;i++)
{
int op,x,y;
scanf("%d%d%d",&op,&x,&y);
if (op==1 && !vis[y])
vis[y]=++tot;
if (op==1)
update(vis[y],x,1);
if (op==2)
update(vis[y],x,-1);
if (op==3)
printf("%d\n",query(vis[y],x));
}
}