QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#472195#6414. Classical Maximization ProblemUESTC_DebugSimulator#WA 86ms7848kbC++173.1kb2024-07-11 14:59:452024-07-11 14:59:46

Judging History

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

  • [2024-07-11 14:59:46]
  • 评测
  • 测评结果:WA
  • 用时:86ms
  • 内存:7848kb
  • [2024-07-11 14:59:45]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lowbit(i) (i&-i)
#define rand() (myrand())
using namespace std;
mt19937 myrand(time(0));
const int maxn = 5e5 + 5;
int n, _, cx[maxn], cy[maxn], vis[maxn], c[maxn], len;
struct node{
	int x, y;
}a[maxn];
void solve() {
	cin >> n;
	n <<= 1;
	vector<int>px, py;
	vector<pair<int, int> >ans;
	priority_queue<pair<int, int> >qx, qy;
	map<pair<int, int>, int>id;
	int num = 0;
	for (int i = 1 ; i <= n ; ++i) {
		int x, y;
		cin >> x >> y;
		a[i].x = x, a[i].y = y;
		c[(i<<1) - 1] = x;
		c[i<<1] = y;
	}
	sort(c + 1, c + 1 + (n<<1));
	len = unique(c + 1, c + 1 + (n<<1)) - c - 1;
	for (int i = 1 ; i <= n ; ++i) {
		a[i].x = lower_bound(c + 1, c + 1 + len, a[i].x) - c;
		a[i].y = lower_bound(c + 1, c + 1 + len, a[i].y) - c;
		int x = a[i].x, y = a[i].y;
		id[{x, y}] = i;
		vis[i] = 0;
		if (!cx[x]) px.push_back(x);
		if (!cy[y]) py.push_back(y);
		cx[x]++;
		cy[y]++;
	}
	for (auto x : px) qx.push({cx[x], x});
	for (auto y : py) qy.push({cy[y], y});
	while(1) {
		pair<int, int>t1, t2, t, p1, p2;
		int maxh = -1, f = 0;
		if (qx.size() >= 2 && qy.size() >= 1) {
			t1 = qx.top();qx.pop();
			t2 = qx.top();qx.pop();
			t = qy.top();qy.pop();
			if (t.first - 2 >= 0) {
				int last = maxh;
				maxh = max(maxh, min({t1.first - 1, t2.first - 1, t.first - 2}));
				if (maxh > last) {
					p1.second = p2.second = t.second;
					p1.first = t1.second;
					p2.first = t2.second;
					f = 1;
				}
			}
			qx.push(t1);	
			qx.push(t2);
			qy.push(t);
		}
		if (qx.size() >= 1 && qy.size() >= 2) {
			t1 = qy.top();qy.pop();
			t2 = qy.top();qy.pop();
			t = qx.top();qx.pop();
			if (t.first - 2 >= 0) {
				int last = maxh;
				maxh = max(maxh, min({t1.first - 1, t2.first - 1, t.first - 2}));
				if (maxh > last) {
					p1.first = p2.first = t.second;
					p1.second = t1.second;
					p2.second = t2.second;
					f = 2;
				}	
			}	
			qy.push(t1);	
			qy.push(t2);
			qx.push(t);	
		}
		if (!f) break;
		num++;
		if (f == 1) {
			t1 = qx.top();qx.pop();
			t2 = qx.top();qx.pop();
			t = qy.top();qy.pop();
			t1.first--;
			t2.first--;
			t.first -= 2;
			if (t1.first > 0) qx.push(t1);	
			if (t2.first > 0) qx.push(t2);
			if (t.first > 0) qy.push(t);		
		}
		else {
			t1 = qy.top();qy.pop();
			t2 = qy.top();qy.pop();
			t = qx.top();qx.pop();		
			t1.first--;
			t2.first--;
			t.first -= 2;
			if (t1.first > 0) qy.push(t1);	
			if (t2.first > 0) qy.push(t2);
			if (t.first > 0) qx.push(t);	
		}
		ans.push_back({id[p1], id[p2]});
		vis[id[p1]] = vis[id[p2]] = 1;
	}
	vector<int>res;
	for (int i = 1 ; i <= n ; ++i) {
		if (!vis[i]) res.push_back(i);
	}
	for (int i = 0 ; i < res.size() ; i += 2) {
		if (!res[i] || !res[i + 1]) continue;
		ans.push_back({res[i], res[i + 1]});
	}
	cout << num << '\n';
	for (auto [x, y] : ans) cout << x << ' ' << y << '\n';
	for (int i = 1 ; i <= n ; ++i) cx[a[i].x] = cy[a[i].y] = 0;
}
signed main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> _;
	while(_--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

result:

ok ok (3 test cases)

Test #2:

score: 0
Accepted
time: 81ms
memory: 7848kb

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

result:

ok ok (10000 test cases)

Test #3:

score: -100
Wrong Answer
time: 86ms
memory: 7840kb

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

result:

wrong answer Integer parameter [name=a[1]] equals to 0, violates the range [1, 24] (test case 2517)