#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
const ll INF = 1e18 + 10;
int n;
ll a, b;
vector<pair<ll,int>>p;
ll mul(ll aa, ll ba) {
if(ba == 0) return 0LL;
if(ba & 1) {
return min(INF, 2 * mul(aa, ba/2) + aa);
} else {
return min(INF, 2 * mul(aa, ba/2));
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> a >> b;
ll g = __gcd(a, b + 1);
a /= g;
ll mod = mul(a, b);
for(int i = 1; i <= n; ++i) {
ll l, r;
cin >> l >> r;
if(r - l + 1 >= mod) {
p.PB({0,1});
p.PB({mod,-1});
} else {
if(l % (mod) <= r % (mod)) {
p.PB({l % (mod), 1});
p.PB({(r % (mod)) + 1, -1});
} else {
p.PB({(l % (mod)), 1});
p.PB({mod, -1});
p.PB({0, 1});
p.PB({r % (mod) + 1, -1});
}
}
}
sort(p.begin(), p.end());
ll ans = 0;
int cnt = 0;
ll pr = 0;
for(auto it : p) {
if(cnt > 0) ans += it.ST - pr;
cnt += it.ND;
pr = it.ST;
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
8 ms |
1392 KB |
Output is correct |
3 |
Correct |
7 ms |
1392 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
1392 KB |
Output is correct |
17 |
Correct |
68 ms |
7268 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
406 ms |
33596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
599 ms |
41084 KB |
Output is correct |
3 |
Correct |
616 ms |
41276 KB |
Output is correct |
4 |
Correct |
593 ms |
41180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
599 ms |
41084 KB |
Output is correct |
3 |
Correct |
616 ms |
41276 KB |
Output is correct |
4 |
Correct |
593 ms |
41180 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
606 ms |
41184 KB |
Output is correct |
7 |
Correct |
586 ms |
41336 KB |
Output is correct |
8 |
Correct |
616 ms |
33596 KB |
Output is correct |
9 |
Correct |
698 ms |
33596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
599 ms |
41084 KB |
Output is correct |
3 |
Correct |
616 ms |
41276 KB |
Output is correct |
4 |
Correct |
593 ms |
41180 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
60 ms |
7344 KB |
Output is correct |
7 |
Correct |
62 ms |
7268 KB |
Output is correct |
8 |
Correct |
58 ms |
7268 KB |
Output is correct |
9 |
Correct |
60 ms |
7268 KB |
Output is correct |
10 |
Correct |
58 ms |
7268 KB |
Output is correct |
11 |
Correct |
59 ms |
7268 KB |
Output is correct |
12 |
Correct |
57 ms |
7268 KB |
Output is correct |
13 |
Correct |
63 ms |
7268 KB |
Output is correct |
14 |
Correct |
57 ms |
7268 KB |
Output is correct |
15 |
Correct |
66 ms |
7268 KB |
Output is correct |
16 |
Correct |
65 ms |
7268 KB |
Output is correct |
17 |
Correct |
69 ms |
7268 KB |
Output is correct |
18 |
Correct |
599 ms |
33596 KB |
Output is correct |
19 |
Correct |
571 ms |
33596 KB |
Output is correct |
20 |
Correct |
715 ms |
39612 KB |
Output is correct |
21 |
Correct |
66 ms |
7452 KB |
Output is correct |
22 |
Correct |
52 ms |
7268 KB |
Output is correct |
23 |
Correct |
161 ms |
22992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
62 ms |
7268 KB |
Output is correct |
3 |
Correct |
64 ms |
7268 KB |
Output is correct |
4 |
Correct |
732 ms |
38716 KB |
Output is correct |
5 |
Correct |
65 ms |
7308 KB |
Output is correct |
6 |
Correct |
66 ms |
7412 KB |
Output is correct |
7 |
Correct |
63 ms |
7268 KB |
Output is correct |
8 |
Correct |
68 ms |
7392 KB |
Output is correct |
9 |
Correct |
62 ms |
7268 KB |
Output is correct |
10 |
Correct |
68 ms |
7268 KB |
Output is correct |
11 |
Correct |
65 ms |
7468 KB |
Output is correct |
12 |
Correct |
67 ms |
7396 KB |
Output is correct |
13 |
Correct |
66 ms |
7268 KB |
Output is correct |
14 |
Correct |
699 ms |
38192 KB |
Output is correct |
15 |
Correct |
72 ms |
7388 KB |
Output is correct |
16 |
Correct |
589 ms |
38232 KB |
Output is correct |
17 |
Correct |
587 ms |
38352 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
8 ms |
1392 KB |
Output is correct |
3 |
Correct |
7 ms |
1392 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
1392 KB |
Output is correct |
17 |
Correct |
68 ms |
7268 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
492 KB |
Output is correct |
26 |
Correct |
1 ms |
492 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
406 ms |
33596 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
599 ms |
41084 KB |
Output is correct |
31 |
Correct |
616 ms |
41276 KB |
Output is correct |
32 |
Correct |
593 ms |
41180 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
606 ms |
41184 KB |
Output is correct |
35 |
Correct |
586 ms |
41336 KB |
Output is correct |
36 |
Correct |
616 ms |
33596 KB |
Output is correct |
37 |
Correct |
698 ms |
33596 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
60 ms |
7344 KB |
Output is correct |
40 |
Correct |
62 ms |
7268 KB |
Output is correct |
41 |
Correct |
58 ms |
7268 KB |
Output is correct |
42 |
Correct |
60 ms |
7268 KB |
Output is correct |
43 |
Correct |
58 ms |
7268 KB |
Output is correct |
44 |
Correct |
59 ms |
7268 KB |
Output is correct |
45 |
Correct |
57 ms |
7268 KB |
Output is correct |
46 |
Correct |
63 ms |
7268 KB |
Output is correct |
47 |
Correct |
57 ms |
7268 KB |
Output is correct |
48 |
Correct |
66 ms |
7268 KB |
Output is correct |
49 |
Correct |
65 ms |
7268 KB |
Output is correct |
50 |
Correct |
69 ms |
7268 KB |
Output is correct |
51 |
Correct |
599 ms |
33596 KB |
Output is correct |
52 |
Correct |
571 ms |
33596 KB |
Output is correct |
53 |
Correct |
715 ms |
39612 KB |
Output is correct |
54 |
Correct |
66 ms |
7452 KB |
Output is correct |
55 |
Correct |
52 ms |
7268 KB |
Output is correct |
56 |
Correct |
161 ms |
22992 KB |
Output is correct |
57 |
Correct |
1 ms |
364 KB |
Output is correct |
58 |
Correct |
62 ms |
7268 KB |
Output is correct |
59 |
Correct |
64 ms |
7268 KB |
Output is correct |
60 |
Correct |
732 ms |
38716 KB |
Output is correct |
61 |
Correct |
65 ms |
7308 KB |
Output is correct |
62 |
Correct |
66 ms |
7412 KB |
Output is correct |
63 |
Correct |
63 ms |
7268 KB |
Output is correct |
64 |
Correct |
68 ms |
7392 KB |
Output is correct |
65 |
Correct |
62 ms |
7268 KB |
Output is correct |
66 |
Correct |
68 ms |
7268 KB |
Output is correct |
67 |
Correct |
65 ms |
7468 KB |
Output is correct |
68 |
Correct |
67 ms |
7396 KB |
Output is correct |
69 |
Correct |
66 ms |
7268 KB |
Output is correct |
70 |
Correct |
699 ms |
38192 KB |
Output is correct |
71 |
Correct |
72 ms |
7388 KB |
Output is correct |
72 |
Correct |
589 ms |
38232 KB |
Output is correct |
73 |
Correct |
587 ms |
38352 KB |
Output is correct |
74 |
Correct |
1 ms |
364 KB |
Output is correct |
75 |
Correct |
1 ms |
364 KB |
Output is correct |
76 |
Correct |
1 ms |
364 KB |
Output is correct |
77 |
Correct |
1 ms |
364 KB |
Output is correct |
78 |
Correct |
1 ms |
364 KB |
Output is correct |
79 |
Correct |
6 ms |
1392 KB |
Output is correct |
80 |
Correct |
732 ms |
42688 KB |
Output is correct |
81 |
Correct |
776 ms |
42480 KB |
Output is correct |
82 |
Correct |
684 ms |
42584 KB |
Output is correct |
83 |
Correct |
687 ms |
42592 KB |
Output is correct |
84 |
Correct |
708 ms |
42504 KB |
Output is correct |
85 |
Correct |
697 ms |
42520 KB |
Output is correct |
86 |
Correct |
167 ms |
26704 KB |
Output is correct |
87 |
Correct |
1 ms |
364 KB |
Output is correct |