#include <bits/stdc++.h>
#define ft first
#define sd second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define pll pair<ll, ll>
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long ll;
//typedef long long __int128;
vector<pll> vc;
vector<pll> seg;
int n;
ll A, B;
int main(){
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#else
ios_base::sync_with_stdio(0); cin.tie(0);
#endif // _LOCAL
cin >> n >> A >> B;
// if (B <= ll(1e6)){
ll fi = ll(1e18) + 10;
if ((ll(1e18) + A - 1ll) / A >= B) {
fi = A * B;
while (fi % 2 == 0){
fi >>= 1;
if ((fi + fi / B) % A != 0 || fi % B != 0) {
fi <<= 1;
break;
}
}
}
seg.clear();
for (int i = 0; i < n; i++){
ll l, r; cin >> l >> r;
if (r - l + 1 >= fi){
seg.PB(MP(0, fi - 1));
continue;
}
ll vl = ((l - 1) / fi) * fi + fi;
if (vl > r){
vl -= fi;
seg.PB(MP(l - vl, r - vl));
} else {
vl -= fi;
seg.PB(MP(l - vl, fi - 1));
vl += fi;
seg.PB(MP(0ll, r - vl));
}
}
sort(all(seg));
ll lst = -1, ans = 0;
for (pll cr : seg)
if (cr.ft > lst){
ans += cr.sd - cr.ft + 1ll;
lst = cr.sd;
} else {
ans += max(lst, cr.sd) - lst;
lst = max(lst, cr.sd);
}
cout << ans << '\n';
return 0;
// }
//
// for (int i = 0; i < n; i++){
// ll l, r; cin >> l >> r;
//
// for (ll t = l; t <= r; t++)
// vc.PB(MP((t + t / B) % A, t % B));
// }
//
// sort(all(vc));
// vc.resize(unique(all(vc)) - vc.begin());
//
// cout << sz(vc);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
9 ms |
768 KB |
Output is correct |
3 |
Correct |
10 ms |
768 KB |
Output is correct |
4 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
412 ms |
33396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
506 ms |
16852 KB |
Output is correct |
3 |
Correct |
489 ms |
16980 KB |
Output is correct |
4 |
Correct |
493 ms |
17108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
506 ms |
16852 KB |
Output is correct |
3 |
Correct |
489 ms |
16980 KB |
Output is correct |
4 |
Correct |
493 ms |
17108 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
503 ms |
16848 KB |
Output is correct |
7 |
Correct |
521 ms |
16852 KB |
Output is correct |
8 |
Correct |
482 ms |
16852 KB |
Output is correct |
9 |
Correct |
557 ms |
16852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
506 ms |
16852 KB |
Output is correct |
3 |
Correct |
489 ms |
16980 KB |
Output is correct |
4 |
Correct |
493 ms |
17108 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
52 ms |
2552 KB |
Output is correct |
7 |
Correct |
55 ms |
2544 KB |
Output is correct |
8 |
Correct |
54 ms |
2548 KB |
Output is correct |
9 |
Correct |
53 ms |
2544 KB |
Output is correct |
10 |
Correct |
51 ms |
2544 KB |
Output is correct |
11 |
Correct |
53 ms |
2544 KB |
Output is correct |
12 |
Correct |
54 ms |
2672 KB |
Output is correct |
13 |
Correct |
56 ms |
2544 KB |
Output is correct |
14 |
Correct |
52 ms |
2544 KB |
Output is correct |
15 |
Correct |
59 ms |
2544 KB |
Output is correct |
16 |
Correct |
57 ms |
2552 KB |
Output is correct |
17 |
Correct |
55 ms |
2544 KB |
Output is correct |
18 |
Correct |
507 ms |
16856 KB |
Output is correct |
19 |
Correct |
477 ms |
16860 KB |
Output is correct |
20 |
Correct |
554 ms |
16856 KB |
Output is correct |
21 |
Correct |
55 ms |
2552 KB |
Output is correct |
22 |
Correct |
52 ms |
2544 KB |
Output is correct |
23 |
Correct |
172 ms |
16856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
56 ms |
2544 KB |
Output is correct |
3 |
Correct |
57 ms |
2544 KB |
Output is correct |
4 |
Correct |
573 ms |
17104 KB |
Output is correct |
5 |
Correct |
56 ms |
2544 KB |
Output is correct |
6 |
Correct |
57 ms |
2544 KB |
Output is correct |
7 |
Correct |
54 ms |
2544 KB |
Output is correct |
8 |
Correct |
59 ms |
2544 KB |
Output is correct |
9 |
Correct |
54 ms |
2552 KB |
Output is correct |
10 |
Correct |
56 ms |
2552 KB |
Output is correct |
11 |
Correct |
56 ms |
2544 KB |
Output is correct |
12 |
Correct |
51 ms |
2544 KB |
Output is correct |
13 |
Correct |
58 ms |
2552 KB |
Output is correct |
14 |
Correct |
532 ms |
16852 KB |
Output is correct |
15 |
Incorrect |
57 ms |
2544 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
9 ms |
768 KB |
Output is correct |
3 |
Correct |
10 ms |
768 KB |
Output is correct |
4 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |