#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>
using namespace std;
// using namespace __gnu_cxx;
// using namespace __gnu_pbds;
void Hollwo_Pelw();
signed main(){
#ifndef hollwo_pelw_local
if (fopen(".inp", "r"))
assert(freopen(".inp", "r", stdin)), assert(freopen(".out", "w", stdout));
#else
auto start = chrono::steady_clock::now();
#endif
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
int testcases = 1;
// cin >> testcases;
for (int test = 1; test <= testcases; test++){
// cout << "Case #" << test << ": ";
Hollwo_Pelw();
}
#ifdef hollwo_pelw_local
auto end = chrono::steady_clock::now();
cout << "\nExcution time : " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif
}
/*
t = z * b + y
0 <= y < b
x = (z * (b + 1) + y) % a
y1 == y2
((z1 - z2) * (b + 1)) % a == 0
b = 1e18
b >= 1e12 -> z <= 1e6
*/
#define int long long
const int N = 1e6 + 5, inf = (int) 1e18 + 7;
int n, a, b, l[N], r[N];
void Hollwo_Pelw(){
cin >> n >> a >> b;
int f = a / __gcd(a, b + 1), p = inf / f >= b ? f * b : inf;
vector<pair<int, int>> v;
for (int i = 1, l, r; i <= n; i++) {
cin >> l >> r;
if (r - l + 1 >= p)
return cout << p, (void) 0;
l %= p, r %= p;
if (l > r) {
v.emplace_back(l, p - 1);
v.emplace_back(0, r);
} else {
v.emplace_back(l, r);
}
}
sort(v.begin(), v.end());
int res = 0, curl = 0, curr = -1;
for (auto [l, r] : v) {
if (curl > r || l > curr) {
res += curr - curl + 1;
curl = l, curr = r;
}
curl = min(curl, l), curr = max(curr, r);
}
res += curr - curl + 1;
cout << res << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
984 KB |
Output is correct |
3 |
Correct |
6 ms |
996 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
284 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
5 ms |
1064 KB |
Output is correct |
17 |
Correct |
51 ms |
5696 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
302 ms |
41272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
473 ms |
27232 KB |
Output is correct |
3 |
Correct |
431 ms |
31248 KB |
Output is correct |
4 |
Correct |
456 ms |
35360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
473 ms |
27232 KB |
Output is correct |
3 |
Correct |
431 ms |
31248 KB |
Output is correct |
4 |
Correct |
456 ms |
35360 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
477 ms |
35316 KB |
Output is correct |
7 |
Correct |
442 ms |
35400 KB |
Output is correct |
8 |
Correct |
452 ms |
35232 KB |
Output is correct |
9 |
Correct |
513 ms |
35296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
473 ms |
27232 KB |
Output is correct |
3 |
Correct |
431 ms |
31248 KB |
Output is correct |
4 |
Correct |
456 ms |
35360 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
44 ms |
5832 KB |
Output is correct |
7 |
Correct |
49 ms |
5748 KB |
Output is correct |
8 |
Correct |
60 ms |
5828 KB |
Output is correct |
9 |
Correct |
41 ms |
5636 KB |
Output is correct |
10 |
Correct |
43 ms |
5788 KB |
Output is correct |
11 |
Correct |
56 ms |
5628 KB |
Output is correct |
12 |
Correct |
58 ms |
5620 KB |
Output is correct |
13 |
Correct |
58 ms |
5724 KB |
Output is correct |
14 |
Correct |
49 ms |
5668 KB |
Output is correct |
15 |
Correct |
43 ms |
5700 KB |
Output is correct |
16 |
Correct |
48 ms |
5708 KB |
Output is correct |
17 |
Correct |
53 ms |
5680 KB |
Output is correct |
18 |
Correct |
451 ms |
35328 KB |
Output is correct |
19 |
Correct |
458 ms |
35316 KB |
Output is correct |
20 |
Correct |
506 ms |
35216 KB |
Output is correct |
21 |
Correct |
58 ms |
5624 KB |
Output is correct |
22 |
Correct |
37 ms |
5696 KB |
Output is correct |
23 |
Correct |
131 ms |
18484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
55 ms |
5608 KB |
Output is correct |
3 |
Correct |
57 ms |
5672 KB |
Output is correct |
4 |
Correct |
474 ms |
31084 KB |
Output is correct |
5 |
Correct |
47 ms |
5736 KB |
Output is correct |
6 |
Correct |
54 ms |
5716 KB |
Output is correct |
7 |
Correct |
43 ms |
5680 KB |
Output is correct |
8 |
Correct |
46 ms |
5696 KB |
Output is correct |
9 |
Correct |
42 ms |
5684 KB |
Output is correct |
10 |
Correct |
45 ms |
5660 KB |
Output is correct |
11 |
Correct |
54 ms |
5644 KB |
Output is correct |
12 |
Correct |
39 ms |
5668 KB |
Output is correct |
13 |
Correct |
43 ms |
5692 KB |
Output is correct |
14 |
Correct |
470 ms |
35424 KB |
Output is correct |
15 |
Correct |
48 ms |
5700 KB |
Output is correct |
16 |
Correct |
422 ms |
35300 KB |
Output is correct |
17 |
Correct |
475 ms |
35204 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
984 KB |
Output is correct |
3 |
Correct |
6 ms |
996 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
284 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
5 ms |
1064 KB |
Output is correct |
17 |
Correct |
51 ms |
5696 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
324 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
302 ms |
41272 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
473 ms |
27232 KB |
Output is correct |
31 |
Correct |
431 ms |
31248 KB |
Output is correct |
32 |
Correct |
456 ms |
35360 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
477 ms |
35316 KB |
Output is correct |
35 |
Correct |
442 ms |
35400 KB |
Output is correct |
36 |
Correct |
452 ms |
35232 KB |
Output is correct |
37 |
Correct |
513 ms |
35296 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
44 ms |
5832 KB |
Output is correct |
40 |
Correct |
49 ms |
5748 KB |
Output is correct |
41 |
Correct |
60 ms |
5828 KB |
Output is correct |
42 |
Correct |
41 ms |
5636 KB |
Output is correct |
43 |
Correct |
43 ms |
5788 KB |
Output is correct |
44 |
Correct |
56 ms |
5628 KB |
Output is correct |
45 |
Correct |
58 ms |
5620 KB |
Output is correct |
46 |
Correct |
58 ms |
5724 KB |
Output is correct |
47 |
Correct |
49 ms |
5668 KB |
Output is correct |
48 |
Correct |
43 ms |
5700 KB |
Output is correct |
49 |
Correct |
48 ms |
5708 KB |
Output is correct |
50 |
Correct |
53 ms |
5680 KB |
Output is correct |
51 |
Correct |
451 ms |
35328 KB |
Output is correct |
52 |
Correct |
458 ms |
35316 KB |
Output is correct |
53 |
Correct |
506 ms |
35216 KB |
Output is correct |
54 |
Correct |
58 ms |
5624 KB |
Output is correct |
55 |
Correct |
37 ms |
5696 KB |
Output is correct |
56 |
Correct |
131 ms |
18484 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
55 ms |
5608 KB |
Output is correct |
59 |
Correct |
57 ms |
5672 KB |
Output is correct |
60 |
Correct |
474 ms |
31084 KB |
Output is correct |
61 |
Correct |
47 ms |
5736 KB |
Output is correct |
62 |
Correct |
54 ms |
5716 KB |
Output is correct |
63 |
Correct |
43 ms |
5680 KB |
Output is correct |
64 |
Correct |
46 ms |
5696 KB |
Output is correct |
65 |
Correct |
42 ms |
5684 KB |
Output is correct |
66 |
Correct |
45 ms |
5660 KB |
Output is correct |
67 |
Correct |
54 ms |
5644 KB |
Output is correct |
68 |
Correct |
39 ms |
5668 KB |
Output is correct |
69 |
Correct |
43 ms |
5692 KB |
Output is correct |
70 |
Correct |
470 ms |
35424 KB |
Output is correct |
71 |
Correct |
48 ms |
5700 KB |
Output is correct |
72 |
Correct |
422 ms |
35300 KB |
Output is correct |
73 |
Correct |
475 ms |
35204 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
6 ms |
1108 KB |
Output is correct |
80 |
Correct |
518 ms |
35288 KB |
Output is correct |
81 |
Correct |
501 ms |
35220 KB |
Output is correct |
82 |
Correct |
467 ms |
35252 KB |
Output is correct |
83 |
Correct |
475 ms |
35152 KB |
Output is correct |
84 |
Correct |
472 ms |
35180 KB |
Output is correct |
85 |
Correct |
493 ms |
35124 KB |
Output is correct |
86 |
Correct |
133 ms |
18444 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |