#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
int n; ll a, b; cin >> n >> a >> b;
ll p = a / __gcd(a, b + 1) * b; map<ll, int> d;
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]--;
}
ll cnt = 0, pre, ans = 0; d[p];
for (auto &val : d){
if (cnt) ans += val.first - pre;
cnt += val.second; pre = val.first;
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
292 KB |
Output is correct |
2 |
Correct |
17 ms |
1260 KB |
Output is correct |
3 |
Correct |
17 ms |
1284 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
292 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 |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
2 ms |
292 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 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 |
17 ms |
1396 KB |
Output is correct |
17 |
Correct |
174 ms |
8016 KB |
Output is correct |
18 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
292 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
1022 ms |
312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1954 ms |
63044 KB |
Output is correct |
3 |
Correct |
1979 ms |
62980 KB |
Output is correct |
4 |
Correct |
2008 ms |
62944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1954 ms |
63044 KB |
Output is correct |
3 |
Correct |
1979 ms |
62980 KB |
Output is correct |
4 |
Correct |
2008 ms |
62944 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1880 ms |
62908 KB |
Output is correct |
7 |
Correct |
1835 ms |
62924 KB |
Output is correct |
8 |
Correct |
1793 ms |
62924 KB |
Output is correct |
9 |
Correct |
1974 ms |
62952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1954 ms |
63044 KB |
Output is correct |
3 |
Correct |
1979 ms |
62980 KB |
Output is correct |
4 |
Correct |
2008 ms |
62944 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
169 ms |
7624 KB |
Output is correct |
7 |
Correct |
198 ms |
7612 KB |
Output is correct |
8 |
Correct |
171 ms |
7616 KB |
Output is correct |
9 |
Correct |
175 ms |
7736 KB |
Output is correct |
10 |
Correct |
169 ms |
7676 KB |
Output is correct |
11 |
Correct |
167 ms |
7700 KB |
Output is correct |
12 |
Correct |
170 ms |
7620 KB |
Output is correct |
13 |
Correct |
174 ms |
7676 KB |
Output is correct |
14 |
Correct |
176 ms |
7692 KB |
Output is correct |
15 |
Correct |
178 ms |
7636 KB |
Output is correct |
16 |
Correct |
178 ms |
7680 KB |
Output is correct |
17 |
Correct |
198 ms |
7680 KB |
Output is correct |
18 |
Correct |
1879 ms |
63032 KB |
Output is correct |
19 |
Correct |
1865 ms |
62992 KB |
Output is correct |
20 |
Correct |
1856 ms |
63056 KB |
Output is correct |
21 |
Correct |
171 ms |
7236 KB |
Output is correct |
22 |
Correct |
176 ms |
7208 KB |
Output is correct |
23 |
Correct |
475 ms |
1032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
180 ms |
7232 KB |
Output is correct |
3 |
Correct |
177 ms |
7424 KB |
Output is correct |
4 |
Correct |
1838 ms |
62932 KB |
Output is correct |
5 |
Correct |
181 ms |
7120 KB |
Output is correct |
6 |
Correct |
180 ms |
7076 KB |
Output is correct |
7 |
Correct |
179 ms |
7116 KB |
Output is correct |
8 |
Correct |
174 ms |
7164 KB |
Output is correct |
9 |
Correct |
174 ms |
7108 KB |
Output is correct |
10 |
Correct |
172 ms |
7100 KB |
Output is correct |
11 |
Correct |
176 ms |
7076 KB |
Output is correct |
12 |
Correct |
174 ms |
7096 KB |
Output is correct |
13 |
Correct |
202 ms |
7192 KB |
Output is correct |
14 |
Correct |
1912 ms |
62928 KB |
Output is correct |
15 |
Correct |
200 ms |
6984 KB |
Output is correct |
16 |
Correct |
1771 ms |
62916 KB |
Output is correct |
17 |
Correct |
1779 ms |
63156 KB |
Output is correct |
18 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
292 KB |
Output is correct |
2 |
Correct |
17 ms |
1260 KB |
Output is correct |
3 |
Correct |
17 ms |
1284 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
292 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 |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
2 ms |
292 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 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 |
17 ms |
1396 KB |
Output is correct |
17 |
Correct |
174 ms |
8016 KB |
Output is correct |
18 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |