QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#536447#4571. Even SplitLavineAC ✓20ms5508kbC++231.7kb2024-08-29 12:57:312024-08-29 12:57:32

Judging History

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

  • [2024-08-29 12:57:32]
  • 评测
  • 测评结果:AC
  • 用时:20ms
  • 内存:5508kb
  • [2024-08-29 12:57:31]
  • 提交

answer

#include <cstdio>
#include <algorithm>
#include <utility>
#include <bits/stdc++.h>
using namespace std ;
using namespace std;
typedef pair<int, int> pii;
constexpr int MAXN = 100'005;

int v[MAXN];
pii segs[MAXN];
int ans[MAXN];

int main()
{
	int len, n;
	scanf("%d %d", &len, &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &v[i]);
	v[n] = len;

	int minlen;
	{
		const auto is_min_ok = [len, n](int cmin) -> bool
		{
			int start = 0;
			for (int i = 0; i < n; i++)
			{
				if (start > v[i])
					return false;
				start = max(start + cmin, v[i]);
			}
			return start <= len;
		};

		int left = 1, right = len + 1;
		while (left + 1 != right)
		{
			int m = (left + right) / 2;
			if (is_min_ok(m))
				left = m;
			else
				right = m;
		}
		minlen = left;
	}

	int maxlen;
	{
		const auto is_max_ok = [len, n](int cmax) -> bool
		{
			int start = 0;
			for (int i = 0; i < n; i++)
			{
				if (start + cmax < v[i])
					return false;
				start = min(start + cmax, v[i + 1]);
			}
			return start == len;
		};

		int left = 0, right = len;
		while (left + 1 != right)
		{
			int m = (left + right) / 2;
			if (is_max_ok(m))
				right = m;
			else
				left = m;
		}
		maxlen = right;
	}

	segs[0] = {0, 0};
	for (int i = 0; i < n; i++)
	{
		auto &[start, end] = segs[i];
		start = max(start, v[i] - maxlen);
		end = min(end, v[i]);
		segs[i + 1] = {max(start + minlen, v[i]), end + maxlen};
	}
    assert(segs[n].second>=len);
	ans[n] = len;
	for (int i = n - 1; i >= 0; i--)
		ans[i] = max(segs[i].first, ans[i + 1] - maxlen);

	for (int i = 0; i < n; i++)
		printf("%d %d\n", ans[i], ans[i + 1]);
	return 0;
}

详细

Test #1:

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

input:

6 3
1 3 5

output:

0 2
2 4
4 6

result:

ok Minimal imbalance is 0

Test #2:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

10 2
1 2

output:

0 2
2 10

result:

ok Minimal imbalance is 6

Test #3:

score: 0
Accepted
time: 0ms
memory: 3888kb

input:

100 10
14 26 29 31 34 42 44 48 49 68

output:

0 14
14 26
26 29
29 32
32 35
35 42
42 45
45 48
48 68
68 100

result:

ok Minimal imbalance is 29

Test #4:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

100 10
3 42 45 58 69 73 75 78 84 88

output:

0 21
21 42
42 46
46 58
58 69
69 73
73 77
77 81
81 85
85 100

result:

ok Minimal imbalance is 17

Test #5:

score: 0
Accepted
time: 0ms
memory: 3956kb

input:

100 10
12 15 24 25 30 45 55 64 80 86

output:

0 12
12 18
18 24
24 30
30 36
36 45
45 58
58 72
72 86
86 100

result:

ok Minimal imbalance is 8

Test #6:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

100 10
10 46 50 57 59 65 76 79 80 90

output:

0 23
23 46
46 50
50 57
57 61
61 65
65 76
76 80
80 84
84 100

result:

ok Minimal imbalance is 19

Test #7:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

100 10
3 5 23 34 36 42 72 81 84 91

output:

0 5
5 10
10 23
23 34
34 42
42 57
57 72
72 81
81 86
86 100

result:

ok Minimal imbalance is 10

Test #8:

score: 0
Accepted
time: 19ms
memory: 5420kb

input:

1000000000 100000
234 521 2233 5010 10213 15298 22181 29569 37404 41370 46544 52606 58851 73956 74520 84776 102335 111406 140442 143688 161164 166404 166924 167716 185557 194472 213634 230507 241622 244806 303238 320282 328153 335228 339419 348046 353158 357866 369691 377344 386277 402535 409037 417...

output:

