思路是都有红纸的情况来自于以下:
Ⅰ:1操作x存在n个
Ⅱ:2操作x存在2个
Ⅲ:存在x执行过1 2操作
60pts Wa Subtask #1 Subtask #5
int T;
int n,m,o,x,ans,t1,t2;
int all[INF],nod[INF];
int main() {
cin>>T;
while (T--) {
cin>>n>>m;
for (int i=1; i<=n; i++) nod[i]=all[i]=0;
t1=t2=ans=0;
for (int i=1; i<=m; i++){
cin>>o>>x;
if (o-1) {
if ((nod[x] or t2 and t2!=x) and !ans) ans=i;
t2=x,all[x]=1;
}
else {
if (!nod[x]) nod[x]=1,t1++;
if (t1==n or all[x] and !ans) ans=i;
}
}
ans ? cout<<ans<<'\n' : cout<<"-1\n";
}
return 0;
}