#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
int n,curr;
ll a,b,ans,l,r,cc,pre=-1;
lll cyc;
map<ll,int> todo;
int main(){
cin>>n>>a>>b;
cyc=a/__gcd(a,b+1);
cyc*=b;
if (cyc>=LLONG_MAX) cc=LLONG_MAX;
else cc=cyc;
for (int i=1;i<=n;i++){
cin>>l>>r;
if (r-l>=cc){
cout<<cc<<"\n";
return 0;
}
if (l/cc!=r/cc){
todo[l%cc]++;
todo[cc]--;
todo[0]++;
todo[r%cc+1]--;
}else{
todo[l%cc]++;
todo[r%cc+1]--;
}
}
for (auto i:todo){
if (curr) ans+=i.first-pre;
curr+=i.second;
pre=i.first;
}
cout<<ans<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
19 ms |
1240 KB |
Output is correct |
3 |
Correct |
15 ms |
1240 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 |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
16 ms |
1212 KB |
Output is correct |
17 |
Correct |
155 ms |
10292 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
292 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
935 ms |
25496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1645 ms |
100092 KB |
Output is correct |
3 |
Correct |
1653 ms |
100012 KB |
Output is correct |
4 |
Correct |
1715 ms |
100048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1645 ms |
100092 KB |
Output is correct |
3 |
Correct |
1653 ms |
100012 KB |
Output is correct |
4 |
Correct |
1715 ms |
100048 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1579 ms |
100032 KB |
Output is correct |
7 |
Correct |
1592 ms |
100100 KB |
Output is correct |
8 |
Correct |
1612 ms |
100136 KB |
Output is correct |
9 |
Correct |
1764 ms |
100012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1645 ms |
100092 KB |
Output is correct |
3 |
Correct |
1653 ms |
100012 KB |
Output is correct |
4 |
Correct |
1715 ms |
100048 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
151 ms |
10284 KB |
Output is correct |
7 |
Correct |
148 ms |
10188 KB |
Output is correct |
8 |
Correct |
145 ms |
10188 KB |
Output is correct |
9 |
Correct |
161 ms |
10184 KB |
Output is correct |
10 |
Correct |
147 ms |
10180 KB |
Output is correct |
11 |
Correct |
154 ms |
10248 KB |
Output is correct |
12 |
Correct |
144 ms |
10260 KB |
Output is correct |
13 |
Correct |
191 ms |
10228 KB |
Output is correct |
14 |
Correct |
142 ms |
10184 KB |
Output is correct |
15 |
Correct |
159 ms |
10476 KB |
Output is correct |
16 |
Correct |
159 ms |
10180 KB |
Output is correct |
17 |
Correct |
201 ms |
10240 KB |
Output is correct |
18 |
Correct |
1560 ms |
100004 KB |
Output is correct |
19 |
Correct |
1650 ms |
100208 KB |
Output is correct |
20 |
Correct |
1692 ms |
100108 KB |
Output is correct |
21 |
Correct |
149 ms |
10252 KB |
Output is correct |
22 |
Correct |
148 ms |
10204 KB |
Output is correct |
23 |
Correct |
420 ms |
12840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
165 ms |
10168 KB |
Output is correct |
3 |
Correct |
155 ms |
10196 KB |
Output is correct |
4 |
Correct |
1677 ms |
99992 KB |
Output is correct |
5 |
Correct |
160 ms |
10308 KB |
Output is correct |
6 |
Correct |
186 ms |
10256 KB |
Output is correct |
7 |
Correct |
162 ms |
10232 KB |
Output is correct |
8 |
Correct |
168 ms |
10188 KB |
Output is correct |
9 |
Correct |
160 ms |
10188 KB |
Output is correct |
10 |
Correct |
160 ms |
10272 KB |
Output is correct |
11 |
Correct |
150 ms |
10232 KB |
Output is correct |
12 |
Correct |
148 ms |
10172 KB |
Output is correct |
13 |
Correct |
167 ms |
10208 KB |
Output is correct |
14 |
Correct |
1810 ms |
100116 KB |
Output is correct |
15 |
Correct |
146 ms |
10184 KB |
Output is correct |
16 |
Correct |
1550 ms |
100116 KB |
Output is correct |
17 |
Correct |
1658 ms |
100060 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
19 ms |
1240 KB |
Output is correct |
3 |
Correct |
15 ms |
1240 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 |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
16 ms |
1212 KB |
Output is correct |
17 |
Correct |
155 ms |
10292 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
304 KB |
Output is correct |
21 |
Correct |
1 ms |
292 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
935 ms |
25496 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1645 ms |
100092 KB |
Output is correct |
31 |
Correct |
1653 ms |
100012 KB |
Output is correct |
32 |
Correct |
1715 ms |
100048 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1579 ms |
100032 KB |
Output is correct |
35 |
Correct |
1592 ms |
100100 KB |
Output is correct |
36 |
Correct |
1612 ms |
100136 KB |
Output is correct |
37 |
Correct |
1764 ms |
100012 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
151 ms |
10284 KB |
Output is correct |
40 |
Correct |
148 ms |
10188 KB |
Output is correct |
41 |
Correct |
145 ms |
10188 KB |
Output is correct |
42 |
Correct |
161 ms |
10184 KB |
Output is correct |
43 |
Correct |
147 ms |
10180 KB |
Output is correct |
44 |
Correct |
154 ms |
10248 KB |
Output is correct |
45 |
Correct |
144 ms |
10260 KB |
Output is correct |
46 |
Correct |
191 ms |
10228 KB |
Output is correct |
47 |
Correct |
142 ms |
10184 KB |
Output is correct |
48 |
Correct |
159 ms |
10476 KB |
Output is correct |
49 |
Correct |
159 ms |
10180 KB |
Output is correct |
50 |
Correct |
201 ms |
10240 KB |
Output is correct |
51 |
Correct |
1560 ms |
100004 KB |
Output is correct |
52 |
Correct |
1650 ms |
100208 KB |
Output is correct |
53 |
Correct |
1692 ms |
100108 KB |
Output is correct |
54 |
Correct |
149 ms |
10252 KB |
Output is correct |
55 |
Correct |
148 ms |
10204 KB |
Output is correct |
56 |
Correct |
420 ms |
12840 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
165 ms |
10168 KB |
Output is correct |
59 |
Correct |
155 ms |
10196 KB |
Output is correct |
60 |
Correct |
1677 ms |
99992 KB |
Output is correct |
61 |
Correct |
160 ms |
10308 KB |
Output is correct |
62 |
Correct |
186 ms |
10256 KB |
Output is correct |
63 |
Correct |
162 ms |
10232 KB |
Output is correct |
64 |
Correct |
168 ms |
10188 KB |
Output is correct |
65 |
Correct |
160 ms |
10188 KB |
Output is correct |
66 |
Correct |
160 ms |
10272 KB |
Output is correct |
67 |
Correct |
150 ms |
10232 KB |
Output is correct |
68 |
Correct |
148 ms |
10172 KB |
Output is correct |
69 |
Correct |
167 ms |
10208 KB |
Output is correct |
70 |
Correct |
1810 ms |
100116 KB |
Output is correct |
71 |
Correct |
146 ms |
10184 KB |
Output is correct |
72 |
Correct |
1550 ms |
100116 KB |
Output is correct |
73 |
Correct |
1658 ms |
100060 KB |
Output is correct |
74 |
Correct |
0 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
308 KB |
Output is correct |
79 |
Correct |
15 ms |
1236 KB |
Output is correct |
80 |
Correct |
1688 ms |
100092 KB |
Output is correct |
81 |
Correct |
1728 ms |
100044 KB |
Output is correct |
82 |
Correct |
1762 ms |
100100 KB |
Output is correct |
83 |
Correct |
1671 ms |
100180 KB |
Output is correct |
84 |
Correct |
1693 ms |
100112 KB |
Output is correct |
85 |
Correct |
1644 ms |
100152 KB |
Output is correct |
86 |
Correct |
433 ms |
12952 KB |
Output is correct |
87 |
Correct |
0 ms |
212 KB |
Output is correct |