#include <bits/stdc++.h>
using namespace std;
// Hi
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n;
long long a,b;
cin>>n>>a>>b;
a /= __gcd(a,b+1);
long long max_ans = 1000000000000000001;
long long mod = max_ans;
if (a <= LLONG_MAX / b)mod = a*b;
vector<pair<long long,long long>> q;
for(int i=0;i<n;i++){
long long l,r;
cin>>l>>r;
if(r-l+1 >= mod){
cout << mod << '\n';
return 0;
}
long long ll = l% mod, rr = r% mod;
if(ll <= rr){
q.push_back({ll,rr});
}else {
q.push_back({0,rr});
q.push_back({ll,mod-1});
}
}
sort(q.begin(),q.end());
long long ans = 0,curr_l = q[0].first,curr_r = q[0].second;
for(auto p:q){
if(p.first<= curr_r){
curr_r = max(curr_r,p.second);
}else{
ans += curr_r-curr_l+1;
curr_l = p.first;
curr_r = p.second;
}
}
ans += curr_r-curr_l+1;
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
7 ms |
592 KB |
Output is correct |
3 |
Correct |
6 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
276 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 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 |
1 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 |
1 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 |
5 ms |
592 KB |
Output is correct |
17 |
Correct |
51 ms |
2468 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is 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 |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
353 ms |
16780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
480 ms |
16760 KB |
Output is correct |
3 |
Correct |
478 ms |
16740 KB |
Output is correct |
4 |
Correct |
475 ms |
28556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
480 ms |
16760 KB |
Output is correct |
3 |
Correct |
478 ms |
16740 KB |
Output is correct |
4 |
Correct |
475 ms |
28556 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
475 ms |
29020 KB |
Output is correct |
7 |
Correct |
487 ms |
30412 KB |
Output is correct |
8 |
Correct |
481 ms |
29988 KB |
Output is correct |
9 |
Correct |
513 ms |
30316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
480 ms |
16760 KB |
Output is correct |
3 |
Correct |
478 ms |
16740 KB |
Output is correct |
4 |
Correct |
475 ms |
28556 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
48 ms |
5608 KB |
Output is correct |
7 |
Correct |
54 ms |
5768 KB |
Output is correct |
8 |
Correct |
48 ms |
5712 KB |
Output is correct |
9 |
Correct |
51 ms |
5632 KB |
Output is correct |
10 |
Correct |
47 ms |
5628 KB |
Output is correct |
11 |
Correct |
53 ms |
5620 KB |
Output is correct |
12 |
Correct |
59 ms |
5668 KB |
Output is correct |
13 |
Correct |
51 ms |
5688 KB |
Output is correct |
14 |
Correct |
48 ms |
5688 KB |
Output is correct |
15 |
Correct |
53 ms |
5720 KB |
Output is correct |
16 |
Correct |
58 ms |
5612 KB |
Output is correct |
17 |
Correct |
59 ms |
5612 KB |
Output is correct |
18 |
Correct |
486 ms |
30324 KB |
Output is correct |
19 |
Correct |
520 ms |
30500 KB |
Output is correct |
20 |
Correct |
519 ms |
30360 KB |
Output is correct |
21 |
Correct |
52 ms |
5684 KB |
Output is correct |
22 |
Correct |
46 ms |
5652 KB |
Output is correct |
23 |
Correct |
150 ms |
18480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
51 ms |
2472 KB |
Output is correct |
3 |
Correct |
50 ms |
2512 KB |
Output is correct |
4 |
Correct |
560 ms |
16824 KB |
Output is correct |
5 |
Correct |
50 ms |
5620 KB |
Output is correct |
6 |
Correct |
51 ms |
5668 KB |
Output is correct |
7 |
Correct |
51 ms |
5660 KB |
Output is correct |
8 |
Correct |
58 ms |
5656 KB |
Output is correct |
9 |
Correct |
50 ms |
5692 KB |
Output is correct |
10 |
Correct |
51 ms |
5684 KB |
Output is correct |
11 |
Correct |
63 ms |
5656 KB |
Output is correct |
12 |
Correct |
49 ms |
5624 KB |
Output is correct |
13 |
Correct |
51 ms |
5692 KB |
Output is correct |
14 |
Correct |
519 ms |
28344 KB |
Output is correct |
15 |
Correct |
59 ms |
5692 KB |
Output is correct |
16 |
Correct |
486 ms |
28400 KB |
Output is correct |
17 |
Correct |
511 ms |
28320 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
7 ms |
592 KB |
Output is correct |
3 |
Correct |
6 ms |
592 KB |
Output is correct |
4 |
Correct |
1 ms |
276 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 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 |
1 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 |
1 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 |
5 ms |
592 KB |
Output is correct |
17 |
Correct |
51 ms |
2468 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
353 ms |
16780 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
480 ms |
16760 KB |
Output is correct |
31 |
Correct |
478 ms |
16740 KB |
Output is correct |
32 |
Correct |
475 ms |
28556 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
475 ms |
29020 KB |
Output is correct |
35 |
Correct |
487 ms |
30412 KB |
Output is correct |
36 |
Correct |
481 ms |
29988 KB |
Output is correct |
37 |
Correct |
513 ms |
30316 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
48 ms |
5608 KB |
Output is correct |
40 |
Correct |
54 ms |
5768 KB |
Output is correct |
41 |
Correct |
48 ms |
5712 KB |
Output is correct |
42 |
Correct |
51 ms |
5632 KB |
Output is correct |
43 |
Correct |
47 ms |
5628 KB |
Output is correct |
44 |
Correct |
53 ms |
5620 KB |
Output is correct |
45 |
Correct |
59 ms |
5668 KB |
Output is correct |
46 |
Correct |
51 ms |
5688 KB |
Output is correct |
47 |
Correct |
48 ms |
5688 KB |
Output is correct |
48 |
Correct |
53 ms |
5720 KB |
Output is correct |
49 |
Correct |
58 ms |
5612 KB |
Output is correct |
50 |
Correct |
59 ms |
5612 KB |
Output is correct |
51 |
Correct |
486 ms |
30324 KB |
Output is correct |
52 |
Correct |
520 ms |
30500 KB |
Output is correct |
53 |
Correct |
519 ms |
30360 KB |
Output is correct |
54 |
Correct |
52 ms |
5684 KB |
Output is correct |
55 |
Correct |
46 ms |
5652 KB |
Output is correct |
56 |
Correct |
150 ms |
18480 KB |
Output is correct |
57 |
Correct |
1 ms |
204 KB |
Output is correct |
58 |
Correct |
51 ms |
2472 KB |
Output is correct |
59 |
Correct |
50 ms |
2512 KB |
Output is correct |
60 |
Correct |
560 ms |
16824 KB |
Output is correct |
61 |
Correct |
50 ms |
5620 KB |
Output is correct |
62 |
Correct |
51 ms |
5668 KB |
Output is correct |
63 |
Correct |
51 ms |
5660 KB |
Output is correct |
64 |
Correct |
58 ms |
5656 KB |
Output is correct |
65 |
Correct |
50 ms |
5692 KB |
Output is correct |
66 |
Correct |
51 ms |
5684 KB |
Output is correct |
67 |
Correct |
63 ms |
5656 KB |
Output is correct |
68 |
Correct |
49 ms |
5624 KB |
Output is correct |
69 |
Correct |
51 ms |
5692 KB |
Output is correct |
70 |
Correct |
519 ms |
28344 KB |
Output is correct |
71 |
Correct |
59 ms |
5692 KB |
Output is correct |
72 |
Correct |
486 ms |
28400 KB |
Output is correct |
73 |
Correct |
511 ms |
28320 KB |
Output is correct |
74 |
Correct |
1 ms |
204 KB |
Output is correct |
75 |
Correct |
1 ms |
316 KB |
Output is correct |
76 |
Correct |
1 ms |
204 KB |
Output is correct |
77 |
Correct |
1 ms |
204 KB |
Output is correct |
78 |
Correct |
1 ms |
308 KB |
Output is correct |
79 |
Correct |
6 ms |
964 KB |
Output is correct |
80 |
Correct |
544 ms |
32804 KB |
Output is correct |
81 |
Correct |
588 ms |
32868 KB |
Output is correct |
82 |
Correct |
539 ms |
32824 KB |
Output is correct |
83 |
Correct |
521 ms |
32788 KB |
Output is correct |
84 |
Correct |
514 ms |
32812 KB |
Output is correct |
85 |
Correct |
524 ms |
32884 KB |
Output is correct |
86 |
Correct |
150 ms |
18480 KB |
Output is correct |
87 |
Correct |
1 ms |
204 KB |
Output is correct |