#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll n,A,B,mod,ans;
vector<pll> v;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>A>>B;
A=A/__gcd(A,B+1);
if (A>2e18/B || A>2e18/B) mod=2e18;
else mod=A*B;
while (n--) {
ll l,r;
cin>>l>>r;
if (r-l+1>=mod) {
cout<<mod;
return 0;
}
l%=mod;
r%=mod;
if (l<=r) v.push_back(pll(l,r));
else v.push_back(pll(l,mod-1)), v.push_back(pll(0,r));
}
sort(v.begin(),v.end());
ll mmax=-1;
for (auto s : v) {
if (mmax<s.first) {
ans+=(s.second-s.first+1);
mmax=s.second;
} else if (s.first<=mmax && mmax<s.second) {
ans+=(s.second-mmax);
mmax=s.second;
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
972 KB |
Output is correct |
3 |
Correct |
4 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
984 KB |
Output is correct |
17 |
Correct |
45 ms |
5320 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 |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
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 |
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 |
283 ms |
16904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
399 ms |
17648 KB |
Output is correct |
3 |
Correct |
378 ms |
17380 KB |
Output is correct |
4 |
Correct |
375 ms |
17312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
399 ms |
17648 KB |
Output is correct |
3 |
Correct |
378 ms |
17380 KB |
Output is correct |
4 |
Correct |
375 ms |
17312 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
399 ms |
17276 KB |
Output is correct |
7 |
Correct |
391 ms |
17248 KB |
Output is correct |
8 |
Correct |
421 ms |
17176 KB |
Output is correct |
9 |
Correct |
402 ms |
17200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
399 ms |
17648 KB |
Output is correct |
3 |
Correct |
378 ms |
17380 KB |
Output is correct |
4 |
Correct |
375 ms |
17312 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
39 ms |
2788 KB |
Output is correct |
7 |
Correct |
42 ms |
2824 KB |
Output is correct |
8 |
Correct |
40 ms |
5236 KB |
Output is correct |
9 |
Correct |
40 ms |
5160 KB |
Output is correct |
10 |
Correct |
42 ms |
5124 KB |
Output is correct |
11 |
Correct |
41 ms |
5148 KB |
Output is correct |
12 |
Correct |
38 ms |
5180 KB |
Output is correct |
13 |
Correct |
43 ms |
5104 KB |
Output is correct |
14 |
Correct |
53 ms |
5108 KB |
Output is correct |
15 |
Correct |
46 ms |
5160 KB |
Output is correct |
16 |
Correct |
41 ms |
5132 KB |
Output is correct |
17 |
Correct |
40 ms |
5192 KB |
Output is correct |
18 |
Correct |
392 ms |
17048 KB |
Output is correct |
19 |
Correct |
396 ms |
16956 KB |
Output is correct |
20 |
Correct |
415 ms |
16992 KB |
Output is correct |
21 |
Correct |
54 ms |
5188 KB |
Output is correct |
22 |
Correct |
38 ms |
5172 KB |
Output is correct |
23 |
Correct |
121 ms |
11804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
52 ms |
2776 KB |
Output is correct |
3 |
Correct |
51 ms |
2852 KB |
Output is correct |
4 |
Correct |
422 ms |
17336 KB |
Output is correct |
5 |
Correct |
41 ms |
2884 KB |
Output is correct |
6 |
Correct |
44 ms |
2808 KB |
Output is correct |
7 |
Correct |
41 ms |
2844 KB |
Output is correct |
8 |
Correct |
46 ms |
2784 KB |
Output is correct |
9 |
Correct |
45 ms |
2792 KB |
Output is correct |
10 |
Correct |
46 ms |
2812 KB |
Output is correct |
11 |
Correct |
51 ms |
2884 KB |
Output is correct |
12 |
Correct |
36 ms |
2816 KB |
Output is correct |
13 |
Correct |
41 ms |
2824 KB |
Output is correct |
14 |
Correct |
418 ms |
17284 KB |
Output is correct |
15 |
Correct |
42 ms |
2760 KB |
Output is correct |
16 |
Correct |
386 ms |
16860 KB |
Output is correct |
17 |
Correct |
375 ms |
16940 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
972 KB |
Output is correct |
3 |
Correct |
4 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
984 KB |
Output is correct |
17 |
Correct |
45 ms |
5320 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 |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
283 ms |
16904 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
399 ms |
17648 KB |
Output is correct |
31 |
Correct |
378 ms |
17380 KB |
Output is correct |
32 |
Correct |
375 ms |
17312 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
399 ms |
17276 KB |
Output is correct |
35 |
Correct |
391 ms |
17248 KB |
Output is correct |
36 |
Correct |
421 ms |
17176 KB |
Output is correct |
37 |
Correct |
402 ms |
17200 KB |
Output is correct |
38 |
Correct |
0 ms |
320 KB |
Output is correct |
39 |
Correct |
39 ms |
2788 KB |
Output is correct |
40 |
Correct |
42 ms |
2824 KB |
Output is correct |
41 |
Correct |
40 ms |
5236 KB |
Output is correct |
42 |
Correct |
40 ms |
5160 KB |
Output is correct |
43 |
Correct |
42 ms |
5124 KB |
Output is correct |
44 |
Correct |
41 ms |
5148 KB |
Output is correct |
45 |
Correct |
38 ms |
5180 KB |
Output is correct |
46 |
Correct |
43 ms |
5104 KB |
Output is correct |
47 |
Correct |
53 ms |
5108 KB |
Output is correct |
48 |
Correct |
46 ms |
5160 KB |
Output is correct |
49 |
Correct |
41 ms |
5132 KB |
Output is correct |
50 |
Correct |
40 ms |
5192 KB |
Output is correct |
51 |
Correct |
392 ms |
17048 KB |
Output is correct |
52 |
Correct |
396 ms |
16956 KB |
Output is correct |
53 |
Correct |
415 ms |
16992 KB |
Output is correct |
54 |
Correct |
54 ms |
5188 KB |
Output is correct |
55 |
Correct |
38 ms |
5172 KB |
Output is correct |
56 |
Correct |
121 ms |
11804 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
52 ms |
2776 KB |
Output is correct |
59 |
Correct |
51 ms |
2852 KB |
Output is correct |
60 |
Correct |
422 ms |
17336 KB |
Output is correct |
61 |
Correct |
41 ms |
2884 KB |
Output is correct |
62 |
Correct |
44 ms |
2808 KB |
Output is correct |
63 |
Correct |
41 ms |
2844 KB |
Output is correct |
64 |
Correct |
46 ms |
2784 KB |
Output is correct |
65 |
Correct |
45 ms |
2792 KB |
Output is correct |
66 |
Correct |
46 ms |
2812 KB |
Output is correct |
67 |
Correct |
51 ms |
2884 KB |
Output is correct |
68 |
Correct |
36 ms |
2816 KB |
Output is correct |
69 |
Correct |
41 ms |
2824 KB |
Output is correct |
70 |
Correct |
418 ms |
17284 KB |
Output is correct |
71 |
Correct |
42 ms |
2760 KB |
Output is correct |
72 |
Correct |
386 ms |
16860 KB |
Output is correct |
73 |
Correct |
375 ms |
16940 KB |
Output is correct |
74 |
Correct |
0 ms |
340 KB |
Output is correct |
75 |
Correct |
0 ms |
212 KB |
Output is correct |
76 |
Correct |
1 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 |
4 ms |
1008 KB |
Output is correct |
80 |
Correct |
439 ms |
17072 KB |
Output is correct |
81 |
Correct |
431 ms |
17136 KB |
Output is correct |
82 |
Correct |
399 ms |
16944 KB |
Output is correct |
83 |
Correct |
399 ms |
17120 KB |
Output is correct |
84 |
Correct |
407 ms |
16944 KB |
Output is correct |
85 |
Correct |
427 ms |
17136 KB |
Output is correct |
86 |
Correct |
117 ms |
10972 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |