#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
const lint LNF = 2e18;
int n;
lint A, B;
lint gcd(lint a, lint b){ return (b==0 ? a : gcd(b, a%b)); }
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>A>>B;
lint g = gcd(A, B+1), a=A/g;
lint T = LNF;
if(a<=LNF/B) T = a*B;
map<lint, int> mp;
for(int i=1; i<=n; i++){
lint l,r; cin>>l>>r;
if(r-l+1>=T) mp[0]++, mp[T]--;
else{
l%=T, r%=T;
if(l<=r) mp[l]++, mp[r+1]--;
else mp[0]++, mp[r+1]--, mp[l]++, mp[T]--;
}
}
mp[T] = 0;
lint xp = 0, cnt = 0, ans = 0;
for(auto p:mp){
lint x = p.first;
if(cnt>0) ans += x-xp;
cnt+=p.second;
xp = x;
}
cout<<ans<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
10 ms |
1408 KB |
Output is correct |
3 |
Correct |
8 ms |
1408 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
7 ms |
1408 KB |
Output is correct |
17 |
Correct |
73 ms |
10360 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
294 ms |
6008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
758 ms |
71340 KB |
Output is correct |
3 |
Correct |
800 ms |
100232 KB |
Output is correct |
4 |
Correct |
880 ms |
100216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
758 ms |
71340 KB |
Output is correct |
3 |
Correct |
800 ms |
100232 KB |
Output is correct |
4 |
Correct |
880 ms |
100216 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
844 ms |
100088 KB |
Output is correct |
7 |
Correct |
791 ms |
100192 KB |
Output is correct |
8 |
Correct |
842 ms |
100104 KB |
Output is correct |
9 |
Correct |
896 ms |
100044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
758 ms |
71340 KB |
Output is correct |
3 |
Correct |
800 ms |
100232 KB |
Output is correct |
4 |
Correct |
880 ms |
100216 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
69 ms |
10376 KB |
Output is correct |
7 |
Correct |
68 ms |
10360 KB |
Output is correct |
8 |
Correct |
96 ms |
10360 KB |
Output is correct |
9 |
Correct |
86 ms |
10360 KB |
Output is correct |
10 |
Correct |
75 ms |
10260 KB |
Output is correct |
11 |
Correct |
67 ms |
10360 KB |
Output is correct |
12 |
Correct |
78 ms |
10360 KB |
Output is correct |
13 |
Correct |
76 ms |
10364 KB |
Output is correct |
14 |
Correct |
106 ms |
10360 KB |
Output is correct |
15 |
Correct |
78 ms |
10360 KB |
Output is correct |
16 |
Correct |
78 ms |
10264 KB |
Output is correct |
17 |
Correct |
80 ms |
10260 KB |
Output is correct |
18 |
Correct |
857 ms |
100152 KB |
Output is correct |
19 |
Correct |
837 ms |
100232 KB |
Output is correct |
20 |
Correct |
877 ms |
100132 KB |
Output is correct |
21 |
Correct |
74 ms |
10364 KB |
Output is correct |
22 |
Correct |
85 ms |
10256 KB |
Output is correct |
23 |
Correct |
159 ms |
12920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
77 ms |
10340 KB |
Output is correct |
3 |
Correct |
92 ms |
10360 KB |
Output is correct |
4 |
Correct |
881 ms |
100092 KB |
Output is correct |
5 |
Correct |
82 ms |
10360 KB |
Output is correct |
6 |
Correct |
92 ms |
10360 KB |
Output is correct |
7 |
Correct |
87 ms |
10360 KB |
Output is correct |
8 |
Correct |
74 ms |
10360 KB |
Output is correct |
9 |
Correct |
84 ms |
10360 KB |
Output is correct |
10 |
Correct |
81 ms |
10360 KB |
Output is correct |
11 |
Correct |
71 ms |
10360 KB |
Output is correct |
12 |
Correct |
88 ms |
10360 KB |
Output is correct |
13 |
Correct |
90 ms |
10360 KB |
Output is correct |
14 |
Correct |
907 ms |
100088 KB |
Output is correct |
15 |
Correct |
70 ms |
10360 KB |
Output is correct |
16 |
Correct |
800 ms |
82856 KB |
Output is correct |
17 |
Correct |
857 ms |
100212 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
10 ms |
1408 KB |
Output is correct |
3 |
Correct |
8 ms |
1408 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
7 ms |
1408 KB |
Output is correct |
17 |
Correct |
73 ms |
10360 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
512 KB |
Output is correct |
26 |
Correct |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
294 ms |
6008 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
758 ms |
71340 KB |
Output is correct |
31 |
Correct |
800 ms |
100232 KB |
Output is correct |
32 |
Correct |
880 ms |
100216 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
844 ms |
100088 KB |
Output is correct |
35 |
Correct |
791 ms |
100192 KB |
Output is correct |
36 |
Correct |
842 ms |
100104 KB |
Output is correct |
37 |
Correct |
896 ms |
100044 KB |
Output is correct |
38 |
Correct |
0 ms |
384 KB |
Output is correct |
39 |
Correct |
69 ms |
10376 KB |
Output is correct |
40 |
Correct |
68 ms |
10360 KB |
Output is correct |
41 |
Correct |
96 ms |
10360 KB |
Output is correct |
42 |
Correct |
86 ms |
10360 KB |
Output is correct |
43 |
Correct |
75 ms |
10260 KB |
Output is correct |
44 |
Correct |
67 ms |
10360 KB |
Output is correct |
45 |
Correct |
78 ms |
10360 KB |
Output is correct |
46 |
Correct |
76 ms |
10364 KB |
Output is correct |
47 |
Correct |
106 ms |
10360 KB |
Output is correct |
48 |
Correct |
78 ms |
10360 KB |
Output is correct |
49 |
Correct |
78 ms |
10264 KB |
Output is correct |
50 |
Correct |
80 ms |
10260 KB |
Output is correct |
51 |
Correct |
857 ms |
100152 KB |
Output is correct |
52 |
Correct |
837 ms |
100232 KB |
Output is correct |
53 |
Correct |
877 ms |
100132 KB |
Output is correct |
54 |
Correct |
74 ms |
10364 KB |
Output is correct |
55 |
Correct |
85 ms |
10256 KB |
Output is correct |
56 |
Correct |
159 ms |
12920 KB |
Output is correct |
57 |
Correct |
1 ms |
384 KB |
Output is correct |
58 |
Correct |
77 ms |
10340 KB |
Output is correct |
59 |
Correct |
92 ms |
10360 KB |
Output is correct |
60 |
Correct |
881 ms |
100092 KB |
Output is correct |
61 |
Correct |
82 ms |
10360 KB |
Output is correct |
62 |
Correct |
92 ms |
10360 KB |
Output is correct |
63 |
Correct |
87 ms |
10360 KB |
Output is correct |
64 |
Correct |
74 ms |
10360 KB |
Output is correct |
65 |
Correct |
84 ms |
10360 KB |
Output is correct |
66 |
Correct |
81 ms |
10360 KB |
Output is correct |
67 |
Correct |
71 ms |
10360 KB |
Output is correct |
68 |
Correct |
88 ms |
10360 KB |
Output is correct |
69 |
Correct |
90 ms |
10360 KB |
Output is correct |
70 |
Correct |
907 ms |
100088 KB |
Output is correct |
71 |
Correct |
70 ms |
10360 KB |
Output is correct |
72 |
Correct |
800 ms |
82856 KB |
Output is correct |
73 |
Correct |
857 ms |
100212 KB |
Output is correct |
74 |
Correct |
1 ms |
384 KB |
Output is correct |
75 |
Correct |
1 ms |
384 KB |
Output is correct |
76 |
Correct |
1 ms |
384 KB |
Output is correct |
77 |
Correct |
0 ms |
384 KB |
Output is correct |
78 |
Correct |
1 ms |
288 KB |
Output is correct |
79 |
Correct |
7 ms |
1408 KB |
Output is correct |
80 |
Correct |
850 ms |
83448 KB |
Output is correct |
81 |
Correct |
846 ms |
83508 KB |
Output is correct |
82 |
Correct |
906 ms |
83568 KB |
Output is correct |
83 |
Correct |
906 ms |
83460 KB |
Output is correct |
84 |
Correct |
914 ms |
83532 KB |
Output is correct |
85 |
Correct |
885 ms |
100064 KB |
Output is correct |
86 |
Correct |
149 ms |
12920 KB |
Output is correct |
87 |
Correct |
1 ms |
384 KB |
Output is correct |