QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#560744#6414. Classical Maximization ProblemlcqlilyWA 138ms13820kbC++142.1kb2024-09-12 17:38:512024-09-12 17:38:56

Judging History

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

  • [2024-09-12 17:38:56]
  • 评测
  • 测评结果:WA
  • 用时:138ms
  • 内存:13820kb
  • [2024-09-12 17:38:51]
  • 提交

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];
int d[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]||d[v]<d[u]) 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=0;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<=m1+m2;i++) lk[i]=vis[i]=t[i]=d[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;
}/*
15
14 2
39 17
5 4
29 13
30 7
16 6
40 36
9 34
3 1
18 11
31 10
8 33
35 15
12 32
38 37*/

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 13820kb

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
2 1
4 3
2
4 3
2 1
0
1 2
3 4

result:

ok ok (3 test cases)

Test #2:

score: 0
Accepted
time: 138ms
memory: 11792kb

input:

10000
2
-107276936 -310501829
419434212 585811870
-65754386 -491212232
381152038 897148193
3
-474045168 493506332
299114415 540203303
165808153 983551
-506936261 -694189769
766718170 -725540031
975267148 -593051087
1
-818952276 -762387923
584023914 -612401389
6
-77701228 -266484128
659434465 6322062...

output:

0
1 3
4 2
0
4 1
3 2
5 6
0
1 2
0
9 7
11 1
4 6
8 12
2 10
5 3
0
1 3
5 6
12 13
7 8
11 4
2 10
14 9
0
2 1
0
54 1
45 16
35 46
26 33
65 44
5 29
22 20
39 10
9 61
32 21
47 31
43 50
37 12
6 2
62 13
3 11
19 58
51 27
18 24
17 52
23 34
28 49
14 41
25 48
40 63
38 42
59 55
30 60
57 8
56 4
15 66
64 7
53 36
0
4 2
1 3...

result:

ok ok (10000 test cases)

Test #3:

score: -100
Wrong Answer
time: 132ms
memory: 11816kb

input:

10000
1
999855386 999580905
999342928 999615227
21
999601032 999015398
999155628 999176944
999309856 999524434
999121011 999509537
999323572 999685730
999272272 999769606
999450559 999390758
999632027 999178534
999024993 999463838
999784856 999374197
999980525 999366771
999241260 999516879
999599548...

output:

0
2 1
0
30 26
9 19
27 4
41 2
40 12
33 6
3 5
35 7
16 23
42 13
1 17
8 36
28 14
38 29
32 18
20 25
10 15
21 39
37 34
24 31
22 11
0
9 22
3 16
28 30
27 5
2 24
11 6
18 26
4 8
12 7
23 14
13 19
10 29
17 15
1 20
25 21
0
25 21
15 19
17 2
28 11
24 4
20 10
3 27
26 23
5 22
1 13
8 7
6 16
12 14
18 9
0
13 8
20 24
3 ...

result:

wrong answer worse than author's solution: expected 1, found 0 (test case 3954)