ZZUILIOJ 2836: 黑曜石http://acm.zzuli.edu.cn/problem.php?id=2836
#include<bits/stdc++.h>
using namespace std;
long long c[200010],h[200010];
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int t;cin>>t;
while(t--)
{
int n,cnt=0;
cin>>n;
memset(c,0,sizeof c);
memset(h,0,sizeof h);
for(int i=1;i<=n;i++)
{
int x;
scanf("%d %lld",&x,&h[i]);
if(x==3) cnt++;
c[h[i]]=x;
}
sort(h+1,h+1+n,cmp);
for(int i=1;i<n;i++)
{
if((c[h[i]]==1&&c[h[i+1]]==2)||(c[h[i]]==2&&c[h[i+1]]==1))
cnt++;
}
cout<<cnt<<endl;
}
return 0;
}