#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pp pop_back
#define mp make_pair
#define bb back
#define ff first
#define ss second
#define int long long
using namespace std;
/*
____ __ _______ _______ __________
| \ | | | _____| / _____) |____ ____|
| |\ \ | | | |__ ( (_____ | |
| | \ \| | | __| \_____ \ | |
| | \ | | |_____ _____) ) | |
|__| \____| |_______| (_______/ |__|
*/
int INF = LLONG_MAX;
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, A, B, I, gcd, k, l, r;
cin >> n >> A >> B;
gcd = __gcd(A, B+1);
if (gcd == 1) k = A;
else k = A / gcd;
if (INF / k <= B)
I = INF;
else
I = k*B;
vector<pair<int, int> > rem;
for (int i = 0; i < n; i++) {
cin >> l >> r;
if (r-l >= I) {
rem.pb({0, I});
} else if (l%I > r%I) {
rem.pb({l%I, I-1});
rem.pb({0, r%I});
} else {
rem.pb({l%I, r%I});
}
}
int L = 0, ans = 0;
sort(rem.begin(), rem.end());
for (auto el : rem) {
el.ff = max(el.ff, L);
if (el.ff > el.ss)
continue;
ans += el.ss-el.ff+1;
L = max(L, el.ss+1);
}
cout << ans << '\n';
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
5 ms |
592 KB |
Output is correct |
3 |
Correct |
5 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
276 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
8 ms |
704 KB |
Output is correct |
17 |
Correct |
49 ms |
2416 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
335 ms |
16824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
490 ms |
16784 KB |
Output is correct |
3 |
Correct |
462 ms |
16752 KB |
Output is correct |
4 |
Correct |
513 ms |
16928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
490 ms |
16784 KB |
Output is correct |
3 |
Correct |
462 ms |
16752 KB |
Output is correct |
4 |
Correct |
513 ms |
16928 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
487 ms |
16840 KB |
Output is correct |
7 |
Correct |
478 ms |
16900 KB |
Output is correct |
8 |
Correct |
470 ms |
16744 KB |
Output is correct |
9 |
Correct |
591 ms |
16780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
490 ms |
16784 KB |
Output is correct |
3 |
Correct |
462 ms |
16752 KB |
Output is correct |
4 |
Correct |
513 ms |
16928 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
53 ms |
2400 KB |
Output is correct |
7 |
Correct |
51 ms |
2456 KB |
Output is correct |
8 |
Correct |
51 ms |
2496 KB |
Output is correct |
9 |
Correct |
47 ms |
2392 KB |
Output is correct |
10 |
Correct |
45 ms |
2432 KB |
Output is correct |
11 |
Correct |
60 ms |
2420 KB |
Output is correct |
12 |
Correct |
52 ms |
2496 KB |
Output is correct |
13 |
Correct |
51 ms |
2408 KB |
Output is correct |
14 |
Correct |
44 ms |
2516 KB |
Output is correct |
15 |
Correct |
52 ms |
2400 KB |
Output is correct |
16 |
Correct |
54 ms |
2500 KB |
Output is correct |
17 |
Correct |
47 ms |
2392 KB |
Output is correct |
18 |
Correct |
495 ms |
16812 KB |
Output is correct |
19 |
Correct |
462 ms |
16872 KB |
Output is correct |
20 |
Correct |
539 ms |
16804 KB |
Output is correct |
21 |
Correct |
51 ms |
2428 KB |
Output is correct |
22 |
Correct |
42 ms |
2496 KB |
Output is correct |
23 |
Correct |
146 ms |
8572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
50 ms |
2504 KB |
Output is correct |
3 |
Correct |
56 ms |
2476 KB |
Output is correct |
4 |
Correct |
551 ms |
16816 KB |
Output is correct |
5 |
Correct |
56 ms |
2392 KB |
Output is correct |
6 |
Correct |
51 ms |
2480 KB |
Output is correct |
7 |
Correct |
49 ms |
2432 KB |
Output is correct |
8 |
Correct |
54 ms |
2456 KB |
Output is correct |
9 |
Correct |
47 ms |
2428 KB |
Output is correct |
10 |
Correct |
55 ms |
2520 KB |
Output is correct |
11 |
Correct |
47 ms |
2444 KB |
Output is correct |
12 |
Correct |
41 ms |
2504 KB |
Output is correct |
13 |
Correct |
55 ms |
2496 KB |
Output is correct |
14 |
Correct |
520 ms |
16760 KB |
Output is correct |
15 |
Correct |
47 ms |
2504 KB |
Output is correct |
16 |
Correct |
512 ms |
16740 KB |
Output is correct |
17 |
Correct |
493 ms |
16804 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
5 ms |
592 KB |
Output is correct |
3 |
Correct |
5 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
276 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
8 ms |
704 KB |
Output is correct |
17 |
Correct |
49 ms |
2416 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |