// #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;
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 |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
776 KB |
Output is correct |
3 |
Correct |
5 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 |
1 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 |
29 ms |
3808 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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
173 ms |
18952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
221 ms |
18300 KB |
Output is correct |
3 |
Correct |
257 ms |
18256 KB |
Output is correct |
4 |
Correct |
252 ms |
39492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
221 ms |
18300 KB |
Output is correct |
3 |
Correct |
257 ms |
18256 KB |
Output is correct |
4 |
Correct |
252 ms |
39492 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
251 ms |
39636 KB |
Output is correct |
7 |
Correct |
279 ms |
39424 KB |
Output is correct |
8 |
Correct |
246 ms |
38780 KB |
Output is correct |
9 |
Correct |
281 ms |
39184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
221 ms |
18300 KB |
Output is correct |
3 |
Correct |
257 ms |
18256 KB |
Output is correct |
4 |
Correct |
252 ms |
39492 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
23 ms |
4876 KB |
Output is correct |
7 |
Correct |
25 ms |
5064 KB |
Output is correct |
8 |
Correct |
30 ms |
4928 KB |
Output is correct |
9 |
Correct |
29 ms |
5104 KB |
Output is correct |
10 |
Correct |
26 ms |
5312 KB |
Output is correct |
11 |
Correct |
25 ms |
5060 KB |
Output is correct |
12 |
Correct |
25 ms |
5124 KB |
Output is correct |
13 |
Correct |
27 ms |
5064 KB |
Output is correct |
14 |
Correct |
25 ms |
4916 KB |
Output is correct |
15 |
Correct |
27 ms |
5068 KB |
Output is correct |
16 |
Correct |
30 ms |
4992 KB |
Output is correct |
17 |
Correct |
25 ms |
5052 KB |
Output is correct |
18 |
Correct |
240 ms |
38948 KB |
Output is correct |
19 |
Correct |
244 ms |
39340 KB |
Output is correct |
20 |
Correct |
273 ms |
39308 KB |
Output is correct |
21 |
Correct |
29 ms |
4848 KB |
Output is correct |
22 |
Correct |
24 ms |
5060 KB |
Output is correct |
23 |
Correct |
73 ms |
15988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
27 ms |
2520 KB |
Output is correct |
3 |
Correct |
25 ms |
2520 KB |
Output is correct |
4 |
Correct |
268 ms |
18352 KB |
Output is correct |
5 |
Correct |
25 ms |
2520 KB |
Output is correct |
6 |
Correct |
25 ms |
2480 KB |
Output is correct |
7 |
Correct |
25 ms |
2520 KB |
Output is correct |
8 |
Correct |
26 ms |
2516 KB |
Output is correct |
9 |
Correct |
24 ms |
2664 KB |
Output is correct |
10 |
Correct |
33 ms |
2472 KB |
Output is correct |
11 |
Correct |
25 ms |
2516 KB |
Output is correct |
12 |
Correct |
22 ms |
2516 KB |
Output is correct |
13 |
Correct |
25 ms |
2520 KB |
Output is correct |
14 |
Correct |
254 ms |
18612 KB |
Output is correct |
15 |
Correct |
25 ms |
2520 KB |
Output is correct |
16 |
Correct |
250 ms |
38928 KB |
Output is correct |
17 |
Correct |
239 ms |
38948 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
776 KB |
Output is correct |
3 |
Correct |
5 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 |
1 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 |
29 ms |
3808 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |