QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#204053#7105. Pixel Artucup-team484AC ✓195ms17196kbC++172.1kb2023-10-07 00:35:282023-10-07 00:35:28

Judging History

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

  • [2023-10-07 00:35:28]
  • 评测
  • 测评结果:AC
  • 用时:195ms
  • 内存:17196kb
  • [2023-10-07 00:35:28]
  • 提交

answer

#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define st first
#define nd second
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
int act[N];

void solve() {
	int n, m, k; cin >> n >> m >> k;
	vector<vector<array<int, 4>>> arr(n + 1);
	vector<array<int, 4>> lin(k);
	for (int i = 0; i < k; i++) {
		int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2;
		arr[r1].push_back({c1, r2, c2, i});
		lin[i] = {r1, c1, r2, c2};
	}
	ll cnt = 0;
	vector<int> pref(n + 2), par(k + 1);
	iota(all(par), 0);
	function<int(int)> qry = [&](int x) {
		return x == par[x] ? x : par[x] = qry(par[x]);
	};
	auto join = [&](int x, int y) {
		if (qry(x) == qry(y))
			return 0;
		par[qry(x)] = qry(y);
		return 1;
	};
	int comp = 0;
	vector<vector<int>> todo(n + 1);
	for (int r1 = 1; r1 <= n; r1++) {
		sort(arr[r1].begin(), arr[r1].end());
		int lst = -1;
		for (auto [c1, r2, c2, i]: arr[r1]) {
			if (lst != -1 && lin[lst][3] + 1 == c1)
				comp -= join(lst, i);
			if (act[c1 - 1] != -1)
				comp -= join(i, act[c1 - 1]);
			if (act[c2 + 1] != -1)
				comp -= join(i, act[c2 + 1]);
			comp++;
			lst = i;
			if (c1 == c2) {
				act[c1] = i;
				todo[r2].push_back(i);
			}
			pref[r1] += c2 - c1 + 1;
			pref[r2 + 1] -= c2 - c1 + 1;
		}
		for (int i: todo[r1])
			act[lin[i][1]] = -1;
		for (int i: todo[r1 - 1]) {
			int c = lin[i][1];
			array<int, 4> tmp = {c + 1, -1, -1, -1};
			auto it = lower_bound(all(arr[r1]), tmp);
			if (it != arr[r1].begin() && c <= (*prev(it))[2])
				comp -= join(i, (*prev(it))[3]);
		}
		for (int f: {0, 1}) {
			for (auto [c1, r2, c2, i]: arr[r1 - f]) {
				for (int x: {c1, c2}) {
					array<int, 4> tmp = {x + 1, -1, -1, -1};
					auto it = lower_bound(all(arr[r1 - !f]), tmp);
					if (it != arr[r1 - !f].begin() && (*prev(it))[2] >= x)
						comp -= join(i, (*prev(it))[3]);
				}
			}
		}
		pref[r1] += pref[r1 - 1];
		cnt += pref[r1];
		cout << cnt << " " << comp << "\n";
	}
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	memset(act, -1, sizeof act);
	int t; cin >> t; while (t--) solve();
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 5 2
1 1 1 2
2 3 2 5
2 5 2
1 1 1 3
2 3 2 5
3 3 3
1 1 1 2
3 1 3 2
1 3 2 3

output:

2 1
5 2
3 1
6 1
3 1
4 1
6 2

result:

ok 7 lines

Test #2:

score: 0
Accepted
time: 195ms
memory: 17196kb

input:

2130
2 5 2
1 1 1 2
2 3 2 5
2 5 2
1 1 1 3
2 3 2 5
3 3 3
1 1 1 2
3 1 3 2
1 3 2 3
3 100 51
1 2 2 2
1 4 2 4
1 6 2 6
1 8 2 8
1 10 2 10
1 12 2 12
1 14 2 14
1 16 2 16
1 18 2 18
1 20 2 20
1 22 2 22
1 24 2 24
1 26 2 26
1 28 2 28
1 30 2 30
1 32 2 32
1 34 2 34
1 36 2 36
1 38 2 38
1 40 2 40
1 42 2 42
1 44 2 44
...

output:

2 1
5 2
3 1
6 1
3 1
4 1
6 2
50 50
100 50
200 1
50 50
150 1
200 1
2 1
4 1
6 1
8 1
10 1
12 1
14 1
16 1
18 1
20 1
22 1
24 1
26 1
28 1
30 1
32 1
34 1
36 1
38 1
40 1
42 1
44 1
46 1
48 1
50 1
52 1
54 1
56 1
58 1
60 1
62 1
64 1
66 1
68 1
70 1
72 1
74 1
76 1
78 1
80 1
82 1
84 1
86 1
88 1
90 1
92 1
94 1
96 1...

result:

ok 355756 lines

Extra Test:

score: 0
Extra Test Passed