0 234
234 521
521 2233
2233 5010
5010 10213
10213 15298
15298 22181
22181 29569
29569 37404
37404 41370
41370 46544
46544 52606
52606 58851
58851 73956
73956 74520
74520 84776
84776 102335
102335 111406
111406 140442
140442 143688
143688 161164
161164 166404
166404 166924
166924 167716
167716 185557...

result:

ok Minimal imbalance is 58553

Test #9:

score: 0
Accepted
time: 20ms
memory: 5420kb

input:

1000000000 100000
9821 14877 29979 35144 54431 56557 59891 72599 75587 121025 122887 131740 134087 139909 173981 174231 204091 207393 215446 224891 231631 234220 250672 259032 262950 267369 273374 273704 277250 291380 313014 315589 320121 338235 340357 351633 353626 362050 374468 376865 414050 41502...

output:

0 9821
9821 14877
14877 29979
29979 35144
35144 54431
54431 56557
56557 59891
59891 72599
72599 75587
75587 121025
121025 122887
122887 131740
131740 134087
134087 139909
139909 173981
173981 174231
174231 204091
204091 207393
207393 215446
215446 224891
224891 231631
231631 234220
234220 250672
250...

result:

ok Minimal imbalance is 61981

Test #10:

score: 0
Accepted
time: 19ms
memory: 5440kb

input:

1000000000 100000
4042 5042 7422 12401 15821 25327 35801 49225 68723 70197 83123 121581 133929 155017 185876 197018 199980 207705 210442 216704 276702 277043 279595 305639 313551 344704 348884 360171 362803 370412 371572 372244 394028 418234 431550 435436 436500 436512 443397 445171 454725 459496 46...

output:

0 4042
4042 5042
5042 7422
7422 12401
12401 15821
15821 25327
25327 35801
35801 49225
49225 68723
68723 70197
70197 83123
83123 121581
121581 133929
133929 155017
155017 185876
185876 197018
197018 199980
199980 207705
207705 210442
210442 216704
216704 276702
276702 277043
277043 279595
279595 3056...

result:

ok Minimal imbalance is 71459

Test #11:

score: 0
Accepted
time: 19ms
memory: 5504kb

input:

1000000000 100000
43366 52388 59798 64732 83545 90296 93651 96518 108948 116125 117723 136287 142824 148549 150819 166180 212247 219196 232566 240175 245719 249847 268918 270244 274579 280579 281630 287075 288837 310333 352501 379088 408527 420992 423438 433780 441930 445186 461742 481610 483437 501...

output:

0 43366
43366 52388
52388 59798
59798 64732
64732 83545
83545 90296
90296 93651
93651 96518
96518 108948
108948 116125
116125 117723
117723 136287
136287 142824
142824 148549
148549 150819
150819 166180
166180 212247
212247 219196
219196 232566
232566 240175
240175 245719
245719 249847
249847 268918...

result:

ok Minimal imbalance is 69674

Test #12:

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

input:

1000000000 100000
859 16443 26041 39093 40232 42927 57255 62982 65646 65743 82046 98650 105881 118156 137616 138932 152665 153210 157351 158576 162315 174381 176862 186878 202710 207484 209207 215144 227450 240723 245533 254405 258204 258230 264973 272941 277526 285536 286094 292720 324584 324887 33...

output:

0 859
859 16443
16443 26041
26041 39093
39093 40232
40232 42927
42927 57255
57255 62982
62982 65646
65646 65743
65743 82046
82046 98650
98650 105881
105881 118156
118156 137616
137616 138932
138932 152665
152665 153210
153210 157351
157351 158576
158576 162315
162315 174381
174381 176862
176862 1868...

result:

ok Minimal imbalance is 53927

Test #13:

score: 0
Accepted
time: 16ms
memory: 5500kb

input:

200000 100000
1 2 5 9 13 14 15 18 20 22 23 25 27 28 31 35 37 41 45 46 48 49 51 56 57 60 61 62 63 65 66 67 70 71 72 75 77 78 80 81 82 85 86 91 92 93 95 97 99 100 101 103 104 106 107 108 109 111 112 114 115 117 118 119 120 121 125 127 128 129 130 133 134 135 138 139 140 141 142 147 148 149 150 153 154...

output:

