悬关求助
  • 板块灌水区
  • 楼主Gartjock
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/10/19 10:51
  • 上次更新2024/10/19 12:54:53
查看原帖
悬关求助
1352943
Gartjock楼主2024/10/19 10:51

这个代码还有什么小方法能优化时间吗?

#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;
}
2024/10/19 10:51
加载中...