/* In the name of God, aka Allah */
// let this be mytemp.cpp
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define mk make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll inf = (1ll<<60);
const int N = 1e6 + 50;
ll n, A, B;
pll P[N];
map<ll, ll> mp;
void solve() {
cin >> n >> A >> B;
ll C = B+1;
ll lcm = A*min((inf+A-1)/A, C/__gcd(A, C));
for (int i = 1; i <= n; i++) {
cin >> P[i].F >> P[i].S;
P[i].S ++;
P[i].F += P[i].F/B;
P[i].S += P[i].S/B;
if (P[i].S - P[i].F >= lcm) {
return cout << lcm - lcm/C << endl, void();
}
ll l = P[i].F % lcm, r = P[i].S % lcm;
mp[l]++;
mp[r]--;
if (r < l) mp[0]++, mp[lcm]--;
}
ll ans = 0;
ll bl = 0;
ll pt = 0;
for (pll x:mp) {
if (!bl) pt = x.F;
bl += x.S;
if (!bl) {
ans += (x.F-x.F/C)-(pt-pt/C);
}
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
9 ms |
1436 KB |
Output is correct |
3 |
Correct |
6 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
6 ms |
1460 KB |
Output is correct |
17 |
Correct |
61 ms |
11836 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
472 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
273 ms |
41100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
639 ms |
96572 KB |
Output is correct |
3 |
Correct |
673 ms |
96740 KB |
Output is correct |
4 |
Correct |
708 ms |
96692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
639 ms |
96572 KB |
Output is correct |
3 |
Correct |
673 ms |
96740 KB |
Output is correct |
4 |
Correct |
708 ms |
96692 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
705 ms |
96992 KB |
Output is correct |
7 |
Correct |
708 ms |
96848 KB |
Output is correct |
8 |
Correct |
687 ms |
96820 KB |
Output is correct |
9 |
Correct |
728 ms |
96612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
639 ms |
96572 KB |
Output is correct |
3 |
Correct |
673 ms |
96740 KB |
Output is correct |
4 |
Correct |
708 ms |
96692 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
55 ms |
11860 KB |
Output is correct |
7 |
Correct |
56 ms |
11804 KB |
Output is correct |
8 |
Correct |
57 ms |
11792 KB |
Output is correct |
9 |
Correct |
77 ms |
11852 KB |
Output is correct |
10 |
Correct |
59 ms |
11880 KB |
Output is correct |
11 |
Correct |
55 ms |
11860 KB |
Output is correct |
12 |
Correct |
56 ms |
11752 KB |
Output is correct |
13 |
Correct |
62 ms |
11764 KB |
Output is correct |
14 |
Correct |
57 ms |
11872 KB |
Output is correct |
15 |
Correct |
68 ms |
11788 KB |
Output is correct |
16 |
Correct |
68 ms |
11860 KB |
Output is correct |
17 |
Correct |
63 ms |
11864 KB |
Output is correct |
18 |
Correct |
687 ms |
96780 KB |
Output is correct |
19 |
Correct |
678 ms |
96632 KB |
Output is correct |
20 |
Correct |
748 ms |
96532 KB |
Output is correct |
21 |
Correct |
58 ms |
11852 KB |
Output is correct |
22 |
Correct |
59 ms |
11756 KB |
Output is correct |
23 |
Correct |
118 ms |
18132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
65 ms |
11852 KB |
Output is correct |
3 |
Correct |
72 ms |
11796 KB |
Output is correct |
4 |
Correct |
718 ms |
96484 KB |
Output is correct |
5 |
Correct |
67 ms |
11820 KB |
Output is correct |
6 |
Correct |
66 ms |
11756 KB |
Output is correct |
7 |
Correct |
66 ms |
11852 KB |
Output is correct |
8 |
Correct |
64 ms |
11840 KB |
Output is correct |
9 |
Correct |
71 ms |
11852 KB |
Output is correct |
10 |
Correct |
59 ms |
11864 KB |
Output is correct |
11 |
Correct |
63 ms |
11852 KB |
Output is correct |
12 |
Correct |
60 ms |
11820 KB |
Output is correct |
13 |
Correct |
67 ms |
11780 KB |
Output is correct |
14 |
Correct |
738 ms |
96496 KB |
Output is correct |
15 |
Correct |
57 ms |
11780 KB |
Output is correct |
16 |
Correct |
650 ms |
96444 KB |
Output is correct |
17 |
Correct |
622 ms |
96340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
9 ms |
1436 KB |
Output is correct |
3 |
Correct |
6 ms |
1492 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
6 ms |
1460 KB |
Output is correct |
17 |
Correct |
61 ms |
11836 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
472 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
273 ms |
41100 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
639 ms |
96572 KB |
Output is correct |
31 |
Correct |
673 ms |
96740 KB |
Output is correct |
32 |
Correct |
708 ms |
96692 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
705 ms |
96992 KB |
Output is correct |
35 |
Correct |
708 ms |
96848 KB |
Output is correct |
36 |
Correct |
687 ms |
96820 KB |
Output is correct |
37 |
Correct |
728 ms |
96612 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
55 ms |
11860 KB |
Output is correct |
40 |
Correct |
56 ms |
11804 KB |
Output is correct |
41 |
Correct |
57 ms |
11792 KB |
Output is correct |
42 |
Correct |
77 ms |
11852 KB |
Output is correct |
43 |
Correct |
59 ms |
11880 KB |
Output is correct |
44 |
Correct |
55 ms |
11860 KB |
Output is correct |
45 |
Correct |
56 ms |
11752 KB |
Output is correct |
46 |
Correct |
62 ms |
11764 KB |
Output is correct |
47 |
Correct |
57 ms |
11872 KB |
Output is correct |
48 |
Correct |
68 ms |
11788 KB |
Output is correct |
49 |
Correct |
68 ms |
11860 KB |
Output is correct |
50 |
Correct |
63 ms |
11864 KB |
Output is correct |
51 |
Correct |
687 ms |
96780 KB |
Output is correct |
52 |
Correct |
678 ms |
96632 KB |
Output is correct |
53 |
Correct |
748 ms |
96532 KB |
Output is correct |
54 |
Correct |
58 ms |
11852 KB |
Output is correct |
55 |
Correct |
59 ms |
11756 KB |
Output is correct |
56 |
Correct |
118 ms |
18132 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
65 ms |
11852 KB |
Output is correct |
59 |
Correct |
72 ms |
11796 KB |
Output is correct |
60 |
Correct |
718 ms |
96484 KB |
Output is correct |
61 |
Correct |
67 ms |
11820 KB |
Output is correct |
62 |
Correct |
66 ms |
11756 KB |
Output is correct |
63 |
Correct |
66 ms |
11852 KB |
Output is correct |
64 |
Correct |
64 ms |
11840 KB |
Output is correct |
65 |
Correct |
71 ms |
11852 KB |
Output is correct |
66 |
Correct |
59 ms |
11864 KB |
Output is correct |
67 |
Correct |
63 ms |
11852 KB |
Output is correct |
68 |
Correct |
60 ms |
11820 KB |
Output is correct |
69 |
Correct |
67 ms |
11780 KB |
Output is correct |
70 |
Correct |
738 ms |
96496 KB |
Output is correct |
71 |
Correct |
57 ms |
11780 KB |
Output is correct |
72 |
Correct |
650 ms |
96444 KB |
Output is correct |
73 |
Correct |
622 ms |
96340 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
7 ms |
1460 KB |
Output is correct |
80 |
Correct |
707 ms |
96028 KB |
Output is correct |
81 |
Correct |
721 ms |
95748 KB |
Output is correct |
82 |
Correct |
716 ms |
95448 KB |
Output is correct |
83 |
Correct |
722 ms |
95084 KB |
Output is correct |
84 |
Correct |
769 ms |
94780 KB |
Output is correct |
85 |
Correct |
761 ms |
93960 KB |
Output is correct |
86 |
Correct |
116 ms |
18112 KB |
Output is correct |
87 |
Correct |
1 ms |
336 KB |
Output is correct |