0 1
1 2
2 5
5 9
9 13
13 14
14 15
15 18
18 20
20 22
22 23
23 25
25 27
27 28
28 31
31 35
35 37
37 41
41 45
45 46
46 48
48 49
49 51
51 56
56 57
57 60
60 61
61 62
62 63
63 65
65 66
66 67
67 70
70 71
71 72
72 75
75 77
77 78
78 80
80 81
81 82
82 85
85 86
86 91
91 92
92 93
93 95
95 97
97 99
99 100
100 101
...

result:

ok Minimal imbalance is 7

Test #14:

score: 0
Accepted
time: 11ms
memory: 5312kb

input:

200000 100000
9 10 11 13 15 17 19 20 21 22 23 27 28 29 31 32 33 34 37 39 42 43 44 46 47 50 51 52 54 56 58 59 61 62 64 65 67 68 70 71 72 74 75 76 80 82 85 87 88 89 92 93 94 95 97 100 101 104 105 106 107 109 110 111 112 113 114 116 117 122 124 125 128 129 130 133 136 137 139 145 146 147 148 153 157 15...

output:

0 9
9 10
10 11
11 13
13 15
15 17
17 19
19 20
20 21
21 22
22 23
23 27
27 28
28 29
29 31
31 32
32 33
33 34
34 37
37 39
39 42
42 43
43 44
44 46
46 47
47 50
50 51
51 52
52 54
54 56
56 58
58 59
59 61
61 62
62 64
64 65
65 67
67 68
68 70
70 71
71 72
72 74
74 75
75 76
76 80
80 82
82 85
85 87
87 88
88 89
89 ...

result:

ok Minimal imbalance is 8

Test #15:

score: 0
Accepted
time: 16ms
memory: 5504kb

input:

200000 100000
3 4 6 7 12 13 14 16 17 19 20 22 24 28 29 30 32 37 38 39 40 41 43 44 45 48 52 53 54 62 64 67 68 69 70 73 75 79 80 86 89 90 91 92 95 99 100 101 102 106 107 109 110 111 112 113 114 115 119 126 128 129 130 131 132 133 134 135 136 137 139 140 142 145 148 149 151 152 153 154 155 156 157 162 ...

output:

0 3
3 4
4 6
6 7
7 12
12 13
13 14
14 16
16 17
17 19
19 20
20 22
22 24
24 28
28 29
29 30
30 32
32 37
37 38
38 39
39 40
40 41
41 43
43 44
44 45
45 48
48 52
52 53
53 54
54 62
62 64
64 67
67 68
68 69
69 70
70 73
73 75
75 79
79 80
80 86
86 89
89 90
90 91
91 92
92 95
95 99
99 100
100 101
101 102
102 106
10...

result:

ok Minimal imbalance is 9

Test #16:

score: 0
Accepted
time: 16ms
memory: 5508kb

input:

200000 100000
1 2 4 6 9 10 11 13 14 15 17 18 21 22 23 25 26 27 30 31 34 37 38 40 44 48 49 50 52 54 56 59 60 62 63 64 66 68 69 70 73 74 75 76 77 78 79 80 81 82 85 91 92 93 96 97 99 103 104 105 108 111 113 114 118 119 120 122 125 126 128 129 132 134 135 136 137 138 141 142 143 144 145 146 147 148 149 ...

output:

0 1
1 2
2 4
4 6
6 9
9 10
10 11
11 13
13 14
14 15
15 17
17 18
18 21
21 22
22 23
23 25
25 26
26 27
27 30
30 31
31 34
34 37
37 38
38 40
40 44
44 48
48 49
49 50
50 52
52 54
54 56
56 59
59 60
60 62
62 63
63 64
64 66
66 68
68 69
69 70
70 73
73 74
74 75
75 76
76 77
77 78
78 79
79 80
80 81
81 82
82 85
85 91...

result:

ok Minimal imbalance is 7

Test #17:

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

input:

200000 100000
3 6 7 9 10 11 13 16 17 19 21 22 23 24 26 27 29 33 36 39 40 41 42 43 44 45 46 48 49 51 52 57 58 60 61 64 65 66 67 70 71 73 75 76 79 81 82 84 85 89 90 91 94 95 96 97 98 101 103 104 105 106 111 113 120 124 126 132 133 135 140 141 144 146 149 150 151 154 155 156 157 158 161 162 164 168 170...

output:

0 3
3 6
6 7
7 9
9 10
10 11
11 13
13 16
16 17
17 19
19 21
21 22
22 23
23 24
24 26
26 27
27 29
29 33
33 36
36 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 48
48 49
49 51
51 52
52 57
57 58
58 60
60 61
61 64
64 65
65 66
66 67
67 70
70 71
71 73
73 75
75 76
76 79
79 81
81 82
82 84
84 85
85 89
89 90
90 ...

