QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#560756#6414. Classical Maximization ProblemlcqlilyRE 151ms14104kbC++142.0kb2024-09-12 17:43:242024-09-12 17:43:25

Judging History

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

  • [2024-09-12 17:43:25]
  • 评测
  • 测评结果:RE
  • 用时:151ms
  • 内存:14104kb
  • [2024-09-12 17:43:24]
  • 提交

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]||(vis[v]&&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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 13928kb

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

result:

ok ok (3 test cases)

Test #2:

score: 0
Accepted
time: 151ms
memory: 14104kb

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: 0
Accepted
time: 134ms
memory: 13816kb

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:

ok ok (10000 test cases)

Test #4:

score: 0
Accepted
time: 141ms
memory: 13872kb

input:

10000
5
999984799 999981445
999958394 999984217
999994978 999981258
999955539 999938710
999936554 999963561
999907222 999907508
999938166 999941959
999910567 999986887
999901446 999961092
999994730 999963038
5
999916115 999962400
999948250 999940355
999954204 999920844
999928148 999990369
999978118 ...

output:

0
9 6
8 5
7 4
2 1
10 3
0
10 1
8 4
2 3
9 5
6 7
0
2 5
10 4
17 3
16 11
18 8
12 22
7 13
1 9
21 19
14 6
20 15
0
5 3
2 4
6 7
8 1
0
26 20
27 14
21 4
23 11
22 9
24 3
12 31
32 10
6 30
29 18
7 15
2 19
16 25
28 1
17 13
8 5
0
7 8
2 6
3 4
9 1
10 5
0
2 11
14 1
3 15
9 13
12 5
8 10
6 7
16 4
0
47 21
67 65
66 36
60 2...

result:

ok ok (10000 test cases)

Test #5:

score: 0
Accepted
time: 145ms
memory: 11768kb

input:

10000
1
999990146 999993828
999995909 999996353
56
999999851 999991179
999997250 999997987
999990590 999997316
999997350 999996856
999997034 999996236
999999396 999996897
999991180 999993309
999991265 999995185
999993952 999994054
999990210 999994471
999993201 999995893
999997170 999998971
999998201...

output:

0
1 2
1
76 111
87 61
10 52
54 33
109 3
108 41
22 25
48 7
21 85
8 14
90 92
40 60
53 29
93 102
63 103
81 34
66 82
55 50
100 24
83 78
31 11
43 42
88 51
30 9
79 15
28 70
59 56
27 23
107 68
18 77
58 84
17 57
91 64
49 69
112 96
86 36
94 72
35 38
105 37
65 5
80 75
12 2
4 106
104 62
20 95
47 101
26 13
45 32...

result:

ok ok (10000 test cases)

Test #6:

score: 0
Accepted
time: 137ms
memory: 13864kb

input:

10000
5
999999432 999999813
999999271 999999233
999999043 999999606
999999523 999999406
999999564 999999274
999999641 999999102
999999903 999999858
999999058 999999098
999999974 999999119
999999643 999999620
5
999999370 999999738
999999181 999999907
999999163 999999783
999999393 999999086
999999661 ...

output:

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

result:

ok ok (10000 test cases)

Test #7:

score: -100
Runtime Error

input:

10000
14
-369804569 -904204119
526374829 -824374353
-127549933 -904204119
-68608787 929413707
-68608787 -363454459
526374829 929413707
693313139 -824374353
-127549933 -726843762
526374829 -904204119
526374829 -363454459
526374829 -409731440
693313139 -726843762
693313139 929413707
-68608787 -8243743...

output:

14
15 6
10 28
24 13
12 27
9 23
5 4
14 7
2 22
19 18
17 8
3 26
16 11
25 21
20 1

result: