#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 |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
11 ms |
1228 KB |
Output is correct |
3 |
Correct |
12 ms |
1248 KB |
Output is correct |
4 |
Correct |
1 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 |
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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
12 ms |
1312 KB |
Output is correct |
17 |
Correct |
122 ms |
10224 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
468 KB |
Output is correct |
5 |
Correct |
680 ms |
25420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1320 ms |
100024 KB |
Output is correct |
3 |
Correct |
1263 ms |
100044 KB |
Output is correct |
4 |
Correct |
1292 ms |
99980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1320 ms |
100024 KB |
Output is correct |
3 |
Correct |
1263 ms |
100044 KB |
Output is correct |
4 |
Correct |
1292 ms |
99980 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1292 ms |
99972 KB |
Output is correct |
7 |
Correct |
1267 ms |
100064 KB |
Output is correct |
8 |
Correct |
1217 ms |
99980 KB |
Output is correct |
9 |
Correct |
1329 ms |
100004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1320 ms |
100024 KB |
Output is correct |
3 |
Correct |
1263 ms |
100044 KB |
Output is correct |
4 |
Correct |
1292 ms |
99980 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
115 ms |
10284 KB |
Output is correct |
7 |
Correct |
112 ms |
10208 KB |
Output is correct |
8 |
Correct |
115 ms |
10212 KB |
Output is correct |
9 |
Correct |
116 ms |
10168 KB |
Output is correct |
10 |
Correct |
113 ms |
10284 KB |
Output is correct |
11 |
Correct |
116 ms |
10416 KB |
Output is correct |
12 |
Correct |
114 ms |
10248 KB |
Output is correct |
13 |
Correct |
118 ms |
10192 KB |
Output is correct |
14 |
Correct |
114 ms |
10284 KB |
Output is correct |
15 |
Correct |
127 ms |
10240 KB |
Output is correct |
16 |
Correct |
125 ms |
10188 KB |
Output is correct |
17 |
Correct |
116 ms |
10252 KB |
Output is correct |
18 |
Correct |
1231 ms |
100004 KB |
Output is correct |
19 |
Correct |
1345 ms |
100004 KB |
Output is correct |
20 |
Correct |
1338 ms |
100084 KB |
Output is correct |
21 |
Correct |
114 ms |
10188 KB |
Output is correct |
22 |
Correct |
114 ms |
10212 KB |
Output is correct |
23 |
Correct |
314 ms |
12812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
118 ms |
10184 KB |
Output is correct |
3 |
Correct |
135 ms |
10300 KB |
Output is correct |
4 |
Correct |
1391 ms |
100000 KB |
Output is correct |
5 |
Correct |
123 ms |
10192 KB |
Output is correct |
6 |
Correct |
130 ms |
10556 KB |
Output is correct |
7 |
Correct |
122 ms |
10216 KB |
Output is correct |
8 |
Correct |
118 ms |
10236 KB |
Output is correct |
9 |
Correct |
116 ms |
10272 KB |
Output is correct |
10 |
Correct |
115 ms |
10264 KB |
Output is correct |
11 |
Correct |
114 ms |
10232 KB |
Output is correct |
12 |
Correct |
117 ms |
10196 KB |
Output is correct |
13 |
Correct |
133 ms |
10284 KB |
Output is correct |
14 |
Correct |
1285 ms |
100176 KB |
Output is correct |
15 |
Correct |
114 ms |
10204 KB |
Output is correct |
16 |
Correct |
1237 ms |
100028 KB |
Output is correct |
17 |
Correct |
1259 ms |
100088 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
11 ms |
1228 KB |
Output is correct |
3 |
Correct |
12 ms |
1248 KB |
Output is correct |
4 |
Correct |
1 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 |
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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
12 ms |
1312 KB |
Output is correct |
17 |
Correct |
122 ms |
10224 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
300 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
300 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 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 |
468 KB |
Output is correct |
28 |
Correct |
680 ms |
25420 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1320 ms |
100024 KB |
Output is correct |
31 |
Correct |
1263 ms |
100044 KB |
Output is correct |
32 |
Correct |
1292 ms |
99980 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1292 ms |
99972 KB |
Output is correct |
35 |
Correct |
1267 ms |
100064 KB |
Output is correct |
36 |
Correct |
1217 ms |
99980 KB |
Output is correct |
37 |
Correct |
1329 ms |
100004 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
115 ms |
10284 KB |
Output is correct |
40 |
Correct |
112 ms |
10208 KB |
Output is correct |
41 |
Correct |
115 ms |
10212 KB |
Output is correct |
42 |
Correct |
116 ms |
10168 KB |
Output is correct |
43 |
Correct |
113 ms |
10284 KB |
Output is correct |
44 |
Correct |
116 ms |
10416 KB |
Output is correct |
45 |
Correct |
114 ms |
10248 KB |
Output is correct |
46 |
Correct |
118 ms |
10192 KB |
Output is correct |
47 |
Correct |
114 ms |
10284 KB |
Output is correct |
48 |
Correct |
127 ms |
10240 KB |
Output is correct |
49 |
Correct |
125 ms |
10188 KB |
Output is correct |
50 |
Correct |
116 ms |
10252 KB |
Output is correct |
51 |
Correct |
1231 ms |
100004 KB |
Output is correct |
52 |
Correct |
1345 ms |
100004 KB |
Output is correct |
53 |
Correct |
1338 ms |
100084 KB |
Output is correct |
54 |
Correct |
114 ms |
10188 KB |
Output is correct |
55 |
Correct |
114 ms |
10212 KB |
Output is correct |
56 |
Correct |
314 ms |
12812 KB |
Output is correct |
57 |
Correct |
1 ms |
296 KB |
Output is correct |
58 |
Correct |
118 ms |
10184 KB |
Output is correct |
59 |
Correct |
135 ms |
10300 KB |
Output is correct |
60 |
Correct |
1391 ms |
100000 KB |
Output is correct |
61 |
Correct |
123 ms |
10192 KB |
Output is correct |
62 |
Correct |
130 ms |
10556 KB |
Output is correct |
63 |
Correct |
122 ms |
10216 KB |
Output is correct |
64 |
Correct |
118 ms |
10236 KB |
Output is correct |
65 |
Correct |
116 ms |
10272 KB |
Output is correct |
66 |
Correct |
115 ms |
10264 KB |
Output is correct |
67 |
Correct |
114 ms |
10232 KB |
Output is correct |
68 |
Correct |
117 ms |
10196 KB |
Output is correct |
69 |
Correct |
133 ms |
10284 KB |
Output is correct |
70 |
Correct |
1285 ms |
100176 KB |
Output is correct |
71 |
Correct |
114 ms |
10204 KB |
Output is correct |
72 |
Correct |
1237 ms |
100028 KB |
Output is correct |
73 |
Correct |
1259 ms |
100088 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
0 ms |
212 KB |
Output is correct |
77 |
Correct |
0 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
11 ms |
1296 KB |
Output is correct |
80 |
Correct |
1335 ms |
100104 KB |
Output is correct |
81 |
Correct |
1294 ms |
100128 KB |
Output is correct |
82 |
Correct |
1324 ms |
100016 KB |
Output is correct |
83 |
Correct |
1293 ms |
100212 KB |
Output is correct |
84 |
Correct |
1314 ms |
100172 KB |
Output is correct |
85 |
Correct |
1280 ms |
100076 KB |
Output is correct |
86 |
Correct |
311 ms |
12748 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |