QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#583753#6414. Classical Maximization Problemhuaxiamengjin#WA 0ms30212kbC++141.7kb2024-09-22 22:01:442024-09-22 22:01:45

Judging History

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

  • [2024-09-22 22:01:45]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:30212kb
  • [2024-09-22 22:01:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,tot;
int ct[400100],ct2[400100];
vector<int>g1[400100],g2[400100];
int a[400200];
int x[400100],y[400100];
vector<int>s;
priority_queue<pair<int,int>>q;
int used[400100];
void del(int i){
	ct[x[i]]--,ct2[y[i]]--;
	for (auto j:g1[x[i]])
	q.push({-(ct[x[j]]+ct2[y[j]]),j});
	for (auto j:g2[y[i]])
	q.push({-(ct[x[j]]+ct2[y[j]]),j});
}
void solve(){
	cin>>n;tot=0;n*=2;
	for (int i=1;i<=n;i++)
	cin>>x[i]>>y[i],a[++tot]=x[i],a[++tot]=y[i],used[i]=0;
	sort(a+1,a+tot+1);
	tot=unique(a+1,a+tot+1)-a-1;
	for (int i=1;i<=tot;i++)
	g1[i].clear(),g2[i].clear(),ct[i]=ct2[i]=0;
	s.clear();
	while(q.size())q.pop();
	for (int i=1;i<=n;i++)
	x[i]=lower_bound(a+1,a+tot+1,x[i])-a,
	y[i]=lower_bound(a+1,a+tot+1,y[i])-a;
	for (int i=1;i<=n;i++)
	g1[x[i]].push_back(i),g2[y[i]].push_back(i),
	s.push_back(i),ct[x[i]]++,ct2[y[i]]++;
	for (int i=1;i<=n;i++)
	q.push({-(ct[x[i]]+ct[y[i]]),i});
	int zong=0;
	vector<pair<int,int> >ans;
	while(q.size()){
		int i=q.top().second;q.pop();
		if(used[i]==1)continue;
		bool fl=1;used[i]=1;del(i);
		while(g1[x[i]].size()&&used[g1[x[i]].back()]==1)g1[x[i]].pop_back();
		if(g1[x[i]].size()){ans.push_back({i,g1[x[i]].back()}),zong++;used[g1[x[i]].back()]=1;del(g1[x[i]].back());continue;}
		while(g2[y[i]].size()&&used[g2[y[i]].back()]==1)g2[y[i]].pop_back();
		if(g2[y[i]].size()){ans.push_back({i,g2[y[i]].back()}),zong++;used[g2[y[i]].back()]=1;del(g2[y[i]].back());continue;}
	}
	cout<<zong<<"\n";
	int pre=0;
	for (int i=1;i<=n;i++)
	if(used[i]==0){
		if(pre==0)pre=i;
		else ans.push_back({pre,i}),pre=0;
	} 
	for (auto i:ans)cout<<i.first<<" "<<i.second<<"\n";
}
int main(){
	int T;cin>>T;
	while(T--)solve();
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 30212kb

input:

3
2
0 0
0 1
1 0
1 1
2
0 0
0 1
0 2
0 3
2
0 0
1 1
2 2
3 3

output:

2
4 3
2 1
2
4 3
2 1
0

result:

wrong output format Unexpected end of file - int32 expected (test case 3)