QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#536452#4571. Even SplitLavineAC ✓19ms12528kbC++236.9kb2024-08-29 13:05:592024-08-29 13:06:00

Judging History

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

  • [2024-08-29 13:06:00]
  • 评测
  • 测评结果:AC
  • 用时:19ms
  • 内存:12528kb
  • [2024-08-29 13:05:59]
  • 提交

answer

#include <stdio.h>
#include <bits/stdc++.h>
#include <cstdint>
#include <ctime>
#include <functional>
#include <limits>
#include <random>
#include <string_view>
#include <type_traits>
#include <utility>

#ifdef ROOM_311
#	ifndef OLYMP_DEBUG
#		define OLYMP_DEBUG
#	endif
#else
#	define OLYMP_NDEBUG
#endif

//#include <olymp/geometry/point.h>
//#include <olymp/numeric/epsilonized.h>
//#include <olymp/numeric/modular.h>

#ifdef OLYMP_DEBUG
#ifndef OLYMP_PRINT_EXEC_TIME
#define OLYMP_PRINT_EXEC_TIME 1
#endif
#endif

namespace olymp::utils {

inline clock_t &get_exec_clock_storage()
{
	static clock_t exec_clock_storage;
	return exec_clock_storage;
}

inline clock_t &get_step_clock_storage()
{
	static clock_t step_clock_storage;
	return step_clock_storage;
}

inline void init_exec_time()
{
	auto &t0e = get_exec_clock_storage();
	auto &t0s = get_step_clock_storage();
	t0e = t0s = clock();
}

inline double get_exec_time_ms()
{
	const auto &t0 = get_exec_clock_storage();
	auto t1 = clock();
	return (t1 - t0) * 1000.0 / CLOCKS_PER_SEC;
}

inline double get_step_time_ms()
{
	auto &t0 = get_step_clock_storage();
	auto t1 = clock();
	double result = (t1 - t0) * 1000.0 / CLOCKS_PER_SEC;
	t0 = t1;
	return result;
}

inline void print_step_time([[maybe_unused]] std::string_view step_name = {})
{
#ifdef OLYMP_PRINT_EXEC_TIME
#if OLYMP_PRINT_EXEC_TIME
	if (step_name.empty()) {
		fprintf(stderr, "Step time = %0.0lf ms\n", get_step_time_ms());
	}
	else {
		fprintf(stderr, "Step '");
		fwrite(step_name.data(), 1, step_name.size(), stderr);
		fprintf(stderr, "' time = %0.0lf ms\n", get_step_time_ms());
	}
#endif
#endif
}

inline void print_exec_time()
{
#ifdef OLYMP_PRINT_EXEC_TIME
#if OLYMP_PRINT_EXEC_TIME
	fprintf(stderr, "Execution time = %0.0lf ms\n", get_exec_time_ms());
#endif
#endif
}

}  // namespace olymp::utils

namespace olymp::utils {

class rnd_t {
public:
	template<typename int_t = int>
	int_t get()
	{
		if constexpr (gen_.max() >= std::numeric_limits<int_t>::max()) {
			return gen_() & std::numeric_limits<int_t>::max();
		}
		else {
			std::uniform_int_distribution<int_t> d(0, std::numeric_limits<int_t>::max());
			return d(gen_);
		}
	}
	
	template<typename int_t = int>
	int_t operator () ()
	{
		return get<int_t>();
	}
	
	template<typename int_t>
	int_t operator () (int_t n)
	{
		std::uniform_int_distribution<int_t> d(0, n - 1);
		return d(gen_);
	}
	
	template<typename int_l_t, typename int_r_t>
	std::common_type_t<int_l_t, int_r_t> operator () (int_l_t l, int_r_t r)
	{
		std::uniform_int_distribution<std::common_type_t<int_l_t, int_r_t>> d(l, r);
		return d(gen_);
	}
	
	template<typename int_t>
	void seed(int_t &&value)
	{
		gen_.seed(std::forward<int_t>(value));
	}
	
	std::mt19937 &gen() { return gen_; }
	
	template<typename it_t>
	void shuffle(it_t b, it_t e)
	{
		std::shuffle(b, e, gen());
	}
	
