// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const double EPS = 0.00001;
const int INF = 1e18 + 5;
const int N = 3e5+5;
const int ALPH = 26;
const int LGN = 25;
constexpr int MOD = 1e9+7;
int n,m,q;
inline void solve() {
int A, B;
cin >> n >> A >> B;
__int128_t space = (__int128_t)A / __gcd(A, B + 1) * B;
space = min(space, (__int128_t)INF);
int sp = (int)space;
vector<array<int, 2> > inter;
REP(i, n) {
int l, r;
cin >> l >> r;
if(r - l + 1 >= sp) {
cout << sp << "\n";
return;
}
l %= sp; r %= sp;
if(l > r) {
inter.pb({0, r});
inter.pb({l, sp - 1});
}
else {
inter.pb({l, r});
}
}
int last = 0;
int ans = 0;
sort(all(inter));
for(auto c : inter) {
c[0] = max(last, c[0]);
if(c[0] > c[1]) continue;
ans += c[1] - c[0] + 1;
last = c[1] + 1;
}
cout << ans << "\n";
}
signed main() {
fastio();
int test = 1;
//cin>>test;
while(test--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
856 KB |
Output is correct |
3 |
Correct |
3 ms |
736 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 |
0 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 |
0 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 |
2 ms |
736 KB |
Output is correct |
17 |
Correct |
26 ms |
2520 KB |
Output is correct |
18 |
Correct |
1 ms |
348 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 |
348 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 |
173 ms |
17808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
230 ms |
18732 KB |
Output is correct |
3 |
Correct |
244 ms |
17336 KB |
Output is correct |
4 |
Correct |
231 ms |
17848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
230 ms |
18732 KB |
Output is correct |
3 |
Correct |
244 ms |
17336 KB |
Output is correct |
4 |
Correct |
231 ms |
17848 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
232 ms |
17572 KB |
Output is correct |
7 |
Correct |
262 ms |
18104 KB |
Output is correct |
8 |
Correct |
227 ms |
16824 KB |
Output is correct |
9 |
Correct |
267 ms |
17492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
230 ms |
18732 KB |
Output is correct |
3 |
Correct |
244 ms |
17336 KB |
Output is correct |
4 |
Correct |
231 ms |
17848 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
22 ms |
2424 KB |
Output is correct |
7 |
Correct |
24 ms |
2520 KB |
Output is correct |
8 |
Correct |
22 ms |
2520 KB |
Output is correct |
9 |
Correct |
24 ms |
2544 KB |
Output is correct |
10 |
Correct |
24 ms |
2564 KB |
Output is correct |
11 |
Correct |
24 ms |
2520 KB |
Output is correct |
12 |
Correct |
27 ms |
2804 KB |
Output is correct |
13 |
Correct |
26 ms |
2516 KB |
Output is correct |
14 |
Correct |
22 ms |
2520 KB |
Output is correct |
15 |
Correct |
28 ms |
2416 KB |
Output is correct |
16 |
Correct |
26 ms |
2520 KB |
Output is correct |
17 |
Correct |
23 ms |
2520 KB |
Output is correct |
18 |
Correct |
228 ms |
17840 KB |
Output is correct |
19 |
Correct |
224 ms |
18616 KB |
Output is correct |
20 |
Correct |
270 ms |
17588 KB |
Output is correct |
21 |
Correct |
25 ms |
2520 KB |
Output is correct |
22 |
Correct |
22 ms |
2520 KB |
Output is correct |
23 |
Correct |
72 ms |
9936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
26 ms |
2520 KB |
Output is correct |
3 |
Correct |
24 ms |
2416 KB |
Output is correct |
4 |
Correct |
258 ms |
18696 KB |
Output is correct |
5 |
Correct |
25 ms |
2516 KB |
Output is correct |
6 |
Correct |
25 ms |
2520 KB |
Output is correct |
7 |
Correct |
25 ms |
2520 KB |
Output is correct |
8 |
Correct |
33 ms |
2820 KB |
Output is correct |
9 |
Correct |
25 ms |
2520 KB |
Output is correct |
10 |
Correct |
25 ms |
2520 KB |
Output is correct |
11 |
Correct |
25 ms |
2520 KB |
Output is correct |
12 |
Correct |
21 ms |
2516 KB |
Output is correct |
13 |
Correct |
24 ms |
2520 KB |
Output is correct |
14 |
Correct |
289 ms |
16828 KB |
Output is correct |
15 |
Correct |
24 ms |
2520 KB |
Output is correct |
16 |
Correct |
223 ms |
17316 KB |
Output is correct |
17 |
Correct |
220 ms |
18536 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
856 KB |
Output is correct |
3 |
Correct |
3 ms |
736 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 |
0 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 |
0 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 |
2 ms |
736 KB |
Output is correct |
17 |
Correct |
26 ms |
2520 KB |
Output is correct |
18 |
Correct |
1 ms |
348 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 |
348 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 |
173 ms |
17808 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
230 ms |
18732 KB |
Output is correct |
31 |
Correct |
244 ms |
17336 KB |
Output is correct |
32 |
Correct |
231 ms |
17848 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
232 ms |
17572 KB |
Output is correct |
35 |
Correct |
262 ms |
18104 KB |
Output is correct |
36 |
Correct |
227 ms |
16824 KB |
Output is correct |
37 |
Correct |
267 ms |
17492 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
22 ms |
2424 KB |
Output is correct |
40 |
Correct |
24 ms |
2520 KB |
Output is correct |
41 |
Correct |
22 ms |
2520 KB |
Output is correct |
42 |
Correct |
24 ms |
2544 KB |
Output is correct |
43 |
Correct |
24 ms |
2564 KB |
Output is correct |
44 |
Correct |
24 ms |
2520 KB |
Output is correct |
45 |
Correct |
27 ms |
2804 KB |
Output is correct |
46 |
Correct |
26 ms |
2516 KB |
Output is correct |
47 |
Correct |
22 ms |
2520 KB |
Output is correct |
48 |
Correct |
28 ms |
2416 KB |
Output is correct |
49 |
Correct |
26 ms |
2520 KB |
Output is correct |
50 |
Correct |
23 ms |
2520 KB |
Output is correct |
51 |
Correct |
228 ms |
17840 KB |
Output is correct |
52 |
Correct |
224 ms |
18616 KB |
Output is correct |
53 |
Correct |
270 ms |
17588 KB |
Output is correct |
54 |
Correct |
25 ms |
2520 KB |
Output is correct |
55 |
Correct |
22 ms |
2520 KB |
Output is correct |
56 |
Correct |
72 ms |
9936 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
26 ms |
2520 KB |
Output is correct |
59 |
Correct |
24 ms |
2416 KB |
Output is correct |
60 |
Correct |
258 ms |
18696 KB |
Output is correct |
61 |
Correct |
25 ms |
2516 KB |
Output is correct |
62 |
Correct |
25 ms |
2520 KB |
Output is correct |
63 |
Correct |
25 ms |
2520 KB |
Output is correct |
64 |
Correct |
33 ms |
2820 KB |
Output is correct |
65 |
Correct |
25 ms |
2520 KB |
Output is correct |
66 |
Correct |
25 ms |
2520 KB |
Output is correct |
67 |
Correct |
25 ms |
2520 KB |
Output is correct |
68 |
Correct |
21 ms |
2516 KB |
Output is correct |
69 |
Correct |
24 ms |
2520 KB |
Output is correct |
70 |
Correct |
289 ms |
16828 KB |
Output is correct |
71 |
Correct |
24 ms |
2520 KB |
Output is correct |
72 |
Correct |
223 ms |
17316 KB |
Output is correct |
73 |
Correct |
220 ms |
18536 KB |
Output is correct |
74 |
Correct |
0 ms |
348 KB |
Output is correct |
75 |
Correct |
0 ms |
348 KB |
Output is correct |
76 |
Correct |
0 ms |
348 KB |
Output is correct |
77 |
Correct |
1 ms |
348 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
3 ms |
736 KB |
Output is correct |
80 |
Correct |
259 ms |
18140 KB |
Output is correct |
81 |
Correct |
256 ms |
17960 KB |
Output is correct |
82 |
Correct |
255 ms |
18356 KB |
Output is correct |
83 |
Correct |
268 ms |
17080 KB |
Output is correct |
84 |
Correct |
257 ms |
17396 KB |
Output is correct |
85 |
Correct |
253 ms |
16820 KB |
Output is correct |
86 |
Correct |
69 ms |
10692 KB |
Output is correct |
87 |
Correct |
1 ms |
348 KB |
Output is correct |