QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#184990#6674. Connected Intervalsjeffqi#AC ✓194ms33516kbC++142.4kb2023-09-21 15:24:372023-09-21 15:24:38

Judging History

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

  • [2023-09-21 15:24:38]
  • 评测
  • 测评结果:AC
  • 用时:194ms
  • 内存:33516kb
  • [2023-09-21 15:24:37]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define eb emplace_back
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) ((int)v.size())
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define ui unsigned int
#define ull unsigned ll
#define i128 __int128
using namespace std;

namespace qiqi {
	const int inf = 1e9;
	struct Seg {
#define ls (x<<1)
#define rs (ls|1)
		int n; vi mx,cnt,tag;
		Seg(int n):n(n),mx(n*4,-inf),cnt(n*4),tag(n*4) {}
		void pull(int x) {
			mx[x] = max(mx[ls],mx[rs]);
			cnt[x] = 0;
			if (mx[x] == mx[ls]) {
				cnt[x] += cnt[ls];
			}
			if (mx[x] == mx[rs]) {
				cnt[x] += cnt[rs];
			}
		}
		void apl(int x,int k) {
			mx[x] += k; tag[x] += k;
		}
		void push(int x) {
			if (tag[x]) {
				apl(ls,tag[x]); apl(rs,tag[x]);
				tag[x] = 0;
			}
		}
		void ins(int x,int l,int r,int p,int k) {
			if (r-l == 1) {
				mx[x] = k; cnt[x] = 1;
				return;
			}
			int mid = l+((r-l)>>1);
			push(x);
			if (p < mid) {
				ins(ls,l,mid,p,k);
			}
			else {
				ins(rs,mid,r,p,k);
			}
			pull(x);
		}
		void ins(int p,int k) {
			return ins(1,0,n,p,k);
		}
		void upd(int x,int l,int r,int pl,int pr,int k) {
			if (pl <= l && r <= pr) {
				return apl(x,k);
			}
			int mid = l+((r-l)>>1);
			push(x);
			if (pl < mid) {
				upd(ls,l,mid,pl,pr,k);
			}
			if (pr > mid) {
				upd(rs,mid,r,pl,pr,k);
			}
			pull(x);
		}
		void upd(int pl,int pr,int k) {
			return upd(1,0,n,pl,pr,k);
		}
	};
	void main() {
		int n;
		cin >> n;
		vector<vi> e(n);
		for (int i = 0; i < n-1; i++) {
			int u,v;
			cin >> u >> v; u--; v--;
			if (u > v) {
				swap(u,v);
			}
			e[u].eb(v);
		}
		Seg seg(n);
		ll ans = 0;
		for (int i = n-1; i >= 0; i--) {
			seg.ins(i,-i);
			for (auto x:e[i]) {
				seg.upd(x,n,1);
			}
			if (seg.mx[1] == -i) {
				ans += seg.cnt[1];
			}
		}
		cout << ans << '\n';
	}
}

int main() {
//	clock_t st = clock();
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int T = 1;
	cin >> T;
	while (T--) {
		qiqi::main();
	}

//	cout << (double)(clock()-st)/CLOCKS_PER_SEC;
	return 0;
}

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

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3464kb

input:

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

output:

10
9

result:

ok 2 number(s): "10 9"

Test #2:

score: 0
Accepted
time: 15ms
memory: 3488kb

input:

18249
1
2
1 2
3
1 2
1 3
3
2 1
2 3
3
3 1
2 3
4
1 2
1 3
1 4
4
2 3
1 2
1 4
4
3 2
1 3
1 4
4
4 2
1 3
1 4
4
1 3
2 1
2 4
4
2 1
2 3
2 4
4
3 1
2 3
2 4
4
4 1
2 3
2 4
4
1 2
3 1
3 4
4
2 1
3 2
3 4
4
3 1
3 2
3 4
4
4 1
3 2
3 4
4
1 2
4 1
3 4
4
2 1
4 2
3 4
4
3 1
4 2
3 4
4
4 1
4 2
3 4
5
1 2
1 3
1 4
1 5
5
2 3
1 2
1 4
...

output:

1
3
5
6
5
7
8
7
5
7
9
8
7
8
10
9
8
7
8
7
7
9
10
9
7
6
9
11
12
10
7
10
10
11
9
7
9
9
10
9
7
7
7
7
6
6
9
10
10
9
7
9
12
11
10
9
9
13
12
11
10
7
11
10
10
9
6
8
7
7
7
9
9
9
7
6
10
12
11
10
9
11
14
13
12
11
10
12
11
11
10
9
10
9
9
9
10
11
10
8
7
10
13
12
11
10
12
15
14
13
12
11
13
12
12
11
10
11
10
10
10...

result:

ok 18249 numbers

Test #3:

score: 0
Accepted
time: 46ms
memory: 3452kb

input:

25007
14
11 5
9 10
3 9
4 11
3 4
6 3
1 12
7 1
8 7
6 8
14 6
2 13
2 14
10
10 3
2 4
1 2
7 1
6 5
9 8
7 9
6 7
6 10
12
10 5
7 6
12 7
2 8
1 2
4 1
11 4
10 11
3 10
9 3
9 12
11
11 2
7 5
1 8
4 1
7 9
4 7
3 10
6 3
4 6
4 11
14
6 2
1 5
3 6
12 3
11 10
9 11
1 13
7 1
8 7
12 8
9 12
4 9
4 14
14
2 4
1 2
6 5
7 6
14 8
11 9...

output:

20
21
16
14
23
25
22
18
26
21
16
18
18
16
14
18
13
17
13
16
19
12
19
18
14
18
21
18
21
15
19
30
19
25
21
25
20
13
17
16
19
18
30
17
13
32
16
24
13
29
18
22
14
23
13
24
14
13
16
22
13
18
21
24
29
13
16
18
16
18
22
33
17
19
21
17
29
18
23
14
14
15
15
22
14
16
19
16
17
18
21
13
20
16
14
20
16
14
17
15
...

result:

ok 25007 numbers

Test #4:

score: 0
Accepted
time: 50ms
memory: 3464kb

input:

20000
15
8 1
6 2
3 4
11 5
3 6
7 10
7 13
9 7
3 9
3 14
12 3
8 12
11 8
11 15
15
3 2
7 3
1 5
13 1
14 7
6 9
12 6
13 10
8 12
15 8
4 13
11 4
14 11
14 15
15
13 2
14 3
8 6
13 8
4 9
1 4
7 1
12 10
5 11
7 5
12 7
15 12
13 14
13 15
15
15 2
3 6
14 3
9 12
11 9
5 11
5 13
8 5
7 8
10 7
10 14
1 10
4 1
4 15
15
13 1
5 3
...

output:

28
18
19
17
21
22
23
19
23
18
19
19
18
19
18
19
21
20
24
23
22
17
18
16
18
21
17
17
19
22
20
17
27
18
18
37
20
17
18
21
20
21
18
21
26
22
18
19
18
18
18
25
20
21
17
20
19
21
45
17
18
21
19
18
20
25
19
17
21
22
18
23
27
17
20
23
23
19
18
18
22
24
17
20
27
23
18
18
16
17
30
18
16
19
25
19
19
21
19
19
...

result:

ok 20000 numbers

Test #5:

score: 0
Accepted
time: 69ms
memory: 3512kb

input:

3000
100
14 1
50 2
12 3
30 6
47 14
39 16
57 22
38 23
12 29
19 31
45 19
46 34
26 36
54 26
27 37
67 39
11 40
81 11
25 48
9 25
5 9
20 49
21 50
96 54
42 56
32 58
42 59
67 61
15 63
57 64
7 57
17 7
69 17
52 67
65 69
91 65
44 70
77 44
96 71
77 74
51 75
45 76
47 45
97 77
30 78
28 30
51 28
86 51
99 79
72 80
...

output:

109
102
107
106
103
103
105
106
105
106
103
103
105
105
105
103
103
103
105
104
106
102
101
106
104
103
108
103
103
104
108
106
105
103
104
101
103
104
103
105
106
107
107
103
102
106
102
103
102
103
103
106
107
106
104
105
104
105
103
102
107
106
105
103
105
106
105
104
104
107
104
104
104
110
104
...

result:

ok 3000 numbers

Test #6:

score: 0
Accepted
time: 86ms
memory: 3616kb

input:

300
1000
525 4
24 5
40 7
87 8
512 10
262 14
813 15
920 16
65 17
264 19
263 22
563 25
782 26
836 27
152 29
743 31
697 35
970 38
314 39
524 41
881 42
559 44
363 45
128 48
85 51
980 56
253 57
950 62
65 63
259 67
393 70
789 71
913 72
230 74
428 79
314 81
154 83
292 85
514 86
875 89
496 91
176 92
831 93
...

output:

1002
1006
1004
1003
1002
1004
1003
1008
1004
1004
1003
1013
1010
1003
1006
1004
1008
1002
1002
1002
1005
1005
1003
1004
1004
1004
1004
1007
1002
1016
1002
1002
1002
1007
1006
1002
1005
1007
1002
1002
1004
1002
1005
1004
1002
1004
1004
1004
1012
1004
1005
1001
1004
1005
1005
1003
1005
1003
1006
1004
...

result:

ok 300 numbers

Test #7:

score: 0
Accepted
time: 108ms
memory: 4164kb

input:

30
10000
6821 1
9990 2
5302 3
1666 4
6188 7
2395 8
1809 9
9602 12
5294 15
530 20
5389 21
5706 22
3491 23
8268 27
4172 28
529 40
651 41
5961 44
3518 46
3708 49
1308 50
4979 51
1228 52
3466 55
4275 56
3939 60
7197 63
7788 64
7387 65
1091 66
779 68
7651 71
7211 72
7650 73
6368 76
1175 77
3593 80
3885 8...

output:

10006
10004
10006
10007
10007
10001
10003
10009
10002
10006
10005
10008
10001
10002
10004
10003
10003
10004
10007
10007
10007
10003
10007
10008
10021
10005
10015
10005
10003
10007

result:

ok 30 numbers

Test #8:

score: 0
Accepted
time: 138ms
memory: 12224kb

input:

3
100000
38499 2
74037 14
62566 16
12244 22
7435 23
50004 25
85421 27
99298 29
46772 37
627 44
95358 45
80664 48
93303 51
910 52
35696 53
97637 56
27446 57
82638 59
90514 61
24251 64
34056 66
82616 71
60591 73
95904 74
63214 78
17615 81
97332 82
95666 83
48804 84
35814 85
95944 86
30971 88
84660 89
...

output:

100005
100008
100008

result:

ok 3 number(s): "100005 100008 100008"

Test #9:

score: 0
Accepted
time: 194ms
memory: 29964kb

input:

1
300000
203812 2
251949 3
33092 6
190617 12
259200 13
12637 14
227204 16
170636 19
20596 24
27919 25
192879 26
214547 28
40734 32
223434 35
286662 38
46869 41
76948 48
161483 50
145840 53
99310 55
136689 57
62536 59
135775 64
190846 66
78593 69
38258 71
130241 72
90718 73
290341 75
100531 77
184383...

output:

300003

result:

ok 1 number(s): "300003"

Test #10:

score: 0
Accepted
time: 189ms
memory: 30036kb

input:

1
300000
9994 3
114435 4
12353 10
156766 11
109257 14
159440 15
205944 24
101743 25
81457 26
62123 27
223684 28
207546 29
26268 30
251044 34
31153 37
247131 38
25593 39
156614 40
179607 42
87514 54
151903 56
205384 57
277753 60
15148 63
16798 66
79634 69
7496 73
133288 79
96882 80
82922 81
51268 85
...

output:

300003

result:

ok 1 number(s): "300003"

Test #11:

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

input:

1
300000
20 21
20 19
19 18
21 22
22 23
19 110104
18 17
110104 110105
110104 127193
127193 127194
127193 161908
23 24
18 204614
21 56150
56150 56151
17 16
127194 127195
24 25
23 20860
22 24875
127194 150240
24 7474
17 245694
204614 204615
16 15
16 267316
56151 56152
7474 7475
204615 204616
161908 161...

output:

11165318

result:

ok 1 number(s): "11165318"

Test #12:

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

input:

1
300000
131273 131272
131272 131271
131271 131270
131270 131269
131269 131268
131268 131267
131267 131266
131266 131265
131265 131264
131264 131263
131263 131262
131262 131261
131261 131260
131260 131259
131259 131258
131258 131257
131257 131256
131256 131255
131255 131254
131254 131253
131253 1312...

output:

19659324646

result:

ok 1 number(s): "19659324646"

Test #13:

score: 0
Accepted
time: 107ms
memory: 33516kb

input:

1
300000
100845 100844
100844 100843
100843 100842
100842 100841
100841 100840
100840 100839
100839 100838
100838 100837
100837 100836
100836 100835
100835 100834
100834 100833
100833 100832
100832 100831
100831 100830
100830 100829
100829 100828
100828 100827
100827 100826
100826 100825
100825 1008...

output:

24916563180

result:

ok 1 number(s): "24916563180"

Test #14:

score: 0
Accepted
time: 111ms
memory: 26632kb

input:

1
300000
9 8
9 10
9 55997
9 111984
9 167971
8 7
8 223958
8 233289
8 242620
8 251951
8 261282
10 11
10 9342
10 18673
10 28004
10 37335
10 46666
55997 55998
55997 65329
55997 74660
55997 83991
55997 93322
55997 102653
111984 111985
111984 121316
111984 130647
111984 139978
111984 149309
111984 158640
...

output:

4530793

result:

ok 1 number(s): "4530793"

Test #15:

score: 0
Accepted
time: 106ms
memory: 25392kb

input:

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

output:

899997

result:

ok 1 number(s): "899997"

Test #16:

score: 0
Accepted
time: 131ms
memory: 33516kb

input:

1
300000
394 395
394 1020
394 1645
394 2270
394 2895
394 393
394 3520
394 4145
394 4770
394 5395
394 6020
394 6645
394 7270
394 7895
394 8520
394 9145
394 9770
394 10395
394 11020
394 11645
394 12270
394 12895
394 13520
394 14145
394 14770
394 15395
394 16020
394 16645
394 17270
394 17895
394 18520
...

output:

211762181

result:

ok 1 number(s): "211762181"

Test #17:

score: 0
Accepted
time: 122ms
memory: 28960kb

input:

1
300000
292255 292254
292254 292381
292254 292253
292381 292382
292382 292383
292382 292658
292381 292765
292383 292384
292253 292252
292252 292932
292252 292251
292384 292385
292255 292256
292256 292257
292251 292250
292765 292766
292932 292933
292385 292386
292383 292609
292250 292249
292251 2930...

output:

1276240728

result:

ok 1 number(s): "1276240728"

Test #18:

score: 0
Accepted
time: 138ms
memory: 28536kb

input:

1
300000
23794 23795
23794 23951
23794 24107
23794 24263
23794 24419
23794 24575
23794 24731
23794 24887
23794 25043
23794 25199
23794 25355
23794 25511
23794 23793
23794 73333
23794 73489
23794 73645
23794 73801
23794 73956
23794 74111
23794 74266
23794 74421
23794 74576
23794 74731
23794 74886
237...

output:

178191978

result:

ok 1 number(s): "178191978"

Test #19:

score: 0
Accepted
time: 119ms
memory: 28976kb

input:

1
300000
109144 109145
109144 109143
109143 109142
109143 111777
111777 111778
111778 111779
111778 113053
111779 111780
113053 113054
111779 112624
109145 109146
113053 123773
113054 113055
111777 128342
113055 113056
128342 128343
109145 110696
113056 113057
113057 113058
109142 133284
128342 1292...

output:

1551521044

result:

ok 1 number(s): "1551521044"

Test #20:

score: 0
Accepted
time: 120ms
memory: 30932kb

input:

1
300000
217422 217421
217421 217420
217421 217423
217420 217419
217420 282074
217423 217424
217423 281819
217419 282462
217419 217418
282074 282075
282074 282330
217424 217425
217424 281031
281819 281820
281819 281947
282462 282463
282462 282839
217418 217417
217418 282966
282075 282076
282075 2822...

output:

1680325579

result:

ok 1 number(s): "1680325579"

Test #21:

score: 0
Accepted
time: 119ms
memory: 30524kb

input:

1
300000
79407 79406
79406 79405
79405 79404
79404 79403
79403 79402
79402 79401
79401 79400
79400 79399
79399 79398
79398 79397
79397 79396
79396 79395
79395 79394
79394 79393
79393 79392
79392 79391
79391 79390
79390 79389
79389 79388
79388 79387
79387 79386
79386 79385
79385 79384
79384 79383
793...

output:

1812167990

result:

ok 1 number(s): "1812167990"