QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#560824#6414. Classical Maximization ProblemlcqlilyCompile Error//C++141.9kb2024-09-12 18:10:152024-09-12 18:10:16

Judging History

你现在查看的是最新测评结果

  • [2024-09-12 18:10:16]
  • 评测
  • [2024-09-12 18:10:15]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
struct A{int y,i,nxt;}e[800010];
int n,m1,m2,ans;
int a[200010][2];
int lk[400010],ltp;
int b[200010],c[200010];
int vis[400010],t[400010];
vector<int> lft,ans1,ans2;
int dfs(int u){
	vector<int> qwq;vis[u]=1;
	for(int i=lk[u];i;i=e[i].nxt){
		int v=e[i].y;
		if(t[e[i].i]) continue;t[e[i].i]=1;
		if(vis[v]){qwq.push_back(e[i].i);continue;}
		d[v]=d[u]+1;int kk=dfs(v);
		if(!kk) qwq.push_back(e[i].i);
		else{
			ans++;
			ans1.push_back(kk);
			ans2.push_back(e[i].i);
		}
	}
	int sz=qwq.size();
	for(int i=0;i+1<sz;i+=2){
		ans++;
		ans1.push_back(qwq[i]);
		ans2.push_back(qwq[i+1]);
	}
	if(sz%2==0) return 0;
	return qwq[sz-1];
}
int find1(int x){
	int l=1,r=m1;
	while(l<r){
		int mid=(l+r)>>1;
		if(b[mid]>=x) r=mid;
		else l=mid+1;
	}return l;
}
int find2(int x){
	int l=1,r=m2;
	while(l<r){
		int mid=(l+r)>>1;
		if(c[mid]>=x) r=mid;
		else l=mid+1;
	}return l;
}
void add(int u,int v,int i){
	++ltp,e[ltp].y=v,e[ltp].i=i,e[ltp].nxt=lk[u],lk[u]=ltp;
	++ltp,e[ltp].y=u,e[ltp].i=i,e[ltp].nxt=lk[v],lk[v]=ltp;
}
int main(){
	//ios::sync_with_stdio(0);cin.tie(0);
	int T;cin>>T;
	while(T--){
		cin>>n;n*=2;ltp=ans=0;
		lft.clear();ans1.clear();ans2.clear();
		for(int i=1;i<=n;i++) cin>>a[i][0]>>a[i][1];
		for(int i=1;i<=n;i++) b[i]=a[i][0],c[i]=a[i][1];
		sort(b+1,b+n+1);sort(c+1,c+n+1);
		m1=unique(b+1,b+n+1)-b-1;
		m2=unique(c+1,c+n+1)-c-1;
		for(int i=1;i<=n*2;i++) lk[i]=vis[i]=t[i]=0;
		for(int i=1;i<=n;i++){
			add(find1(a[i][0]),find2(a[i][1])+m1,i);
		}
		for(int i=1;i<=m1+m2;i++){
			if(!vis[i]){
				int kk=dfs(i);
				if(kk) lft.push_back(kk);
			}
		}
		for(int i=0;i<lft.size();i+=2){
			ans1.push_back(lft[i]);
			ans2.push_back(lft[i+1]);
		}
		cout<<ans<<"\n";
		for(int i=0;i<ans1.size();i++)
			cout<<ans1[i]<<" "<<ans2[i]<<"\n";
		if(ans1.size()!=n/2) cout<<(100/0)<<"\n";
	}
	return 0;
}

Details

answer.code: In function ‘int dfs(int)’:
answer.code:17:17: error: ‘d’ was not declared in this scope
   17 |                 d[v]=d[u]+1;int kk=dfs(v);
      |                 ^
answer.code: In function ‘int main()’:
answer.code:82:48: warning: division by zero [-Wdiv-by-zero]
   82 |                 if(ans1.size()!=n/2) cout<<(100/0)<<"\n";
      |                                             ~~~^~