	template<typename int_t>
	void discard(int_t n)
	{
		gen_.discard(n);
	}

private:
	std::mt19937 gen_{311311311};
};

#ifdef OLYMP_USE_MT
thread_local
#endif
static inline rnd_t rnd;

}  // namespace olymp::utils

namespace olymp::utils {

template<typename a_t, typename b_t, typename less_t = std::less<a_t>>
inline constexpr std::enable_if_t<
	std::is_same_v<std::common_type_t<a_t, std::decay_t<b_t>>, a_t>,
	bool
> uin(a_t &a, b_t &&b, less_t &&less = less_t())
{
	return less(b, a) ? a = std::forward<b_t>(b), true : false;
}

template<typename a_t, typename b_t, typename less_t = std::less<a_t>>
inline constexpr std::enable_if_t<
	std::is_same_v<std::common_type_t<a_t, std::decay_t<b_t>>, a_t>,
	bool
> uax(a_t &a, b_t &&b, less_t &&less = less_t())
{
	return less(a, b) ? a = std::forward<b_t>(b), true : false;
}

}  // namespace olymp::utils

#define clr(x) memset((x), 0, sizeof(x))
#define all(x) std::begin(x), std::end(x)
#define pb push_back
#define mp make_pair
#define sz size()
#define For(i, st, en) for(std::make_signed_t<std::decay_t<decltype(en)>> i=(st); i<=static_cast<std::make_signed_t<std::decay_t<decltype(en)>>>(en); ++i)
#define Ford(i, st, en) for(std::make_signed_t<std::decay_t<decltype(st)>> i=(st); i>=static_cast<std::make_signed_t<std::decay_t<decltype(st)>>>(en); --i)
#define forn(i, n) for(std::make_signed_t<std::decay_t<decltype(n)>> i=0; i<static_cast<std::make_signed_t<std::decay_t<decltype(n)>>>(n); ++i)
#define ford(i, n) for(auto i=static_cast<std::make_signed_t<std::decay_t<decltype(n)>>>(n)-1; i>=0; --i)

using olymp::utils::print_step_time;
using olymp::utils::print_exec_time;
using olymp::utils::rnd;

template <class _T> inline _T sqr(const _T &x) { return x * x; }

namespace olymp {

__attribute__((constructor)) inline void init_main()
{
	utils::init_exec_time();
}

__attribute__((destructor)) inline void fini_main()
{
	utils::print_exec_time();
}

}  // namespace olymp

using namespace olymp;
using namespace std;
using utils::uax;
using utils::uin;

// Types
using ld = long double;
//using ed = numeric::epsilonized<ld, 9>;
using i64 = long long;
using u64 = unsigned long long;
//using tp = geometry::point<int>;

// Constants
const ld PI = 3.1415926535897932384626433832795L;
const ld EPS = 1e-9;

//const int MOD = 1000000007;
//const int MOD = 998244353;
//using mint = numeric::modular<MOD>;

int n, m, mi, ma;
int a[1024000];
int b[1024000];
array<int, 2> d[1024000];
int ans[1024000];

bool check_mi(int l)
{
	int r = 0;
	forn(i, n + 1)
	{
		if (r > a[i]) return false;
		r = max(a[i], r + l);
	}
	return true;
}

int calc_mi()
{
	int mi = 1;
	int ma = m;
	while (mi < ma)
	{
		int q = (mi + ma + 1) / 2;
		if (check_mi(q)) mi = q;
		else ma = q - 1;
	}
	return mi;
}

bool check_ma(int l)
{
	int r = 0;
	forn(i, n)
	{
		r = min(r + l, a[i + 1]);
		if (r < a[i]) return false;
	}
	return r == m;
}

int calc_ma()
{
	int mi = 1;
	int ma = m;
	while (mi < ma)
	{
		int q = (mi + ma) / 2;
		if (check_ma(q)) ma = q;
		else mi = q + 1;
	}
	return mi;
}

int main()
{
#ifdef ROOM_311
	freopen("input.txt", "rt", stdin);
#endif
	
	scanf("%d%d", &m, &n);
	forn(i, n)
	{
		scanf("%d", &a[i]);
	}
	a[n] = m;
	int mi = calc_mi();
	int ma = calc_ma();
	
	d[0] = {0, 0};
	forn(i, n)
	{
		int l = d[i][0];
		int r = d[i][1];
		d[i + 1][0] = max(a[i], l + mi);
		d[i + 1][1] = min(a[i + 1], r + ma);
	}
	assert(d[n][0] <= m && m == d[n][1]);
	ans[n] = m;
	int t = m;
	ford(i, n)
	{
		assert(d[i + 1][0] <= t && t <= d[i + 1][1]);
		int x = mi;
		uax(x, t - d[i][1]);
		assert(x <= ma);
		assert(x <= t - d[i][0]);
		int z = t - x;
		assert(d[i][0] <= z && z <= d[i][1]);
//		For(k, mi, ma)
//		{
//			int z = t - k;
//			if (d[i][0] <= z && z <= d[i][1])
//			{
				ans[i] = z;
				t = z;
//				break;
//			}
//		}
	}
	
	forn(i, n)
	{
		printf("%d %d\n", ans[i], ans[i + 1]);
	}
	
	return 0;
}

詳細信息

Test #1:

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

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: 1ms
memory: 8060kb

input:

10 2
1 2

output:

0 2
2 10

result:

ok Minimal imbalance is 6

Test #3:

score: 0
Accepted
time: 1ms
memory: 8016kb

input:

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

output:

0 25
25 28
28 31
31 34
34 40
40 43
43 46
46 49
49 68
68 100

result:

ok Minimal imbalance is 29

Test #4:

score: 0
Accepted
time: 1ms
memory: 7996kb

input:

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

output:

0 21
21 42
42 58
58 66
66 70
70 74
74 78
78 84
84 88
88 100

result:

ok Minimal imbalance is 17

Test #5:

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

input:

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

output:

0 12
12 18
18 24
24 30
30 44
44 55
55 64
64 78
78 86
86 100

result:

ok Minimal imbalance is 8

Test #6:

score: 0
Accepted
time: 1ms
memory: 7920kb

input:

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

output:

0 23
23 46
46 55
55 59
59 65
65 72
72 76
76 80
80 90
90 100

result:

ok Minimal imbalance is 19

Test #7:

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

input:

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

output:

0 5
5 20
20 31
31 36
36 42
42 57
57 72
72 84
84 91
91 100

result:

ok Minimal imbalance is 10

Test #8:

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

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 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
185557 ...

result:

ok Minimal imbalance is 58553

Test #9:

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

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 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
250672 259032...

result:

ok Minimal imbalance is 61981

Test #10:

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

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 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 305639
305639 ...

result:

ok Minimal imbalance is 71459

Test #11:

score: 0
Accepted
time: 12ms
memory: 8304kb

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 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
268918 2702...

result:

ok Minimal imbalance is 69674

Test #12:

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

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 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 186878
18687...

result:

ok Minimal imbalance is 53927

Test #13:

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

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 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
101 ...

result:

ok Minimal imbalance is 7

Test #14:

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

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 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 92
92 ...

result:

ok Minimal imbalance is 8

Test #15:

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

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 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
106 10...

result:

ok Minimal imbalance is 9

Test #16:

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

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 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
91 ...

result:

ok Minimal imbalance is 7

Test #17:

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

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 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 91
9...

result:

ok Minimal imbalance is 9

Test #18:

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

input:

2 1
1

output:

0 2

result:

ok Minimal imbalance is 0

Test #19:

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

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: 19ms
memory: 8444kb

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: 15ms
memory: 12284kb

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: 16ms
memory: 12340kb

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 11935
11935 23870
23870 35805
35805 47740
47740 59675
59675 71610
71610 83545
83545 95480
95480 107415
107415 119350
119350 131285
131285 143220
143220 155155
155155 167090
167090 179025
179025 190960
190960 202895
202895 214830
214830 226765
226765 238700
238700 250635
250635 262570
262570 274505...

result:

ok Minimal imbalance is 3871

Test #23:

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

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 4240
4240 8447
8447 12654
12654 16861
16861 21068
21068 25275
25275 29482
29482 33689
33689 37896
37896 42103
42103 46310
46310 50517
50517 54724
54724 58931
58931 63138
63138 67345
67345 71552
71552 75759
75759 79966
79966 84173
84173 88380
88380 92587
92587 96794
96794 101001
101001 105208
10520...

result:

ok Minimal imbalance is 11601