QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#227622#6674. Connected Intervalsluanmenglei#AC ✓155ms33980kbC++173.6kb2023-10-27 19:59:572023-10-27 19:59:58

Judging History

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

  • [2023-10-27 19:59:58]
  • 评测
  • 测评结果:AC
  • 用时:155ms
  • 内存:33980kb
  • [2023-10-27 19:59:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
bool stB;
namespace SOL {

void debug(const char *msg, ...) {
#ifdef CLESIP
    va_list arg;
    static char pbString[512];
    va_start(arg,msg);
    vsprintf(pbString,msg,arg);
    cerr << "[DEBUG] " << pbString << "\n";
    va_end(arg);
#endif    
}

#define PASSED cerr << "PASSED " << __FUNCTION__ << " #" << __LINE__ << "\n";

using i64 = long long;
using i128 = __int128_t;
template <typename T, typename L> void chkmax(T &x, L y) { if (x < y) x = y; }
template <typename T, typename L> void chkmin(T &x, L y) { if (y < x) x = y; }

const int N = 3e5 + 10;

namespace LazySegmentTree {
	const int SEG_SIZE = N * 4;
	template<typename Node, typename Tag>
	struct LazyTagSegTree {
		#define lc (x * 2)
		#define rc (x * 2 + 1)
		#define mid ((l + r) >> 1)

		Node dat[SEG_SIZE];
		Tag tag[SEG_SIZE];

		void pull(int x) {
			dat[x] = dat[lc] + dat[rc];
		}

		void apply(int x, const Tag &t, int sze) {
			dat[x].apply(t, sze);
			tag[x].apply(t);
		}

		void push(int x, int l, int r) {
			if (tag[x]) {
				apply(lc, tag[x], mid - l + 1);
				apply(rc, tag[x], r - mid);
				tag[x].clear();
			}
		}

		void build(int x, int l, int r) {
			tag[x].clear();
			if (l == r) {
				dat[x].init(l);
				return;
			}
			build(lc, l, mid);
			build(rc, mid + 1, r);
			pull(x);
		}

		Node query(int x, int l, int r, int ql, int qr) {
			if (ql <= l && r <= qr) 
				return dat[x];
			push(x, l, r);
			if (ql <= mid && mid < qr)
				return query(lc, l, mid, ql, qr) + query(rc, mid + 1, r, ql, qr);
			else if (ql <= mid)
				return query(lc, l, mid, ql, qr);
			else
				return query(rc, mid + 1, r, ql, qr);
		}

		void modify(int x, int l, int r, int ql, int qr, const Tag &t) {
			if (ql > qr)
				return;
			if (ql <= l && r <= qr) 
				return apply(x, t, r - l + 1);
			push(x, l, r);
			if (ql <= mid)
				modify(lc, l, mid, ql, qr, t);
			if (mid < qr)
				modify(rc, mid + 1, r, ql, qr, t);
			pull(x);
		}

		void change(int x, int l, int r, int pos, const Node &k) {
			if (l == r)
				return dat[x] = k, void();
			push(x, l, r);
			if (pos <= mid)
				change(lc, l, mid, pos, k);
			else
				change(rc, mid + 1, r, pos, k);
			pull(x);
		} 

		#undef lc
		#undef rc
		#undef mid
	};
}

struct Tag {
	int add;

	void apply(const Tag &o) {
		add = add + o.add;
	}

	void clear() {
		add = 0;
	}

	operator bool () const {
		return add;
	}
};

struct Node {
	int mn, cnt;

	void init(int p) {
		mn = 0, cnt = 1;		
	}

	void apply(const Tag &o, int size) {
		mn += o.add;
	}
};

Node operator + (const Node &lhs, const Node &rhs) {
	if (lhs.mn == rhs.mn)
		return { lhs.mn, lhs.cnt + rhs.cnt };
	if (lhs.mn < rhs.mn)
		return lhs;
	else
		return rhs;
}

LazySegmentTree::LazyTagSegTree<Node, Tag> segt; 
int n;
vector<int> G[N];

void ___solve() {
	
	cin >> n;
	for (int i = 1; i <= n; i ++)
		G[i].clear();
	for (int i = 1, x, y; i < n; i ++) {
		cin >> x >> y;
		if (x > y)
			swap(x, y);
		G[y].push_back(x);
	}
	segt.build(1, 1, n);
	i64 ans = 0;
	for (int i = 1; i <= n; i ++) {
		segt.modify(1, 1, n, 1, i, { 1 });
		for (int j : G[i])
			segt.modify(1, 1, n, 1, j, { -1 });
		auto res = segt.query(1, 1, n, 1, i);
		if (res.mn == 1) {
			ans += res.cnt;
		}
	}
	cout << ans << "\n";
}

}
bool edB;
signed main() {
	// cerr << "Memory: " << (&stB - &edB) / 1024.0 / 1024.0 << "MB\n";
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int tt; cin >> tt;
	while (tt --) 
		SOL::___solve();
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 13ms
memory: 13316kb

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: 39ms
memory: 12928kb

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: 40ms
memory: 14088kb

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: 49ms
memory: 13084kb

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: 80ms
memory: 14152kb

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: 89ms
memory: 14756kb

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: 131ms
memory: 18428kb

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: 154ms
memory: 30072kb

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: 155ms
memory: 30076kb

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: 138ms
memory: 33592kb

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: 121ms
memory: 33504kb

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: 102ms
memory: 33672kb

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: 108ms
memory: 33596kb

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: 93ms
memory: 33596kb

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: 123ms
memory: 33596kb

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: 97ms
memory: 33516kb

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: 115ms
memory: 33596kb

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: 110ms
memory: 33980kb

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: 108ms
memory: 33520kb

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: 105ms
memory: 33468kb

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"