// You can't change other people; you can only change yourself.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// Pragmas
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// Namespaces
#define yume using
#define wo namespace
#define kanaeyo std
#define nazotte __gnu_pbds
yume wo kanaeyo;
yume wo nazotte;
// Data types
using i8 = __int128;
using ll = long long;
using si = short int;
using ld = long double;
// Pairs
using pi8 = pair<i8, i8>;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using psi = pair<si, si>;
using pld = pair<ld, ld>;
#define fi first
#define se second
// PBDS
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
// Quick macro functions
#define sqr(x) ((x)*(x))
#define pow2(x) (1ll << (x))
#define debug(x) cout << #x << " = " << (x) << '\n'
#define debugV(x, a) cout << #x << "[" << (a) << "] = " << (x[a]) << '\n'
// Check min and max
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
// Modular arithmetic
template<typename T> void maddto(T &a, T b, T mod) {a += b; a %= mod;}
template<typename T> void msubto(T &a, T b, T mod) {a -= b; while (a < 0) a += mod; a %= mod;}
template<typename T> void mmulto(T &a, T b, T mod) {a *= b; a %= mod;}
template<typename T> T madd(T a, T b, T mod) {a += b; a %= mod; return a;}
template<typename T> T msub(T a, T b, T mod) {a -= b; while (a < 0) a += mod; return a;}
template<typename T> T mmul(T a, T b, T mod) {a *= b; a %= mod; return a;}
// Constants
const ll ModA = 998244353;
const ll ModC = 1e9 + 7;
const ll INF = 1e18;
const ll iINF = 1e9;
const ld EPS = 1e-9;
const ld iEPS = 1e-6;
i8 gcd(i8 x, i8 y) {
if (!y) return x;
return gcd(y, x % y);
}
ll n, A, B;
vector<pi8> segments;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
scanf("%lld %lld %lld", &n, &A, &B);
i8 _A = A, _B = B;
i8 _loop = ((i8)1 * _A * _B) / gcd(_A, _B+1);
ll loop;
if (_loop >= INF) {
loop = INF;
} else {
loop = _loop;
}
for (ll l, r, i = 1; i <= n; i++) {
scanf("%lld %lld", &l, &r);
if (r - l + 1 >= loop) {
printf("%lld\n", loop);
return 0;
} else {
ll lx = l % loop, rx = r % loop;
if (lx <= rx) {
segments.push_back({lx, 1});
segments.push_back({rx+1, -1});
} else {
segments.push_back({0, 1});
segments.push_back({rx+1, -1});
segments.push_back({lx, 1});
segments.push_back({loop, -1});
}
}
}
sort(segments.begin(), segments.end());
ll ans = 0, depth = 0, lastOpen = -1;
for (auto &[pos, d] : segments) {
if (depth == 0) {
lastOpen = pos;
}
depth += d;
if (depth == 0) {
ans += pos - lastOpen;
}
}
printf("%lld\n", ans);
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:77:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
77 | scanf("%lld %lld %lld", &n, &A, &B);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:89:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
89 | scanf("%lld %lld", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
10 ms |
1416 KB |
Output is correct |
3 |
Correct |
7 ms |
1380 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
7 ms |
1492 KB |
Output is correct |
17 |
Correct |
91 ms |
8664 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 |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
499 ms |
66084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
657 ms |
66064 KB |
Output is correct |
3 |
Correct |
707 ms |
66052 KB |
Output is correct |
4 |
Correct |
694 ms |
66032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
657 ms |
66064 KB |
Output is correct |
3 |
Correct |
707 ms |
66052 KB |
Output is correct |
4 |
Correct |
694 ms |
66032 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
685 ms |
66008 KB |
Output is correct |
7 |
Correct |
696 ms |
66000 KB |
Output is correct |
8 |
Correct |
698 ms |
66140 KB |
Output is correct |
9 |
Correct |
821 ms |
66184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
657 ms |
66064 KB |
Output is correct |
3 |
Correct |
707 ms |
66052 KB |
Output is correct |
4 |
Correct |
694 ms |
66032 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
57 ms |
8648 KB |
Output is correct |
7 |
Correct |
71 ms |
8568 KB |
Output is correct |
8 |
Correct |
80 ms |
8640 KB |
Output is correct |
9 |
Correct |
70 ms |
8636 KB |
Output is correct |
10 |
Correct |
57 ms |
8584 KB |
Output is correct |
11 |
Correct |
61 ms |
8636 KB |
Output is correct |
12 |
Correct |
60 ms |
8552 KB |
Output is correct |
13 |
Correct |
77 ms |
8592 KB |
Output is correct |
14 |
Correct |
70 ms |
8544 KB |
Output is correct |
15 |
Correct |
82 ms |
8560 KB |
Output is correct |
16 |
Correct |
70 ms |
8640 KB |
Output is correct |
17 |
Correct |
60 ms |
8588 KB |
Output is correct |
18 |
Correct |
698 ms |
66056 KB |
Output is correct |
19 |
Correct |
616 ms |
66060 KB |
Output is correct |
20 |
Correct |
825 ms |
66072 KB |
Output is correct |
21 |
Correct |
80 ms |
8652 KB |
Output is correct |
22 |
Correct |
66 ms |
8648 KB |
Output is correct |
23 |
Correct |
195 ms |
33280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
66 ms |
8656 KB |
Output is correct |
3 |
Correct |
88 ms |
8580 KB |
Output is correct |
4 |
Correct |
891 ms |
66004 KB |
Output is correct |
5 |
Correct |
71 ms |
8640 KB |
Output is correct |
6 |
Correct |
85 ms |
8616 KB |
Output is correct |
7 |
Correct |
82 ms |
8580 KB |
Output is correct |
8 |
Correct |
73 ms |
8644 KB |
Output is correct |
9 |
Correct |
76 ms |
8552 KB |
Output is correct |
10 |
Correct |
76 ms |
8628 KB |
Output is correct |
11 |
Correct |
67 ms |
8576 KB |
Output is correct |
12 |
Correct |
60 ms |
8604 KB |
Output is correct |
13 |
Correct |
86 ms |
8636 KB |
Output is correct |
14 |
Correct |
849 ms |
66036 KB |
Output is correct |
15 |
Correct |
88 ms |
8680 KB |
Output is correct |
16 |
Correct |
613 ms |
66092 KB |
Output is correct |
17 |
Correct |
654 ms |
66000 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
10 ms |
1416 KB |
Output is correct |
3 |
Correct |
7 ms |
1380 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
7 ms |
1492 KB |
Output is correct |
17 |
Correct |
91 ms |
8664 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 |
320 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
499 ms |
66084 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
657 ms |
66064 KB |
Output is correct |
31 |
Correct |
707 ms |
66052 KB |
Output is correct |
32 |
Correct |
694 ms |
66032 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
685 ms |
66008 KB |
Output is correct |
35 |
Correct |
696 ms |
66000 KB |
Output is correct |
36 |
Correct |
698 ms |
66140 KB |
Output is correct |
37 |
Correct |
821 ms |
66184 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
57 ms |
8648 KB |
Output is correct |
40 |
Correct |
71 ms |
8568 KB |
Output is correct |
41 |
Correct |
80 ms |
8640 KB |
Output is correct |
42 |
Correct |
70 ms |
8636 KB |
Output is correct |
43 |
Correct |
57 ms |
8584 KB |
Output is correct |
44 |
Correct |
61 ms |
8636 KB |
Output is correct |
45 |
Correct |
60 ms |
8552 KB |
Output is correct |
46 |
Correct |
77 ms |
8592 KB |
Output is correct |
47 |
Correct |
70 ms |
8544 KB |
Output is correct |
48 |
Correct |
82 ms |
8560 KB |
Output is correct |
49 |
Correct |
70 ms |
8640 KB |
Output is correct |
50 |
Correct |
60 ms |
8588 KB |
Output is correct |
51 |
Correct |
698 ms |
66056 KB |
Output is correct |
52 |
Correct |
616 ms |
66060 KB |
Output is correct |
53 |
Correct |
825 ms |
66072 KB |
Output is correct |
54 |
Correct |
80 ms |
8652 KB |
Output is correct |
55 |
Correct |
66 ms |
8648 KB |
Output is correct |
56 |
Correct |
195 ms |
33280 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
66 ms |
8656 KB |
Output is correct |
59 |
Correct |
88 ms |
8580 KB |
Output is correct |
60 |
Correct |
891 ms |
66004 KB |
Output is correct |
61 |
Correct |
71 ms |
8640 KB |
Output is correct |
62 |
Correct |
85 ms |
8616 KB |
Output is correct |
63 |
Correct |
82 ms |
8580 KB |
Output is correct |
64 |
Correct |
73 ms |
8644 KB |
Output is correct |
65 |
Correct |
76 ms |
8552 KB |
Output is correct |
66 |
Correct |
76 ms |
8628 KB |
Output is correct |
67 |
Correct |
67 ms |
8576 KB |
Output is correct |
68 |
Correct |
60 ms |
8604 KB |
Output is correct |
69 |
Correct |
86 ms |
8636 KB |
Output is correct |
70 |
Correct |
849 ms |
66036 KB |
Output is correct |
71 |
Correct |
88 ms |
8680 KB |
Output is correct |
72 |
Correct |
613 ms |
66092 KB |
Output is correct |
73 |
Correct |
654 ms |
66000 KB |
Output is correct |
74 |
Correct |
0 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 |
7 ms |
1744 KB |
Output is correct |
80 |
Correct |
844 ms |
100260 KB |
Output is correct |
81 |
Correct |
833 ms |
100132 KB |
Output is correct |
82 |
Correct |
826 ms |
100132 KB |
Output is correct |
83 |
Correct |
785 ms |
100268 KB |
Output is correct |
84 |
Correct |
804 ms |
100112 KB |
Output is correct |
85 |
Correct |
832 ms |
100188 KB |
Output is correct |
86 |
Correct |
181 ms |
43076 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |