Submission #1035212

# Submission time Handle Problem Language Result Execution time Memory
1035212 2024-07-26T06:51:23 Z Halym2007 Strange Device (APIO19_strange_device) C++17
100 / 100
333 ms 69824 KB
/*
Shu soragda biz m-dan x_i we y_i gaytalanyar
m-in tapylshynyn prove shu asakda link dushindiryar
https://codeforces.com/blog/entry/67129?#comment-887900
*/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define sz size()
#define pii pair <ll, ll>
const int N = 1e7 + 5;
#define ll long long
#define pb push_back
vector <pii> v;
ll n, a, b, l[N], r[N];
int main () {
//	freopen ("input.txt", "r", stdin);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> a >> b;
	__int128 m = (__int128)a / __gcd (a, b + 1) * b;	// m - period
	for (int i = 1; i <= n; ++i) {
		cin >> l[i] >> r[i];
	}
	for (int i = 1; i <= n; ++i) {
		if (r[i] - l[i] + 1 >= m) {
			v.pb ({0, m - 1});
			continue;
		}
		if (l[i] % m > r[i] % m) {
			v.pb ({l[i] % m, m - 1});
			v.pb ({0, r[i] % m});
		}
		else {
			v.pb ({l[i] % m, r[i] % m});
		}
	}
	
	sort (v.begin(), v.end());
	ll l1 = v[0].ff, r1 = v[0].ss, jogap = 0;
	for (int i = 1; i < (int)v.sz; ++i) {
		if (v[i].ff <= r1) r1 = max (r1, v[i].ss);
		else if (v[i].ff > r1) {
			jogap += r1 - l1 + 1;
			l1 = v[i].ff; 
			r1 = v[i].ss;
		}
	}
	jogap += r1 - l1 + 1;
	cout << jogap;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 1372 KB Output is correct
3 Correct 3 ms 1372 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1372 KB Output is correct
17 Correct 33 ms 7904 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 215 ms 57796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 286 ms 69748 KB Output is correct
3 Correct 282 ms 69688 KB Output is correct
4 Correct 253 ms 69568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 286 ms 69748 KB Output is correct
3 Correct 282 ms 69688 KB Output is correct
4 Correct 253 ms 69568 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 323 ms 69656 KB Output is correct
7 Correct 261 ms 69824 KB Output is correct
8 Correct 262 ms 69708 KB Output is correct
9 Correct 283 ms 69568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 286 ms 69748 KB Output is correct
3 Correct 282 ms 69688 KB Output is correct
4 Correct 253 ms 69568 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 29 ms 7904 KB Output is correct
7 Correct 30 ms 7888 KB Output is correct
8 Correct 29 ms 7892 KB Output is correct
9 Correct 30 ms 7896 KB Output is correct
10 Correct 28 ms 7888 KB Output is correct
11 Correct 30 ms 7896 KB Output is correct
12 Correct 28 ms 7888 KB Output is correct
13 Correct 30 ms 7884 KB Output is correct
14 Correct 28 ms 7888 KB Output is correct
15 Correct 31 ms 7896 KB Output is correct
16 Correct 32 ms 7888 KB Output is correct
17 Correct 30 ms 7888 KB Output is correct
18 Correct 273 ms 69572 KB Output is correct
19 Correct 302 ms 69568 KB Output is correct
20 Correct 291 ms 69768 KB Output is correct
21 Correct 31 ms 7896 KB Output is correct
22 Correct 28 ms 7896 KB Output is correct
23 Correct 86 ms 26616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 32 ms 7920 KB Output is correct
3 Correct 32 ms 7896 KB Output is correct
4 Correct 310 ms 69624 KB Output is correct
5 Correct 35 ms 7884 KB Output is correct
6 Correct 32 ms 7724 KB Output is correct
7 Correct 36 ms 7888 KB Output is correct
8 Correct 33 ms 7760 KB Output is correct
9 Correct 28 ms 7892 KB Output is correct
10 Correct 28 ms 7884 KB Output is correct
11 Correct 33 ms 7896 KB Output is correct
12 Correct 29 ms 7892 KB Output is correct
13 Correct 32 ms 7864 KB Output is correct
14 Correct 320 ms 69572 KB Output is correct
15 Correct 28 ms 7884 KB Output is correct
16 Correct 275 ms 69584 KB Output is correct
17 Correct 256 ms 69776 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 1372 KB Output is correct
3 Correct 3 ms 1372 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1372 KB Output is correct
17 Correct 33 ms 7904 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 215 ms 57796 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 286 ms 69748 KB Output is correct
31 Correct 282 ms 69688 KB Output is correct
32 Correct 253 ms 69568 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 323 ms 69656 KB Output is correct
35 Correct 261 ms 69824 KB Output is correct
36 Correct 262 ms 69708 KB Output is correct
37 Correct 283 ms 69568 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 29 ms 7904 KB Output is correct
40 Correct 30 ms 7888 KB Output is correct
41 Correct 29 ms 7892 KB Output is correct
42 Correct 30 ms 7896 KB Output is correct
43 Correct 28 ms 7888 KB Output is correct
44 Correct 30 ms 7896 KB Output is correct
45 Correct 28 ms 7888 KB Output is correct
46 Correct 30 ms 7884 KB Output is correct
47 Correct 28 ms 7888 KB Output is correct
48 Correct 31 ms 7896 KB Output is correct
49 Correct 32 ms 7888 KB Output is correct
50 Correct 30 ms 7888 KB Output is correct
51 Correct 273 ms 69572 KB Output is correct
52 Correct 302 ms 69568 KB Output is correct
53 Correct 291 ms 69768 KB Output is correct
54 Correct 31 ms 7896 KB Output is correct
55 Correct 28 ms 7896 KB Output is correct
56 Correct 86 ms 26616 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 32 ms 7920 KB Output is correct
59 Correct 32 ms 7896 KB Output is correct
60 Correct 310 ms 69624 KB Output is correct
61 Correct 35 ms 7884 KB Output is correct
62 Correct 32 ms 7724 KB Output is correct
63 Correct 36 ms 7888 KB Output is correct
64 Correct 33 ms 7760 KB Output is correct
65 Correct 28 ms 7892 KB Output is correct
66 Correct 28 ms 7884 KB Output is correct
67 Correct 33 ms 7896 KB Output is correct
68 Correct 29 ms 7892 KB Output is correct
69 Correct 32 ms 7864 KB Output is correct
70 Correct 320 ms 69572 KB Output is correct
71 Correct 28 ms 7884 KB Output is correct
72 Correct 275 ms 69584 KB Output is correct
73 Correct 256 ms 69776 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 1 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 3 ms 1372 KB Output is correct
80 Correct 313 ms 69752 KB Output is correct
81 Correct 333 ms 69748 KB Output is correct
82 Correct 306 ms 69776 KB Output is correct
83 Correct 301 ms 69612 KB Output is correct
84 Correct 331 ms 69568 KB Output is correct
85 Correct 294 ms 69568 KB Output is correct
86 Correct 86 ms 26548 KB Output is correct
87 Correct 0 ms 344 KB Output is correct