QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#336130#8109. Postcardsucup-team1209#AC ✓486ms80296kbC++203.2kb2024-02-24 13:25:472024-02-24 13:25:48

Judging History

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

  • [2024-02-24 13:25:48]
  • 评测
  • 测评结果:AC
  • 用时:486ms
  • 内存:80296kb
  • [2024-02-24 13:25:47]
  • 提交

answer

#include<bits/stdc++.h>
using std::cin;
using std::cout;
using ll = long long;
using u64 = unsigned long long;
int n, m, q;
const int N = 3005;
const int M = 500005;
int U[M], V[M];
const int K = 101;
int e[N][N];
int s[N][N];

int w[N][N];

std::bitset<K> ee[K];
int vis[N], dep[N];
int dfn[N], size[N];
int anc[N];
int sz[N];
int cc;
std::vector<int> son[N];
void dfs0(int x, int fa = 0) {
	vis[x] = 1;
	anc[x] = fa;
	dep[x] = dep[fa] + 1;
	dfn[x] = ++cc, size[x] = 1;
	for(int i = 1;i <= n;++i) if(!vis[i] && e[x][i]) {
		son[x].push_back(i);
		dfs0(i, x);
		size[x] += size[i];
	}
}
int in(int x, int y) {
	return dfn[y] <= dfn[x] && dfn[x] < dfn[y] + size[y];
}
int u[N], v[N], a[N], b[N];
void dfs1(int x, int type) {
	for(int i : son[x]) {
		dfs1(i, type);
		if(type == 1) {
			for(int j = 1;j <= n;++j) {
				s[x][j] += s[i][j];
			}
		} else {
			for(int j = 1;j <= n;++j) {
				s[j][x] += s[j][i];
			}
		}
	}
}
std::vector<int> vs[N];

