#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
const ll inf = (ll)5e18 + 7;
ll n, a, b, l, r, p;
vector<pii> v;
ll gcd(ll c1, ll c2) {
if (!c2) return c1;
return gcd(c2, c1%c2);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> a >> b;
a /= gcd(a, b+1);
p = (inf/b>a ? a*b : inf);
while (n--) {
cin >> l >> r, l%=p, r%=p;
if (l>r) v.push_back({0, r}), v.push_back({l, p-1});
else v.push_back({l, r});
}
sort(v.begin(), v.end());
ll out=0, ma=-1;
for (auto [x,y]:v) out += (ma<x ? y-x+1 : max((ll)0, y-ma)), ma=max(ma, y);
cout << out;
return 0;
}
/*
3 3 3
4 4
7 9
17 18
ans: 4
3 5 10
1 20
50 68
89 98
ans: 31
1 1000000000000000 1000000000000000000
100000 1000000
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
600 KB |
Output is correct |
3 |
Correct |
6 ms |
724 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
600 KB |
Output is correct |
17 |
Correct |
40 ms |
2376 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
277 ms |
16816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
371 ms |
16804 KB |
Output is correct |
3 |
Correct |
369 ms |
16764 KB |
Output is correct |
4 |
Correct |
353 ms |
16756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
371 ms |
16804 KB |
Output is correct |
3 |
Correct |
369 ms |
16764 KB |
Output is correct |
4 |
Correct |
353 ms |
16756 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
376 ms |
16888 KB |
Output is correct |
7 |
Correct |
370 ms |
16852 KB |
Output is correct |
8 |
Correct |
363 ms |
16828 KB |
Output is correct |
9 |
Correct |
394 ms |
16812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
371 ms |
16804 KB |
Output is correct |
3 |
Correct |
369 ms |
16764 KB |
Output is correct |
4 |
Correct |
353 ms |
16756 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
44 ms |
2472 KB |
Output is correct |
7 |
Correct |
40 ms |
2508 KB |
Output is correct |
8 |
Correct |
38 ms |
2484 KB |
Output is correct |
9 |
Correct |
39 ms |
2472 KB |
Output is correct |
10 |
Correct |
36 ms |
2408 KB |
Output is correct |
11 |
Correct |
37 ms |
2512 KB |
Output is correct |
12 |
Correct |
35 ms |
2460 KB |
Output is correct |
13 |
Correct |
39 ms |
2480 KB |
Output is correct |
14 |
Correct |
39 ms |
2484 KB |
Output is correct |
15 |
Correct |
48 ms |
2472 KB |
Output is correct |
16 |
Correct |
40 ms |
2460 KB |
Output is correct |
17 |
Correct |
37 ms |
2412 KB |
Output is correct |
18 |
Correct |
394 ms |
16820 KB |
Output is correct |
19 |
Correct |
401 ms |
16816 KB |
Output is correct |
20 |
Correct |
459 ms |
16780 KB |
Output is correct |
21 |
Correct |
39 ms |
2512 KB |
Output is correct |
22 |
Correct |
37 ms |
2524 KB |
Output is correct |
23 |
Correct |
114 ms |
8632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
40 ms |
2424 KB |
Output is correct |
3 |
Correct |
53 ms |
2456 KB |
Output is correct |
4 |
Correct |
451 ms |
16784 KB |
Output is correct |
5 |
Correct |
40 ms |
2512 KB |
Output is correct |
6 |
Correct |
39 ms |
2476 KB |
Output is correct |
7 |
Correct |
39 ms |
2452 KB |
Output is correct |
8 |
Correct |
40 ms |
2408 KB |
Output is correct |
9 |
Correct |
39 ms |
2416 KB |
Output is correct |
10 |
Correct |
39 ms |
2420 KB |
Output is correct |
11 |
Correct |
39 ms |
2484 KB |
Output is correct |
12 |
Correct |
34 ms |
2512 KB |
Output is correct |
13 |
Correct |
41 ms |
2540 KB |
Output is correct |
14 |
Correct |
412 ms |
16968 KB |
Output is correct |
15 |
Correct |
41 ms |
2512 KB |
Output is correct |
16 |
Correct |
377 ms |
16760 KB |
Output is correct |
17 |
Correct |
381 ms |
16860 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
600 KB |
Output is correct |
3 |
Correct |
6 ms |
724 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
600 KB |
Output is correct |
17 |
Correct |
40 ms |
2376 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |