// #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();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
736 KB |
Output is correct |
3 |
Correct |
2 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 |
3 ms |
732 KB |
Output is correct |
17 |
Correct |
26 ms |
2516 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
167 ms |
18784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
228 ms |
17688 KB |
Output is correct |
3 |
Correct |
226 ms |
18992 KB |
Output is correct |
4 |
Correct |
223 ms |
17024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
228 ms |
17688 KB |
Output is correct |
3 |
Correct |
226 ms |
18992 KB |
Output is correct |
4 |
Correct |
223 ms |
17024 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
248 ms |
17180 KB |
Output is correct |
7 |
Correct |
224 ms |
18356 KB |
Output is correct |
8 |
Correct |
225 ms |
17332 KB |
Output is correct |
9 |
Correct |
261 ms |
17848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
228 ms |
17688 KB |
Output is correct |
3 |
Correct |
226 ms |
18992 KB |
Output is correct |
4 |
Correct |
223 ms |
17024 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
22 ms |
2520 KB |
Output is correct |
7 |
Correct |
26 ms |
2588 KB |
Output is correct |
8 |
Correct |
28 ms |
2520 KB |
Output is correct |
9 |
Correct |
31 ms |
2520 KB |
Output is correct |
10 |
Correct |
29 ms |
2520 KB |
Output is correct |
11 |
Correct |
24 ms |
2500 KB |
Output is correct |
12 |
Correct |
24 ms |
2520 KB |
Output is correct |
13 |
Correct |
32 ms |
2512 KB |
Output is correct |
14 |
Correct |
22 ms |
2520 KB |
Output is correct |
15 |
Correct |
26 ms |
2440 KB |
Output is correct |
16 |
Correct |
34 ms |
2520 KB |
Output is correct |
17 |
Correct |
30 ms |
2520 KB |
Output is correct |
18 |
Correct |
247 ms |
18872 KB |
Output is correct |
19 |
Correct |
224 ms |
17332 KB |
Output is correct |
20 |
Correct |
251 ms |
17592 KB |
Output is correct |
21 |
Correct |
30 ms |
2876 KB |
Output is correct |
22 |
Correct |
21 ms |
2516 KB |
Output is correct |
23 |
Correct |
70 ms |
8960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
25 ms |
2420 KB |
Output is correct |
3 |
Correct |
30 ms |
2520 KB |
Output is correct |
4 |
Correct |
272 ms |
17144 KB |
Output is correct |
5 |
Correct |
31 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 |
25 ms |
2520 KB |
Output is correct |
9 |
Correct |
25 ms |
2520 KB |
Output is correct |
10 |
Correct |
26 ms |
2520 KB |
Output is correct |
11 |
Correct |
26 ms |
2496 KB |
Output is correct |
12 |
Correct |
22 ms |
2520 KB |
Output is correct |
13 |
Correct |
25 ms |
2444 KB |
Output is correct |
14 |
Correct |
257 ms |
18360 KB |
Output is correct |
15 |
Correct |
24 ms |
2520 KB |
Output is correct |
16 |
Correct |
230 ms |
17216 KB |
Output is correct |
17 |
Correct |
218 ms |
17056 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
736 KB |
Output is correct |
3 |
Correct |
2 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 |
3 ms |
732 KB |
Output is correct |
17 |
Correct |
26 ms |
2516 KB |
Output is correct |
18 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
167 ms |
18784 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
228 ms |
17688 KB |
Output is correct |
31 |
Correct |
226 ms |
18992 KB |
Output is correct |
32 |
Correct |
223 ms |
17024 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
248 ms |
17180 KB |
Output is correct |
35 |
Correct |
224 ms |
18356 KB |
Output is correct |
36 |
Correct |
225 ms |
17332 KB |
Output is correct |
37 |
Correct |
261 ms |
17848 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
22 ms |
2520 KB |
Output is correct |
40 |
Correct |
26 ms |
2588 KB |
Output is correct |
41 |
Correct |
28 ms |
2520 KB |
Output is correct |
42 |
Correct |
31 ms |
2520 KB |
Output is correct |
43 |
Correct |
29 ms |
2520 KB |
Output is correct |
44 |
Correct |
24 ms |
2500 KB |
Output is correct |
45 |
Correct |
24 ms |
2520 KB |
Output is correct |
46 |
Correct |
32 ms |
2512 KB |
Output is correct |
47 |
Correct |
22 ms |
2520 KB |
Output is correct |
48 |
Correct |
26 ms |
2440 KB |
Output is correct |
49 |
Correct |
34 ms |
2520 KB |
Output is correct |
50 |
Correct |
30 ms |
2520 KB |
Output is correct |
51 |
Correct |
247 ms |
18872 KB |
Output is correct |
52 |
Correct |
224 ms |
17332 KB |
Output is correct |
53 |
Correct |
251 ms |
17592 KB |
Output is correct |
54 |
Correct |
30 ms |
2876 KB |
Output is correct |
55 |
Correct |
21 ms |
2516 KB |
Output is correct |
56 |
Correct |
70 ms |
8960 KB |
Output is correct |
57 |
Correct |
1 ms |
344 KB |
Output is correct |
58 |
Correct |
25 ms |
2420 KB |
Output is correct |
59 |
Correct |
30 ms |
2520 KB |
Output is correct |
60 |
Correct |
272 ms |
17144 KB |
Output is correct |
61 |
Correct |
31 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 |
25 ms |
2520 KB |
Output is correct |
65 |
Correct |
25 ms |
2520 KB |
Output is correct |
66 |
Correct |
26 ms |
2520 KB |
Output is correct |
67 |
Correct |
26 ms |
2496 KB |
Output is correct |
68 |
Correct |
22 ms |
2520 KB |
Output is correct |
69 |
Correct |
25 ms |
2444 KB |
Output is correct |
70 |
Correct |
257 ms |
18360 KB |
Output is correct |
71 |
Correct |
24 ms |
2520 KB |
Output is correct |
72 |
Correct |
230 ms |
17216 KB |
Output is correct |
73 |
Correct |
218 ms |
17056 KB |
Output is correct |
74 |
Correct |
0 ms |
344 KB |
Output is correct |
75 |
Correct |
0 ms |
348 KB |
Output is correct |
76 |
Correct |
0 ms |
460 KB |
Output is correct |
77 |
Correct |
0 ms |
348 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
2 ms |
1116 KB |
Output is correct |
80 |
Correct |
298 ms |
38852 KB |
Output is correct |
81 |
Correct |
283 ms |
38884 KB |
Output is correct |
82 |
Correct |
285 ms |
39752 KB |
Output is correct |
83 |
Correct |
265 ms |
39344 KB |
Output is correct |
84 |
Correct |
267 ms |
39564 KB |
Output is correct |
85 |
Correct |
274 ms |
39056 KB |
Output is correct |
86 |
Correct |
79 ms |
16980 KB |
Output is correct |
87 |
Correct |
1 ms |
348 KB |
Output is correct |