QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#502394#2645. Collapsemakrav0 5953ms30376kbC++204.2kb2024-08-03 05:00:102024-08-03 05:00:10

Judging History

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

  • [2024-08-03 05:00:10]
  • 评测
  • 测评结果:0
  • 用时:5953ms
  • 内存:30376kb
  • [2024-08-03 05:00:10]
  • 提交

answer

#include "collapse.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second

const int K = 501;

struct dsu {
	int n, cmp;
	vector<int> par, siz;
	dsu() = default;
	dsu(int n_) {
		cmp = 0;
		n = n_;
		par.assign(n, 0);
		iota(all(par), 0);
		siz.assign(n, 1);
	}

	int get(int v) {
		return (par[v] == v ? v : par[v] = get(par[v]));
	}

	void merge(int u, int v) {
		u = get(u);
		v = get(v);
		if (u == v) return;
		cmp--;
		if (siz[v] > siz[u]) swap(u, v);
		par[v] = u;
		siz[u] += siz[v];
	}
};		

std::vector<int> simulateCollapse(
	int N,
	std::vector<int> T,
	std::vector<int> X,
	std::vector<int> Y,
	std::vector<int> W,
	std::vector<int> P
) {
	int n = N;
	int c = sz(X);
	vector<vector<pair<int, int>>> qrs(c);
	for (int i = 0; i < sz(W); i++) {
		qrs[W[i]].pb({P[i], i});
	}
	vector<int> ans(sz(W));
	vector<vector<int>> gr(n);
	vector<int> used1(n), used_dfs(n);
	int step = 0;
	for(int i = 0; i < c; i++){
		if(X[i]>Y[i])swap(X[i],Y[i]);
	}
	for (int i = 0; i < c; i += K) {
		unordered_set<ll> ch_edg;
		unordered_set<ll> LOL;
		for (int j = i; j < min(c, i + K); j++) {
			if (T[j] == 1 && ch_edg.find(X[j] * 1ll * N + Y[j]) == ch_edg.end()) {
				LOL.insert(X[j] * 1ll * n + Y[j]);
			}
			ch_edg.insert(X[j] * 1ll * N + Y[j]);
		}
		vector<vector<int>> by_rig(n), by_left(n);
		for (int j = 0; j < i; j++) {
			if (ch_edg.find(X[j] * 1ll * n + Y[j]) == ch_edg.end()) {
				by_rig[max(X[j], Y[j])].pb(min(X[j], Y[j]));
				by_left[min(X[j], Y[j])].pb(max(X[j], Y[j]));
			}
		}
		vector<vector<pair<int, int>>> qnums(n - 1);
		for (int j = i; j < min(c, i + K); j++) {
			for (auto &[el, num] : qrs[j]) {
				qnums[el].pb({j, num});
			}
		}
		dsu d(n);
		for (int I = 0; I < n - 1; I++) {
			d.cmp++;
			for (auto &u : by_rig[I]) d.merge(u, I);
			for (auto &[time, numb] : qnums[I]) {
				step++;
				unordered_set<ll> add_edges = LOL;
				for (int j = i; j <= time; j++) {
					if (T[j] == 0) {
						add_edges.insert(X[j] * 1ll * n + Y[j]);
					} else {
						add_edges.erase(X[j] * 1ll * n + Y[j]);
					}
				}
				unordered_set<int> rdfs;
				for (auto E : add_edges) {
					ll u = E / n, v = E % n;
					if (max(u, v) <= I) {
						u = d.get(u);
						v = d.get(v);
						if (u != v) {
							if (used1[u] != step) gr[u].clear();
							if (used1[v] != step) gr[v].clear();
							used1[u] = step;
							used1[v] = step;
							gr[u].pb(v);
							gr[v].pb(u);
							rdfs.insert(u);
							rdfs.insert(v);
						}
					}
				}
				int ccmp = d.cmp;
				auto dfs = [&](int v, auto&&dfs) -> void {
					used_dfs[v] = step;
					for (auto &u : gr[v]) {
						if (used_dfs[u] != step) {
							ccmp--;
							dfs(u, dfs);
						}
					}
				};
				for (auto &u : rdfs) {
					if (used_dfs[u] != step) {
						dfs(u, dfs);
					}
				}
				ans[numb] += ccmp;
			}
		}
		iota(all(d.par), 0);
		d.siz.assign(n, 1);
		d.cmp = 0;
		for (int I = n - 1; I >= 1; I--) {
			d.cmp++;
			for (auto &u : by_left[I]) d.merge(u, I);
			for (auto &[time, numb] : qnums[I - 1]) {
				step++;
				unordered_set<ll> add_edges = LOL;
				for (int j = i; j <= time; j++) {
					if (T[j] == 0) {
						add_edges.insert(X[j] * 1ll * n + Y[j]);
					} else {
						add_edges.erase(X[j] * 1ll * n + Y[j]);
					}
				}
				unordered_set<int> rdfs;
				for (auto E : add_edges) {
					int u = E / n, v = E % n;
					if (min(u, v) >= I) {
						u = d.get(u);
						v = d.get(v);
						if (u != v) {
							if (used1[u] != step) gr[u].clear();
							if (used1[v] != step) gr[v].clear();
							used1[u] = step;
							used1[v] = step;
							gr[u].pb(v);
							gr[v].pb(u);
							rdfs.insert(u);
							rdfs.insert(v);
						}
					}
				}
				int ccmp = d.cmp;
				auto dfs = [&](int v, auto&&dfs) -> void {
					used_dfs[v] = step;
					for (auto &u : gr[v]) {
						if (used_dfs[u] != step) {
							ccmp--;
							dfs(u, dfs);
						}
					}
				};
				for (auto &u : rdfs) {
					if (used_dfs[u] != step) {
						dfs(u, dfs);
					}
				}
				ans[numb] += ccmp;
			}
		}
	}
	return ans;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 31ms
memory: 4560kb

input:

2 5000 5000
0 0 1
1 0 1
0 0 1
1 1 0
0 1 0
1 1 0
0 1 0
1 0 1
0 1 0
1 0 1
0 0 1
1 0 1
0 1 0
1 1 0
0 1 0
1 1 0
0 0 1
1 0 1
0 1 0
1 0 1
0 1 0
1 0 1
0 0 1
1 0 1
0 1 0
1 1 0
0 0 1
1 1 0
0 1 0
1 1 0
0 1 0
1 1 0
0 1 0
1 0 1
0 1 0
1 0 1
0 0 1
1 0 1
0 0 1
1 0 1
0 0 1
1 0 1
0 1 0
1 1 0
0 1 0
1 0 1
0 0 1
1 1 0
...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
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Test #5:

score: 5
Accepted
time: 39ms
memory: 4268kb

input:

10 5000 5000
0 5 1
1 1 5
0 9 1
1 9 1
0 6 2
1 2 6
0 6 2
1 6 2
0 4 2
1 4 2
0 8 7
1 8 7
0 3 0
1 3 0
0 8 3
1 8 3
0 3 5
1 3 5
0 9 2
1 9 2
0 9 6
1 6 9
0 1 5
0 4 3
1 1 5
1 4 3
0 2 6
0 9 4
1 4 9
1 2 6
0 1 4
1 1 4
0 1 6
1 6 1
0 9 3
0 2 7
1 7 2
1 3 9
0 6 9
0 2 5
1 9 6
0 1 3
1 3 1
0 0 4
0 8 7
1 5 2
1 7 8
1 0 4...

output:

3
4
7
5
9
3
5
4
4
5
10
4
2
7
8
7
2
3
3
8
5
2
6
10
8
3
10
10
8
2
4
3
5
5
6
5
5
9
3
2
2
3
9
5
2
2
3
10
5
10
2
8
4
9
4
9
2
2
5
2
7
10
5
4
2
2
8
5
4
4
6
9
10
2
3
5
3
8
5
8
3
2
9
3
3
9
7
5
5
5
6
10
10
4
10
7
5
9
9
8
2
2
6
8
2
6
2
2
6
6
2
8
3
2
2
5
4
3
9
2
8
5
3
9
4
9
2
3
6
8
8
3
3
7
3
6
8
7
10
4
3
2
5
2
...

result:

ok 5000 lines

Test #6:

score: 5
Accepted
time: 135ms
memory: 4444kb

input:

100 4950 5000
0 38 3
0 56 61
0 87 71
0 64 10
0 92 60
0 44 11
0 3 7
0 81 41
0 43 72
0 73 61
0 77 23
0 63 20
0 64 16
0 11 37
0 51 97
0 80 10
0 56 2
0 76 42
0 69 74
0 26 28
0 40 37
0 5 35
0 25 22
0 95 35
0 89 34
0 3 88
0 26 17
0 40 8
0 8 79
0 48 6
0 18 94
0 76 75
0 44 22
0 30 94
0 50 41
0 92 45
0 11 20...

output:

2
2
2
2
2
2
2
2
2
3
2
2
5
2
2
7
2
2
2
2
2
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
2
2
2
2
2
2
4
2
2
3
2
2
2
68
2
2
2
2
2
3
2
2
2
2
2
2
2
2
2
7
3
2
2
2
2
2
2
2
2
2
13
2
2
2
9
9
71
3
2
7
2
2
2
13
2
9
3
2
2
2
2
2
3
2
2
8
2
2
2
2
2
2
2
2
2
2
2
3
2
2
2
7
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 5000 lines

Test #7:

score: 5
Accepted
time: 3ms
memory: 4632kb

input:

5000 1 5000
0 4285 4296
0 174
0 1012
0 3399
0 3238
0 1816
0 4133
0 3019
0 4260
0 2930
0 4630
0 1081
0 2725
0 4468
0 3870
0 1078
0 2021
0 2532
0 4271
0 3007
0 4647
0 3279
0 1541
0 4631
0 2309
0 2625
0 1049
0 3253
0 1274
0 4488
0 4202
0 885
0 2684
0 2656
0 1036
0 2263
0 2196
0 4410
0 1974
0 2852
0 113...

output:

4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
4999
...

result:

ok 5000 lines

Test #8:

score: 5
Accepted
time: 5ms
memory: 4560kb

input:

5000 13 5000
0 1437 2917
0 4619 3686
0 4797 4454
0 3445 4933
0 561 1988
1 4797 4454
1 1988 561
0 1409 339
0 2874 2680
0 1266 4421
0 803 4698
0 3886 2422
1 3686 4619
1 2249
7 4184
3 4331
3 1568
4 4846
1 3533
12 2754
6 232
4 3193
9 2272
7 2268
10 4048
8 4216
6 3985
0 4840
12 3065
5 2887
12 592
2 1092
...

output:

4999
4998
4998
4997
4996
4998
4998
4997
4995
4996
4997
4997
4997
4999
4999
4996
4997
4994
4997
4996
4999
4997
4996
4995
4995
4997
4998
4996
4998
4996
4999
4998
4995
4996
4997
4996
4998
4996
4994
4996
4996
4998
4997
4996
4999
4998
4993
4997
4997
4998
4997
4999
4996
4992
4998
5000
4993
4998
4997
4997
...

result:

ok 5000 lines

Test #9:

score: 0
Wrong Answer
time: 54ms
memory: 4964kb

input:

5000 5000 5000
0 975 2469
1 2469 975
0 3116 3798
0 2112 4747
0 1861 3986
1 3798 3116
0 2915 1795
0 1550 3770
0 433 3583
1 4747 2112
0 1153 4006
0 2233 3268
1 4006 1153
0 4456 1149
0 4 655
0 4058 2897
1 2915 1795
0 1725 1423
0 2206 1507
1 4058 2897
1 1423 1725
1 4 655
1 433 3583
0 4821 1327
0 1407 24...

output:

4051
3695
4994
4803
3799
4060
3906
4006
3849
4636
4256
4742
4562
3753
2883
4571
4761
4591
3854
3928
4593
4164
4993
4166
4829
3617
4084
3229
3963
4741
4812
4600
3826
4637
4552
4719
3758
3531
4843
3942
3927
4859
4744
3681
3342
4614
3974
4109
4556
3556
4834
4983
3427
3745
3892
4993
4093
2892
4823
4991
...

result:

wrong answer 1st lines differ - expected: '4961', found: '4051'

Subtask #2:

score: 0
Wrong Answer

Test #13:

score: 30
Accepted
time: 22ms
memory: 7484kb

input:

2 1 100000
0 1 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 100000 lines

Test #14:

score: 30
Accepted
time: 42ms
memory: 7476kb

input:

5 10 100000
0 3 2
1 2 3
0 2 1
0 2 3
0 0 3
1 3 2
1 1 2
0 2 4
0 0 2
0 4 0
2 2
0 2
7 2
1 2
8 2
0 2
0 2
6 2
0 2
2 2
2 2
7 2
5 2
8 2
0 2
9 2
2 2
7 2
6 2
0 2
8 2
1 2
3 2
2 2
9 2
9 2
1 2
9 2
6 2
1 2
3 2
1 2
3 2
3 2
5 2
8 2
3 2
0 2
7 2
7 2
8 2
9 2
1 2
1 2
0 2
1 2
1 2
0 2
7 2
9 2
2 2
5 2
6 2
2 2
9 2
9 2
0 2
...

output:

4
5
5
5
4
5
5
5
5
4
4
5
4
4
5
4
4
5
5
5
4
5
4
4
4
4
5
4
5
5
4
5
4
4
4
4
4
5
5
5
4
4
5
5
5
5
5
5
5
4
4
4
5
4
4
4
5
4
4
5
4
5
4
5
5
4
5
5
5
4
4
5
4
4
5
4
5
4
4
4
4
4
5
4
4
4
4
4
4
5
5
5
4
5
4
4
5
5
4
4
5
4
4
4
5
4
5
4
5
5
4
4
4
5
5
4
4
5
5
4
5
4
4
5
5
5
5
4
4
4
4
4
4
5
5
4
4
5
4
5
5
5
5
4
5
4
4
4
5
5
...

result:

ok 100000 lines

Test #15:

score: 0
Wrong Answer
time: 949ms
memory: 12936kb

input:

10 100000 100000
0 4 5
0 2 0
1 2 0
0 1 8
1 5 4
0 8 6
0 2 3
0 1 7
1 7 1
1 8 6
0 6 0
0 9 1
0 2 1
0 0 7
1 7 0
1 8 1
1 2 1
1 1 9
0 9 4
1 6 0
1 4 9
1 3 2
0 2 6
0 5 4
0 7 5
0 1 9
0 6 0
1 1 9
1 0 6
0 3 8
1 6 2
1 7 5
1 4 5
1 8 3
0 1 5
0 1 6
0 1 9
1 6 1
1 9 1
1 5 1
0 7 2
1 2 7
0 8 9
1 9 8
0 9 4
0 9 1
0 4 1
1...

output:

2
2
2
9
3
2
9
7
2
5
2
3
5
9
2
3
9
10
4
2
2
3
2
3
2
2
2
2
3
2
8
10
5
7
2
2
7
2
9
3
3
2
9
10
2
2
2
3
8
4
2
2
2
2
4
8
9
3
2
2
4
8
2
2
7
2
3
2
2
4
2
2
5
5
5
4
2
2
2
2
2
2
3
2
2
5
3
2
2
10
2
2
10
2
8
2
6
3
3
2
2
6
4
2
5
10
2
2
2
4
4
9
3
2
2
2
5
2
10
8
5
2
3
2
2
2
2
2
2
8
4
9
2
2
2
2
2
3
2
2
5
2
9
2
6
4
4...

result:

wrong answer 212th lines differ - expected: '7', found: '6'

Subtask #3:

score: 0
Time Limit Exceeded

Test #28:

score: 30
Accepted
time: 21ms
memory: 7428kb

input:

2 1 100000
0 1 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 100000 lines

Test #29:

score: 30
Accepted
time: 39ms
memory: 6984kb

input:

5 7 100000
0 3 1
0 4 1
0 2 3
0 2 1
0 2 4
0 2 0
0 4 0
1 0
3 0
4 0
0 3
1 2
2 0
4 0
2 1
5 1
4 0
2 3
0 2
0 3
6 0
4 2
5 2
4 3
5 0
0 0
5 3
0 1
4 0
4 0
3 1
3 0
1 1
6 3
0 0
0 0
0 3
5 3
3 2
6 0
5 0
4 1
0 0
5 0
0 3
2 3
1 2
2 1
6 2
0 0
3 2
0 0
2 2
1 0
1 1
0 2
1 0
5 3
5 2
2 1
2 2
3 0
2 3
1 3
1 0
3 1
5 2
1 2
5 0...

output:

3
2
2
4
5
2
2
4
3
2
3
5
4
2
4
3
3
2
4
2
5
2
2
4
2
5
2
4
4
4
2
4
2
2
3
4
2
4
3
5
4
3
4
4
4
5
3
5
5
3
2
3
4
5
2
3
4
3
4
3
5
2
5
4
5
2
4
2
5
2
4
5
4
3
2
3
3
3
2
4
5
4
5
4
4
2
3
4
3
3
2
3
2
3
3
2
4
4
4
5
3
3
4
5
4
4
5
3
3
2
5
3
5
4
3
2
5
4
4
5
3
3
4
4
3
5
4
2
4
2
2
4
2
3
4
2
5
5
4
4
2
2
3
3
4
2
2
5
5
4
...

result:

ok 100000 lines

Test #30:

score: 30
Accepted
time: 102ms
memory: 7764kb

input:

10 20 100000
0 5 6
0 5 0
0 0 9
0 0 6
0 3 4
0 4 0
0 7 9
0 3 1
0 4 1
0 6 1
0 3 0
0 8 7
0 1 2
0 5 1
0 3 2
0 8 4
0 8 6
0 2 0
0 4 6
0 9 3
11 6
13 5
19 8
11 4
13 7
5 8
12 6
9 0
9 5
3 4
7 2
18 4
19 0
0 3
4 8
11 4
17 8
4 7
11 3
8 5
0 7
4 5
4 5
10 5
4 6
11 8
9 3
17 7
3 2
17 7
12 5
14 5
12 4
8 4
3 4
12 7
8 1
...

output:

3
3
2
4
4
6
2
5
5
9
7
2
2
9
7
4
2
7
5
5
9
8
8
5
7
4
7
4
9
4
3
3
3
5
9
4
7
5
3
3
5
9
5
3
8
5
4
8
7
7
4
9
9
7
3
9
5
8
8
4
3
6
8
4
8
8
5
2
4
10
3
2
7
2
3
8
9
8
2
7
4
9
2
3
4
4
4
9
9
7
5
2
3
9
2
8
9
8
6
7
9
8
8
2
8
5
6
3
9
2
9
4
9
6
4
7
4
3
5
3
9
7
7
2
5
8
4
7
8
6
2
8
9
5
2
8
7
10
5
9
5
2
5
7
9
3
10
4
2...

result:

ok 100000 lines

Test #31:

score: 30
Accepted
time: 186ms
memory: 7700kb

input:

10 45 100000
0 5 7
0 2 1
0 3 5
0 4 2
0 4 8
0 7 3
0 0 8
0 1 4
0 6 2
0 9 8
0 7 2
0 5 0
0 1 3
0 6 4
0 9 1
0 4 3
0 8 6
0 2 8
0 5 1
0 3 2
0 7 9
0 4 5
0 0 2
0 0 3
0 8 5
0 1 8
0 0 1
0 0 7
0 1 7
0 6 0
0 6 5
0 7 6
0 4 7
0 7 8
0 2 9
0 9 3
0 1 6
0 6 9
0 0 9
0 9 4
0 3 8
0 5 2
0 3 6
0 9 5
0 0 4
17 8
32 2
8 0
29 ...

output:

2
2
4
2
2
2
2
2
9
2
2
4
2
2
2
2
2
2
6
4
5
2
7
3
3
2
2
8
2
2
3
2
9
5
6
3
3
4
6
7
4
6
2
2
7
7
2
5
2
2
2
2
2
2
3
2
2
6
8
2
2
10
9
6
2
5
2
2
2
2
7
3
6
8
2
2
2
7
2
2
2
2
2
9
4
2
2
3
2
2
2
2
2
7
2
7
3
5
2
3
2
2
2
2
2
6
5
2
2
3
7
2
7
2
6
3
8
5
7
2
5
4
3
2
3
2
2
9
4
2
2
2
2
3
9
2
2
3
3
4
6
2
5
2
3
5
2
6
2
2...

result:

ok 100000 lines

Test #32:

score: 30
Accepted
time: 3000ms
memory: 7360kb

input:

100 500 100000
0 75 20
0 23 42
0 53 70
0 11 28
0 23 67
0 74 63
0 93 4
0 13 43
0 96 72
0 2 65
0 43 96
0 86 52
0 77 38
0 89 33
0 85 84
0 55 48
0 8 20
0 7 18
0 43 62
0 38 44
0 42 24
0 98 6
0 92 66
0 17 33
0 4 70
0 12 74
0 13 99
0 79 63
0 53 14
0 38 22
0 54 41
0 61 44
0 85 21
0 25 38
0 38 28
0 81 87
0 7...

output:

8
19
7
7
5
51
5
8
16
8
3
6
5
3
42
3
6
5
9
15
3
9
7
6
5
26
12
4
22
22
3
13
11
6
99
3
79
2
30
3
2
9
56
5
67
2
43
4
12
3
28
26
11
6
5
18
2
6
72
6
17
2
11
18
48
86
3
3
85
6
10
3
7
36
5
3
6
12
5
3
38
3
3
11
9
93
54
60
8
22
35
4
34
16
48
6
11
5
5
31
99
43
60
5
11
8
2
21
69
3
94
50
8
3
8
3
8
6
25
28
3
6
2
...

result:

ok 100000 lines

Test #33:

score: 30
Accepted
time: 2490ms
memory: 6824kb

input:

100 4950 100000
0 50 40
0 87 50
0 72 73
0 74 65
0 2 4
0 29 28
0 20 28
0 15 99
0 13 56
0 31 5
0 5 89
0 28 10
0 84 6
0 19 92
0 38 96
0 89 86
0 21 10
0 18 35
0 84 28
0 86 80
0 69 45
0 33 62
0 3 45
0 81 22
0 0 43
0 12 41
0 81 58
0 34 4
0 53 65
0 55 43
0 71 18
0 60 17
0 44 18
0 12 6
0 55 94
0 87 41
0 42 ...

output:

2
4
2
2
2
2
4
2
2
3
2
2
2
2
2
2
5
2
2
2
2
2
2
2
2
2
2
4
2
2
5
2
2
2
14
2
16
2
2
2
2
2
2
2
2
2
3
2
2
2
2
2
2
41
2
2
2
2
2
14
2
2
2
2
2
2
2
2
6
2
2
2
2
2
2
2
2
8
2
2
2
2
2
2
2
2
2
28
2
2
2
2
2
14
2
2
12
2
2
2
2
2
2
2
2
2
3
2
2
2
2
10
2
2
2
2
2
2
2
3
2
2
2
2
2
2
2
2
2
2
2
2
2
6
78
2
2
2
2
2
2
2
2
2
2
1...

result:

ok 100000 lines

Test #34:

score: 30
Accepted
time: 2880ms
memory: 12096kb

input:

1000 75000 100000
0 312 514
0 320 439
0 100 448
0 646 280
0 535 701
0 199 217
0 178 777
0 843 287
0 996 52
0 587 444
0 728 395
0 882 610
0 875 656
0 971 990
0 656 990
0 549 684
0 766 968
0 969 956
0 15 757
0 978 467
0 736 621
0 673 44
0 911 944
0 555 47
0 385 922
0 897 648
0 352 936
0 157 311
0 645 ...

output:

2
6
2
2
2
10
2
2
2
2
2
2
2
2
3
2
2
2
17
177
3
2
3
2
2
2
39
4
3
2
2
3
2
2
2
2
4
2
2
2
40
2
236
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
694
2
2
2
3
12
19
2
10
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
2
2
2
2
34
4
2
2
2
2
2
2
2
2
2
2
2
2
2
2
12
2
2
2
3
2
2
2
3
70
33
2
14
2
3
2
2
17
2
2
2
2
2
2
2
7
2
2
2
8
10
2
2
3
...

result:

ok 100000 lines

Test #35:

score: 30
Accepted
time: 3706ms
memory: 15164kb

input:

10000 100000 100000
0 4650 4651
0 5118 50
0 8501 1203
0 4320 9114
0 5284 84
0 7128 8483
0 6247 6754
0 4110 4770
0 7990 4574
0 1552 708
0 772 6932
0 924 9657
0 9165 8340
0 8946 1023
0 4548 8725
0 3262 6753
0 8435 8769
0 7335 9388
0 4270 5695
0 2997 5918
0 6108 18
0 724 5121
0 1094 3007
0 7024 4086
0 ...

output:

51
73
889
316
26
367
4
5327
2831
167
3436
107
142
37
8
510
9029
32
28
436
377
342
84
17
4266
38
2590
120
95
52
404
19
21
591
8941
5501
56
362
225
87
263
226
576
40
207
917
31
154
48
6348
1250
53
194
60
65
222
21
67
1688
620
342
62
946
155
25
207
61
1402
72
226
153
22
8283
314
7467
117
9033
17
7044
2...

result:

ok 100000 lines

Test #36:

score: 30
Accepted
time: 36ms
memory: 20068kb

input:

100000 1 100000
0 33336 16556
0 92196
0 26197
0 53372
0 38599
0 96200
0 44612
0 24541
0 75990
0 28525
0 25457
0 83626
0 61731
0 69015
0 29071
0 3513
0 39485
0 52956
0 9699
0 90062
0 41875
0 14538
0 74187
0 73753
0 97815
0 61704
0 86178
0 42498
0 44887
0 55131
0 98310
0 78129
0 54118
0 25940
0 11754
...

output:

99999
100000
99999
99999
99999
99999
100000
99999
100000
100000
99999
99999
99999
100000
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
100000
99999
100000
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999
99999...

result:

ok 100000 lines

Test #37:

score: 30
Accepted
time: 5093ms
memory: 18624kb

input:

100000 1000 100000
0 40911 70767
0 43851 74810
0 98101 23348
0 2588 74553
0 99709 32715
0 80067 21678
0 65194 58715
0 20669 33662
0 58431 82503
0 23326 15298
0 65281 6831
0 49793 40357
0 84369 53367
0 65621 16191
0 99338 18468
0 87123 1278
0 59646 15976
0 34874 48231
0 28748 77608
0 35658 19831
0 75...

output:

99535
99471
99799
99610
99996
99597
99721
99361
99778
99792
99768
99743
99656
99504
99638
99595
99552
99737
99882
99866
99084
99509
99941
99630
99745
99988
99547
99633
99860
99915
99552
99610
99329
99766
99922
99521
99815
99359
99621
99658
99442
99979
99982
99672
99971
99742
99867
99690
99834
99601
...

result:

ok 100000 lines

Test #38:

score: 30
Accepted
time: 5953ms
memory: 30376kb

input:

100000 100000 100000
0 58788 61813
0 21513 25800
0 88016 61813
0 61813 76909
0 80963 25800
0 10224 61813
0 6529 25800
0 84889 16488
0 25800 18639
0 61813 12954
0 86274 61813
0 61813 47108
0 87338 61813
0 31751 61813
0 33113 51903
0 16488 72671
0 28731 40816
0 16488 46955
0 25800 47670
0 72904 16488
...

output:

78047
60034
90581
63392
67541
60865
89448
81437
80808
79233
52778
88836
65017
68685
94108
41263
58600
55445
39882
58392
51111
98840
66143
82087
62682
89169
86782
58768
55792
96187
67172
45894
85547
78657
55227
61523
29863
74318
66324
66850
79441
68780
88962
60149
69875
92753
72295
47527
39478
71770
...

result:

ok 100000 lines

Test #39:

score: 0
Time Limit Exceeded

input:

100000 100000 100000
0 20750 63020
0 78129 41347
0 6274 44744
0 84800 27790
0 38830 41299
0 45700 1339
0 54539 62677
0 66137 96771
0 97257 95836
0 99860 22225
0 1817 18865
0 76593 67906
0 14538 48021
0 53976 99932
0 18091 93984
0 81227 60047
0 71218 27770
0 62632 49210
0 85275 86222
0 10536 63833
0 ...

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%