int main() {
	std::ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m >> q;
	for(int i = 0, x, y;i < m;++i) {
		cin >> x >> y;
		U[i] = x;
		V[i] = y;
		++ e[x][y];
		++ e[y][x];
	}
	dfs0(1);
	for(int i = 1;i <= n;++i) {
		for(int j = 1;j <= n;++j) {
			s[i][j] = e[i][j];
		}
	}
	dfs1(1, 1);
	dfs1(1, 2);
	int last = 0;
	for(int i = 0;i < q;++i) {
		int r;
		cin >> r;
		std::vector<int> set = {1};
		for(int j = 0;j < r;++j) {
			int x;
			cin >> x >> a[j] >> b[j];
			x = (x + last) % m;
			u[j] = U[x];
			v[j] = V[x];
			if(dep[u[j]] > dep[v[j]]) {
				std::swap(u[j], v[j]);
				std::swap(a[j], b[j]);
			}
			if(anc[v[j]] == u[j])
				set.push_back(v[j]);
		}
		auto cmp = [&](int x, int y) { return dfn[x] < dfn[y]; };
		sort(set.begin(), set.end(), cmp);
		set.erase(unique(set.begin(), set.end()), set.end());
		auto gid = [&](int x) {
			return lower_bound(set.begin(), set.end(), x, cmp) - set.begin();
		};
		auto getanc = [&](int x, bool t = 0) {
			int anc = 1;
			for(int y : set)  {
				if(t && x == y) continue;
				if(in(x, y) && dep[y] > dep[anc]) anc = y;
			}
			return gid(anc);
		};
		int N = set.size();
		for(int i = 0;i < N;++i) vs[i].clear();
		for(int x : set) {
			if(x == 1) continue;
			vs[getanc(x, 1)].push_back(gid(x));
		}
		for(int i = 0;i < N;++i) {
			sz[i] = size[set[i]];
			for(int j = 0;j < N;++j) {
				w[i][j] = s[set[i]][set[j]];
			}
		}
		for(int i = 0;i < N;++i) 
			for(int x : vs[i]) sz[i] -= sz[x];
		for(int i = 0;i < N;++i) 
			for(int j = 0;j < N;++j) 
				for(int x : vs[i]) w[i][j] -= w[x][j];
		for(int i = 0;i < N;++i) 
			for(int j = 0;j < N;++j) 
				for(int x : vs[j]) w[i][j] -= w[i][x];
		for(int j = 0;j < r;++j) {
			int A = getanc(u[j]);
			int B = getanc(v[j]);
			if(a[j]) -- w[A][B];
			if(b[j]) -- w[B][A];
		}
		for(int i = 0;i < N;++i) {
			ee[i].reset();
		}
		for(int i = 0;i < N;++i) {
			ee[i].set(i);
			for(int j = 0;j < N;++j) {
				if(w[i][j]) ee[j].set(i);
			}
		}
		for(int k = 0;k < N;++k) {
			for(int i = 0;i < N;++i) if(ee[i].test(k)) {
				ee[i] |= ee[k];
			}
		}
		int ans = 0;
		for(int i = 0;i < N;++i) {
			if(ee[i].count() == N) {
				ans += sz[i];
			}
		}
		cout << ans << '\n';
		last += ans;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 4 3
1 2
4 3
2 3
1 3
2
3 1 1
1 0 1
3
1 1 0
0 1 0
3 1 0
1
1 1 1

output:

3
1
0

result:

ok 3 number(s): "3 1 0"

Test #2:

score: 0
Accepted
time: 208ms
memory: 80156kb

input:

3000 11860 5000
135 1279
1379 1627
1253 2516
338 1596
260 1086
1153 2182
527 732
500 2820
1395 1556
793 1491
2673 2746
1630 1792
1720 2871
443 2095
1095 1296
2008 2358
1685 1801
2356 2704
1856 2698
1798 2134
1683 1792
812 2977
43 1507
1297 1574
222 1563
1278 2168
1181 1851
1492 2757
432 1459
428 902...

output:

3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
2999
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
3000
...

result:

ok 5000 numbers

Test #3:

score: 0
Accepted
time: 135ms
memory: 70976kb

input:

2430 490875 33333
2 1
3 1
3 2
4 1
4 2
4 3
5 1
5 2
5 3
5 4
6 1
6 2
6 3
6 4
6 5
7 1
7 2
7 3
7 4
7 5
7 6
8 1
8 2
8 3
8 4
8 5
8 6
8 7
9 1
9 2
9 3
9 4
9 5
9 6
9 7
9 8
10 1
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
11 1
11 2
11 3
11 4
11 5
11 6
11 7
11 8
11 9
11 10
12 1
12 2
12 3
12 4
12 5
12 6
12 7
12 8
12...

output:

405
405
2430
405
2430
2430
1620
405
2430
2430
405
405
405
1620
2025
405
405
2025
0
405
405
405
405
405
2430
405
405
405
1620
405
405
1620
2430
2430
2430
405
2430
405
2430
1620
405
405
405
2430
1215
2025
2430
405
2025
2430
2430
1620
0
405
405
1215
405
2430
405
0
2430
405
405
0
2430
405
1215
405
2430
...

result:

ok 33333 numbers

Test #4:

score: 0
Accepted
time: 159ms
memory: 66752kb

input:

2225 493960 50000
2 1
3 1
3 2
4 1
4 2
4 3
5 1
5 2
5 3
5 4
6 1
6 2
6 3
6 4
6 5
7 1
7 2
7 3
7 4
7 5
7 6
8 1
8 2
8 3
8 4
8 5
8 6
8 7
9 1
9 2
9 3
9 4
9 5
9 6
9 7
9 8
10 1
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
11 1
11 2
11 3
11 4
11 5
11 6
11 7
11 8
11 9
11 10
12 1
12 2
12 3
12 4
12 5
12 6
12 7
12 8
12...

output:

2225
2225
445
445
445
445
445
1780
2225
445
1780
1780
1335
2225
2225
2225
1780
445
445
445
2225
445
445
445
445
2225
2225
445
0
1780
445
445
445
445
445
445
1780
445
2225
445
445
0
445
445
2225
0
445
445
445
0
1780
0
445
445
445
0
445
2225
445
2225
2225
445
2225
445
0
445
2225
0
2225
445
2225
445
22...

result:

ok 50000 numbers

Test #5:

score: 0
Accepted
time: 162ms
memory: 74780kb

input:

2625 490896 23809
2 1
3 1
3 2
4 1
4 2
4 3
5 1
5 2
5 3
5 4
6 1
6 2
6 3
6 4
6 5
7 1
7 2
7 3
7 4
7 5
7 6
8 1
8 2
8 3
8 4
8 5
8 6
8 7
9 1
9 2
9 3
9 4
9 5
9 6
9 7
9 8
10 1
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
11 1
11 2
11 3
11 4
11 5
11 6
11 7
11 8
11 9
11 10
12 1
12 2
12 3
12 4
12 5
12 6
12 7
12 8
12...

output:

2625
375
2625
2250
1125
375
375
375
0
2250
375
1875
1125
2625
375
375
2625
1875
2625
2625
2250
2625
2250
375
375
375
2250
2625
2625
1875
2625
375
0
375
2625
2625
2625
2625
375
375
375
2625
375
375
2625
375
375
375
2250
375
2625
1125
1125
375
375
2625
2625
0
375
2625
375
375
0
2625
375
375
2625
2625
...

result:

ok 23809 numbers

Test #6:

score: 0
Accepted
time: 158ms
memory: 80072kb

input:

3000 3000 250000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
...

output:

407
687
1378
2124
15
1126
78
1253
990
2020
2664
1455
1888
1494
1448
2467
2995
2193
1673
2823
90
1836
2565
2990
1604
239
429
2943
812
498
1956
829
1164
1329
1703
1578
753
2550
2302
1961
1264
2612
1763
2379
1337
1509
673
1609
2489
643
1736
2003
128
1388
1283
432
2606
931
2283
1695
753
2088
363
1084
46...

result:

ok 250000 numbers

Test #7:

score: 0
Accepted
time: 160ms
memory: 80012kb

input:

3000 13800 250000
2 1
3 1
3 2
4 1
4 2
4 3
5 1
5 2
5 3
5 4
6 1
6 2
6 3
6 4
6 5
7 1
7 2
7 3
7 4
7 5
7 6
8 1
8 2
8 3
8 4
8 5
8 6
8 7
9 1
9 2
9 3
9 4
9 5
9 6
9 7
9 8
10 1
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
12 11
13 11
13 12
14 11
14 12
14 13
15 11
15 12
15 13
15 14
16 11
16 12
16 13
16 14
16 15
17 ...

output:

260
780
1360
2090
2650
930
2390
2790
2650
1970
1390
510
930
2390
620
2500
50
690
1210
1990
330
1200
2950
2880
630
1740
920
320
20
1700
570
2320
2900
1810
2950
70
850
440
570
1540
470
1400
2770
10
680
1150
1450
380
390
1880
130
340
1170
1980
2550
2360
1920
70
1010
450
2540
1030
2650
260
1010
1020
650...

result:

ok 250000 numbers

Test #8:

score: 0
Accepted
time: 179ms
memory: 78616kb

input:

3000 448510 250000
2 1
3 1
3 2
4 1
4 2
4 3
5 1
5 2
5 3
5 4
6 1
6 2
6 3
6 4
6 5
7 1
7 2
7 3
7 4
7 5
7 6
8 1
8 2
8 3
8 4
8 5
8 6
8 7
9 1
9 2
9 3
9 4
9 5
9 6
9 7
9 8
10 1
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
11 1
11 2
11 3
11 4
11 5
11 6
11 7
11 8
11 9
11 10
12 1
12 2
12 3
12 4
12 5
12 6
12 7
12 8
1...

output:

300
2700
1500
300
2700
2700
2100
1500
2400
600
2100
2700
2100
1200
2100
300
600
2700
1500
2700
600
300
1800
1500
2700
900
2700
300
1200
1500
1200
2100
1200
1500
900
2400
1200
2100
2100
2700
1800
1200
900
1200
2100
2700
2100
2100
1500
300
2400
2700
1200
1800
600
2100
2100
2700
600
2100
600
1800
300
2...

result:

ok 250000 numbers

Test #9:

score: 0
Accepted
time: 118ms
memory: 77996kb

input:

2800 9200 41666
2 1
3 1
3 2
4 1
4 2
4 3
5 1
5 2
5 3
5 4
6 1
6 2
6 3
6 4
6 5
7 1
7 2
7 3
7 4
7 5
7 6
9 8
10 8
10 9
11 8
11 9
11 10
12 8
12 9
12 10
12 11
13 8
13 9
13 10
13 11
13 12
14 8
14 9
14 10
14 11
14 12
14 13
16 15
17 15
17 16
18 15
18 16
18 17
19 15
19 16
19 17
19 18
20 15
20 16
20 17
20 18
20...

output:

21
14
21
28
42
7
63
14
28
21
14
63
63
63
14
14
14
7
21
42
21
14
63
28
14
14
42
42
21
21
7
21
28
21
42
42
28
42
42
28
63
28
14
7
42
14
21
42
42
28
42
7
42
42
14
28
63
28
14
28
14
42
14
42
63
42
14
7
42
14
28
14
21
7
21
42
7
28
28
14
21
21
63
21
42
14
42
14
28
63
21
42
7
42
63
42
14
7
42
63
21
21
7
14...

result:

ok 41666 numbers

Test #10:

score: 0
Accepted
time: 158ms
memory: 79828kb

input:

2940 20972 15625
2 1
3 1
3 2
4 1
4 2
4 3
5 1
5 2
5 3
5 4
6 1
6 2
6 3
6 4
6 5
7 1
7 2
7 3
7 4
7 5
7 6
8 1
8 2
8 3
8 4
8 5
8 6
8 7
9 1
9 2
9 3
9 4
9 5
9 6
9 7
9 8
10 1
10 2
10 3
10 4
10 5
10 6
10 7
10 8
10 9
11 1
11 2
11 3
11 4
11 5
11 6
11 7
11 8
11 9
11 10
12 1
12 2
12 3
12 4
12 5
12 6
12 7
12 8
12 ...

output:

90
480
150
525
60
840
300
600
960
240
60
525
420
90
75
90
60
360
960
450
120
150
225
75
525
75
840
120
60
150
360
420
300
300
105
375
360
90
270
15
180
360
360
630
420
60
225
60
360
240
60
525
360
600
90
180
90
210
360
540
180
30
90
60
180
180
120
525
480
630
105
600
60
525
15
210
90
315
525
120
420...

result:

ok 15625 numbers

Test #11:

score: 0
Accepted
time: 130ms
memory: 80296kb

input:

2809 5618 5000
1 54
1 2
2 55
2 3
3 56
3 4
4 57
4 5
5 58
5 6
6 59
6 7
7 60
7 8
8 61
8 9
9 62
9 10
10 63
10 11
11 64
11 12
12 65
12 13
13 66
13 14
14 67
14 15
15 68
15 16
16 69
16 17
17 70
17 18
18 71
18 19
19 72
19 20
20 73
20 21
21 74
21 22
22 75
22 23
23 76
23 24
24 77
24 25
25 78
25 26
26 79
26 27...

output:

9
46
10
250
240
81
408
84
484
175
63
48
57
154
8
198
84
350
18
308
50
285
114
368
54
196
55
336
30
72
120
192
76
260
368
108
250
108
255
56
170
320
8
336
4
198
200
120
252
255
10
30
625
48
9
30
500
150
30
168
418
112
576
247
18
30
253
414
65
462
216
60
352
72
380
84
6
28
42
170
437
25
400
182
170
22...

result:

ok 5000 numbers

Test #12:

score: 0
Accepted
time: 96ms
memory: 12148kb

input:

20 100 12500
7 12
14 16
3 8
1 16
5 13
9 16
2 18
10 20
9 12
1 6
5 17
11 15
6 16
4 11
1 12
5 15
6 14
4 10
12 13
5 20
3 19
11 13
13 20
17 20
4 18
9 10
2 19
6 15
13 15
6 10
3 18
2 20
15 16
4 9
5 14
3 20
4 5
5 19
18 19
4 15
16 17
17 18
9 15
10 16
14 19
5 16
2 5
3 10
1 11
8 9
3 6
5 12
13 14
1 4
2 15
7 14
...

output:

20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
20
...

result:

ok 12500 numbers

Test #13:

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

input:

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

output:

2
0
0
3
0
1
0
1
0
3
0
3
3
0
0
2
0
1
2
2
0
3
0
0
1
0
1
0
3
0
3
0
3
0
3
0
2
1
2
2
1
3
3
3
1
3
1
1
1
3
3
0
2
3
0
3
2
0
3
1
1
1
0
1
0
3
0
3
1
2
1
0
2
1
3
3
0
0
1
3
3
0
1
0
2
3
0
1
0
3
2
3
3
2
2
2
0
1
1
1
0
3
1
1
2
2
2
2
0
1
3
1
3
3
0
1
0
1
3
1
3
2
2
3
3
3
1
0
2
0
1
0
2
0
3
1
3
1
3
3
3
2
0
0
1
0
3
3
0
1
...

result:

ok 100000 numbers

Test #14:

score: 0
Accepted
time: 174ms
memory: 79612kb

input:

3000 2999 100000
32 23
1819 1600
1795 530
263 65
2688 1258
540 186
835 75
2780 1758
1483 753
859 394
387 97
100 56
616 199
824 136
1633 834
2086 789
1582 60
733 309
47 29
545 237
2418 1559
966 250
1032 929
1590 600
1980 983
2378 325
1504 1309
2583 1446
2510 976
2631 1099
1278 1264
2643 331
151 59
13...

output:

2901
2979
2944
2988
2986
2990
2992
2981
2994
2994
2991
2993
2988
2995
2993
2990
2976
2968
2967
2989
2993
2968
2984
2991
2991
2990
2990
2988
2981
2992
2991
2989
2995
2989
2978
2983
2922
2985
2991
2980
2993
2978
2985
2995
2975
2990
2986
2990
2979
2935
2990
2986
2993
2983
2979
2993
2971
2934
2993
2994
...

result:

ok 100000 numbers

Test #15:

score: 0
Accepted
time: 261ms
memory: 77596kb

input:

2999 2998 17857
2123 1486
1916 1560
1615 335
948 870
453 88
818 350
2502 1982
2819 1992
1333 711
1436 1282
397 362
1314 525
2926 564
94 90
2835 1610
2994 1891
2011 325
1844 211
1186 4
2006 221
1832 1700
2763 2518
607 348
2483 1077
449 352
2241 1457
2317 2149
1250 886
2180 850
1162 73
1142 1054
1118 ...

output:

2843
2826
2914
1
2717
2881
2584
2903
2727
2932
2840
1
2789
2863
2902
2913
26
2830
2317
2889
2909
2888
2876
2934
11
2853
2565
2910
2919
2937
2748
2904
2884
2922
2895
2876
2855
2703
2889
2716
2945
2769
2916
2901
2829
2875
2726
2939
2939
2769
2902
2261
2778
2924
2698
2346
2932
2898
2683
2766
2297
2809
...

result:

ok 17857 numbers

Test #16:

score: 0
Accepted
time: 486ms
memory: 78028kb

input:

2999 2998 5000
1095 1092
624 381
1167 916
2307 1155
1976 1067
584 282
2978 936
1383 247
481 279
1185 1015
2097 2008
2268 2080
393 217
1528 1417
1590 1009
1353 66
1054 370
526 169
1790 591
2287 2129
1959 855
2679 2364
903 654
256 101
752 595
1683 904
2494 485
236 64
2796 1904
2037 1038
2396 934
2898 ...

output:

12
2331
1600
2487
2530
1970
2388
2627
2525
2728
2445
2394
2588
2263
940
1895
2332
2393
2549
0
2551
914
2361
2366
0
0
1
2311
1
2261
2605
2300
2650
2306
2528
2568
2640
2311
2466
2512
2527
2197
4
4
2374
1867
2690
2003
8
2508
2272
2728
1
8
3
1568
904
2455
1
2246
2259
2707
2628
2287
1
1637
0
2556
2409
0
...

result:

ok 5000 numbers