result:

ok Minimal imbalance is 9

Test #18:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

2 1
1

output:

0 2

result:

ok Minimal imbalance is 0

Test #19:

score: 0
Accepted
time: 19ms
memory: 5504kb

input:

999934479 100000
1347 7016 13646 16374 19258 25729 29070 35355 41999 43931 48141 53449 57471 62160 70011 71302 76850 80099 87156 90531 94830 100986 107127 109682 116557 117400 122935 126876 133002 136999 141021 145873 153443 157968 159027 164692 168204 172909 178889 182471 190653 196019 196899 20187...

output:

0 4670
4670 9340
9340 14010
14010 18680
18680 23350
23350 28020
28020 32690
32690 37360
37360 42030
42030 46700
46700 51370
51370 56040
56040 60710
60710 65380
65380 70050
70050 74720
74720 79390
79390 84060
84060 88730
88730 93400
93400 98070
98070 102740
102740 107410
107410 112080
112080 116750
1...

result:

ok Minimal imbalance is 10703

Test #20:

score: 0
Accepted
time: 11ms
memory: 5504kb

input:

999938652 100000
10872 12876 29327 39905 54962 63774 68095 78723 92667 103162 118715 125653 139032 153559 161457 172997 187452 196302 207806 212033 227157 235734 252930 255857 273858 283859 294767 305386 314251 327619 340534 351036 361521 370216 387250 397101 405113 413617 430570 435277 453829 45923...

output:

0 11095
11095 22190
22190 33285
33285 44380
44380 55475
55475 66570
66570 77665
77665 88760
88760 99855
99855 110950
110950 122045
122045 133140
133140 144235
144235 155330
155330 166425
166425 177520
177520 188615
188615 199710
199710 210805
210805 221900
221900 232995
232995 244090
244090 255185
2...

result:

ok Minimal imbalance is 2747

Test #21:

score: 0
Accepted
time: 9ms
memory: 5400kb

input:

999927360 100000
2777 15328 31200 39979 52649 68523 69247 81294 94805 108866 125092 131743 137506 150523 167769 178287 191991 200932 213245 219533 237155 241318 253312 270831 281458 288670 303989 316622 326818 337655 345316 354786 372518 382283 399600 408565 413618 428562 435378 453307 460485 474419...

output:

0 11422
11422 22844
22844 34266
34266 45688
45688 57110
57110 68532
68532 79954
79954 91376
91376 102798
102798 114220
114220 125642
125642 137064
137064 148486
148486 159908
159908 171330
171330 182752
182752 194174
194174 205596
205596 217018
217018 228440
228440 239862
239862 251284
251284 262706...

result:

ok Minimal imbalance is 2840

Test #22:

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

input:

999973226 100000
8238 22946 33688 42374 55242 66863 81086 93866 98195 113105 122089 138236 144142 163223 168825 180021 193238 211332 222913 231489 243095 261038 270761 282786 290131 298656 319277 329899 341441 348632 367549 370885 388745 403498 416443 426637 439241 451995 462335 473876 479891 498950...

output:

0 11923
11923 23858
23858 35793
35793 47728
47728 59663
59663 71598
71598 83533
83533 95468
95468 107403
107403 119338
119338 131273
131273 143208
143208 155143
155143 167078
167078 179013
179013 190948
190948 202883
202883 214818
214818 226753
226753 238688
238688 250623
250623 262558
262558 274493...

result:

ok Minimal imbalance is 3871

Test #23:

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

input:

999949531 100000
743 6197 10329 16172 19309 23132 26683 33598 37622 39742 43421 48654 51693 57257 59690 65723 69262 74479 77169 82025 87674 89494 95109 97377 102998 107176 111805 117071 121947 123348 128149 132227 136488 142523 144092 150001 152892 156515 163460 165985 168396 173464 179654 181215 18...

output:

0 4207
4207 8414
8414 12621
12621 16828
16828 21035
21035 25242
25242 29449
29449 33656
33656 37863
37863 42070
42070 46277
46277 50484
50484 54691
54691 58898
58898 63105
63105 67312
67312 71519
71519 75726
75726 79933
79933 84140
84140 88347
88347 92554
92554 96761
96761 100968
100968 105175
10517...

result:

ok Minimal imbalance is 11601