这个代码还有什么小方法能优化时间吗?
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;
const int N=1e6+6;
typedef pair<int,int>PII;
int n,m;
bool a[200005];
bool check(){
for(int i=1;i<=n;i++){
if(a[i]!=1){
return 0;
}
}
return 1;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
memset(a,0,sizeof(a));
bool flag=0,f=0,fx=0;
cin>>n>>m;
for(int i=1;i<=m;i++){
int op,x;
cin>>op>>x;
if(flag==1)
continue;
if(op==1)a[x]=1;
else{
for(int i=1;i<=n;i++)
if(i!=x)a[i]=1;
}
if(check()){
cout<<i<<endl;
flag=1;
}
}
if(flag==0)
cout<<-1<<endl;
}
return 0;
}