#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 2e18
int main(){
int n; ll a, b, p; cin >> n >> a >> b; map<ll, int> d;
p = a / __gcd(a, b + 1); p = (p >= inf / b) ? inf : p * b;
for (int i = 0; i < n; i++){
ll l, r; cin >> l >> r;
if (r - l + 1 >= p){ d[0]++, d[p]--; continue; }
l %= p; r %= p;
if (l <= r) d[l]++, d[r + 1]--;
else d[0]++, d[r + 1]--, d[l]++, d[p]--;
}
int cnt = 0; ll pre, ans = 0;
for (auto &val : d){
if (cnt) ans += val.first - pre;
cnt += val.second; pre = val.first;
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
17 ms |
868 KB |
Output is correct |
3 |
Correct |
17 ms |
896 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
17 ms |
924 KB |
Output is correct |
17 |
Correct |
176 ms |
6620 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
332 KB |
Output is correct |
5 |
Correct |
1054 ms |
268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1898 ms |
62924 KB |
Output is correct |
3 |
Correct |
1849 ms |
63044 KB |
Output is correct |
4 |
Correct |
1904 ms |
62788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1898 ms |
62924 KB |
Output is correct |
3 |
Correct |
1849 ms |
63044 KB |
Output is correct |
4 |
Correct |
1904 ms |
62788 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1810 ms |
62944 KB |
Output is correct |
7 |
Correct |
1892 ms |
62840 KB |
Output is correct |
8 |
Correct |
1868 ms |
62840 KB |
Output is correct |
9 |
Correct |
1926 ms |
62936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1898 ms |
62924 KB |
Output is correct |
3 |
Correct |
1849 ms |
63044 KB |
Output is correct |
4 |
Correct |
1904 ms |
62788 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
187 ms |
6572 KB |
Output is correct |
7 |
Correct |
187 ms |
6500 KB |
Output is correct |
8 |
Correct |
173 ms |
6488 KB |
Output is correct |
9 |
Correct |
174 ms |
6476 KB |
Output is correct |
10 |
Correct |
166 ms |
6468 KB |
Output is correct |
11 |
Correct |
171 ms |
6536 KB |
Output is correct |
12 |
Correct |
171 ms |
6500 KB |
Output is correct |
13 |
Correct |
179 ms |
6468 KB |
Output is correct |
14 |
Correct |
171 ms |
6548 KB |
Output is correct |
15 |
Correct |
180 ms |
6612 KB |
Output is correct |
16 |
Correct |
182 ms |
6448 KB |
Output is correct |
17 |
Correct |
178 ms |
6540 KB |
Output is correct |
18 |
Correct |
1786 ms |
62896 KB |
Output is correct |
19 |
Correct |
1879 ms |
63028 KB |
Output is correct |
20 |
Correct |
1897 ms |
63064 KB |
Output is correct |
21 |
Correct |
177 ms |
6476 KB |
Output is correct |
22 |
Correct |
178 ms |
6428 KB |
Output is correct |
23 |
Correct |
481 ms |
268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
174 ms |
6528 KB |
Output is correct |
3 |
Correct |
192 ms |
6484 KB |
Output is correct |
4 |
Correct |
1869 ms |
62904 KB |
Output is correct |
5 |
Correct |
186 ms |
6504 KB |
Output is correct |
6 |
Correct |
178 ms |
6512 KB |
Output is correct |
7 |
Correct |
179 ms |
6480 KB |
Output is correct |
8 |
Correct |
177 ms |
6628 KB |
Output is correct |
9 |
Correct |
178 ms |
6456 KB |
Output is correct |
10 |
Correct |
171 ms |
6512 KB |
Output is correct |
11 |
Correct |
176 ms |
6448 KB |
Output is correct |
12 |
Correct |
182 ms |
6524 KB |
Output is correct |
13 |
Correct |
176 ms |
6468 KB |
Output is correct |
14 |
Correct |
1896 ms |
63124 KB |
Output is correct |
15 |
Correct |
171 ms |
6468 KB |
Output is correct |
16 |
Correct |
1820 ms |
62916 KB |
Output is correct |
17 |
Correct |
1792 ms |
62880 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
17 ms |
868 KB |
Output is correct |
3 |
Correct |
17 ms |
896 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
17 ms |
924 KB |
Output is correct |
17 |
Correct |
176 ms |
6620 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
3 ms |
332 KB |
Output is correct |
28 |
Correct |
1054 ms |
268 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1898 ms |
62924 KB |
Output is correct |
31 |
Correct |
1849 ms |
63044 KB |
Output is correct |
32 |
Correct |
1904 ms |
62788 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1810 ms |
62944 KB |
Output is correct |
35 |
Correct |
1892 ms |
62840 KB |
Output is correct |
36 |
Correct |
1868 ms |
62840 KB |
Output is correct |
37 |
Correct |
1926 ms |
62936 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
187 ms |
6572 KB |
Output is correct |
40 |
Correct |
187 ms |
6500 KB |
Output is correct |
41 |
Correct |
173 ms |
6488 KB |
Output is correct |
42 |
Correct |
174 ms |
6476 KB |
Output is correct |
43 |
Correct |
166 ms |
6468 KB |
Output is correct |
44 |
Correct |
171 ms |
6536 KB |
Output is correct |
45 |
Correct |
171 ms |
6500 KB |
Output is correct |
46 |
Correct |
179 ms |
6468 KB |
Output is correct |
47 |
Correct |
171 ms |
6548 KB |
Output is correct |
48 |
Correct |
180 ms |
6612 KB |
Output is correct |
49 |
Correct |
182 ms |
6448 KB |
Output is correct |
50 |
Correct |
178 ms |
6540 KB |
Output is correct |
51 |
Correct |
1786 ms |
62896 KB |
Output is correct |
52 |
Correct |
1879 ms |
63028 KB |
Output is correct |
53 |
Correct |
1897 ms |
63064 KB |
Output is correct |
54 |
Correct |
177 ms |
6476 KB |
Output is correct |
55 |
Correct |
178 ms |
6428 KB |
Output is correct |
56 |
Correct |
481 ms |
268 KB |
Output is correct |
57 |
Correct |
0 ms |
204 KB |
Output is correct |
58 |
Correct |
174 ms |
6528 KB |
Output is correct |
59 |
Correct |
192 ms |
6484 KB |
Output is correct |
60 |
Correct |
1869 ms |
62904 KB |
Output is correct |
61 |
Correct |
186 ms |
6504 KB |
Output is correct |
62 |
Correct |
178 ms |
6512 KB |
Output is correct |
63 |
Correct |
179 ms |
6480 KB |
Output is correct |
64 |
Correct |
177 ms |
6628 KB |
Output is correct |
65 |
Correct |
178 ms |
6456 KB |
Output is correct |
66 |
Correct |
171 ms |
6512 KB |
Output is correct |
67 |
Correct |
176 ms |
6448 KB |
Output is correct |
68 |
Correct |
182 ms |
6524 KB |
Output is correct |
69 |
Correct |
176 ms |
6468 KB |
Output is correct |
70 |
Correct |
1896 ms |
63124 KB |
Output is correct |
71 |
Correct |
171 ms |
6468 KB |
Output is correct |
72 |
Correct |
1820 ms |
62916 KB |
Output is correct |
73 |
Correct |
1792 ms |
62880 KB |
Output is correct |
74 |
Correct |
1 ms |
204 KB |
Output is correct |
75 |
Correct |
0 ms |
204 KB |
Output is correct |
76 |
Correct |
1 ms |
204 KB |
Output is correct |
77 |
Correct |
0 ms |
204 KB |
Output is correct |
78 |
Correct |
0 ms |
204 KB |
Output is correct |
79 |
Correct |
18 ms |
1228 KB |
Output is correct |
80 |
Correct |
1897 ms |
100176 KB |
Output is correct |
81 |
Correct |
1915 ms |
100088 KB |
Output is correct |
82 |
Correct |
2013 ms |
100108 KB |
Output is correct |
83 |
Correct |
1987 ms |
100032 KB |
Output is correct |
84 |
Correct |
2033 ms |
100096 KB |
Output is correct |
85 |
Correct |
1864 ms |
100156 KB |
Output is correct |
86 |
Correct |
482 ms |
12828 KB |
Output is correct |
87 |
Correct |
1 ms |
204 KB |
Output is correct |