#include <bits/stdc++.h>
using namespace std;
int n;
long long a, b, mod;
long long l, r, last=0, sum = 0;
vector<pair<long long, bool>> vec;
int ctr = 0;
int main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> a >> b; a /= __gcd(a, b+1);
if(a >= 4e18/b) mod = 4e18;
else mod = a*b;
while(n--) {
cin >> l >> r;
if(r-l+1 >= mod) {
cout << mod;
return 0;
}
l %= mod; r %= mod;
if(l <= r) vec.emplace_back(l, 0), vec.emplace_back(r+1, 1);
else vec.emplace_back(l, 0), vec.emplace_back(mod, 1), vec.emplace_back(0, 0), vec.emplace_back(r+1, 1);
}
sort(vec.begin(), vec.end());
for(auto e:vec) {
sum += min(ctr, 1) * (e.first-last);
if(e.second) ctr--;
else ctr++;
last = e.first;
}
cout << sum;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
916 KB |
Output is correct |
3 |
Correct |
4 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
220 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
1240 KB |
Output is correct |
17 |
Correct |
45 ms |
7240 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 |
0 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 |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
372 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
273 ms |
35500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
403 ms |
33232 KB |
Output is correct |
3 |
Correct |
403 ms |
33360 KB |
Output is correct |
4 |
Correct |
403 ms |
68872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
403 ms |
33232 KB |
Output is correct |
3 |
Correct |
403 ms |
33360 KB |
Output is correct |
4 |
Correct |
403 ms |
68872 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
403 ms |
68808 KB |
Output is correct |
7 |
Correct |
397 ms |
68856 KB |
Output is correct |
8 |
Correct |
401 ms |
68756 KB |
Output is correct |
9 |
Correct |
466 ms |
68856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
403 ms |
33232 KB |
Output is correct |
3 |
Correct |
403 ms |
33360 KB |
Output is correct |
4 |
Correct |
403 ms |
68872 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
38 ms |
7264 KB |
Output is correct |
7 |
Correct |
45 ms |
7376 KB |
Output is correct |
8 |
Correct |
38 ms |
7276 KB |
Output is correct |
9 |
Correct |
38 ms |
7224 KB |
Output is correct |
10 |
Correct |
35 ms |
7216 KB |
Output is correct |
11 |
Correct |
38 ms |
7236 KB |
Output is correct |
12 |
Correct |
36 ms |
7228 KB |
Output is correct |
13 |
Correct |
41 ms |
7280 KB |
Output is correct |
14 |
Correct |
35 ms |
7244 KB |
Output is correct |
15 |
Correct |
45 ms |
7216 KB |
Output is correct |
16 |
Correct |
45 ms |
7248 KB |
Output is correct |
17 |
Correct |
36 ms |
7216 KB |
Output is correct |
18 |
Correct |
411 ms |
68744 KB |
Output is correct |
19 |
Correct |
391 ms |
68840 KB |
Output is correct |
20 |
Correct |
507 ms |
68800 KB |
Output is correct |
21 |
Correct |
45 ms |
7288 KB |
Output is correct |
22 |
Correct |
34 ms |
7224 KB |
Output is correct |
23 |
Correct |
106 ms |
26628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
50 ms |
4460 KB |
Output is correct |
3 |
Correct |
42 ms |
7180 KB |
Output is correct |
4 |
Correct |
543 ms |
36960 KB |
Output is correct |
5 |
Correct |
43 ms |
7240 KB |
Output is correct |
6 |
Correct |
44 ms |
7272 KB |
Output is correct |
7 |
Correct |
42 ms |
7252 KB |
Output is correct |
8 |
Correct |
45 ms |
7232 KB |
Output is correct |
9 |
Correct |
42 ms |
7248 KB |
Output is correct |
10 |
Correct |
47 ms |
7244 KB |
Output is correct |
11 |
Correct |
44 ms |
7260 KB |
Output is correct |
12 |
Correct |
38 ms |
7224 KB |
Output is correct |
13 |
Correct |
51 ms |
7232 KB |
Output is correct |
14 |
Correct |
505 ms |
36980 KB |
Output is correct |
15 |
Correct |
45 ms |
7196 KB |
Output is correct |
16 |
Correct |
378 ms |
68828 KB |
Output is correct |
17 |
Correct |
397 ms |
68752 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
916 KB |
Output is correct |
3 |
Correct |
4 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
220 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
1240 KB |
Output is correct |
17 |
Correct |
45 ms |
7240 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
372 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
273 ms |
35500 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
403 ms |
33232 KB |
Output is correct |
31 |
Correct |
403 ms |
33360 KB |
Output is correct |
32 |
Correct |
403 ms |
68872 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
403 ms |
68808 KB |
Output is correct |
35 |
Correct |
397 ms |
68856 KB |
Output is correct |
36 |
Correct |
401 ms |
68756 KB |
Output is correct |
37 |
Correct |
466 ms |
68856 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
38 ms |
7264 KB |
Output is correct |
40 |
Correct |
45 ms |
7376 KB |
Output is correct |
41 |
Correct |
38 ms |
7276 KB |
Output is correct |
42 |
Correct |
38 ms |
7224 KB |
Output is correct |
43 |
Correct |
35 ms |
7216 KB |
Output is correct |
44 |
Correct |
38 ms |
7236 KB |
Output is correct |
45 |
Correct |
36 ms |
7228 KB |
Output is correct |
46 |
Correct |
41 ms |
7280 KB |
Output is correct |
47 |
Correct |
35 ms |
7244 KB |
Output is correct |
48 |
Correct |
45 ms |
7216 KB |
Output is correct |
49 |
Correct |
45 ms |
7248 KB |
Output is correct |
50 |
Correct |
36 ms |
7216 KB |
Output is correct |
51 |
Correct |
411 ms |
68744 KB |
Output is correct |
52 |
Correct |
391 ms |
68840 KB |
Output is correct |
53 |
Correct |
507 ms |
68800 KB |
Output is correct |
54 |
Correct |
45 ms |
7288 KB |
Output is correct |
55 |
Correct |
34 ms |
7224 KB |
Output is correct |
56 |
Correct |
106 ms |
26628 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
50 ms |
4460 KB |
Output is correct |
59 |
Correct |
42 ms |
7180 KB |
Output is correct |
60 |
Correct |
543 ms |
36960 KB |
Output is correct |
61 |
Correct |
43 ms |
7240 KB |
Output is correct |
62 |
Correct |
44 ms |
7272 KB |
Output is correct |
63 |
Correct |
42 ms |
7252 KB |
Output is correct |
64 |
Correct |
45 ms |
7232 KB |
Output is correct |
65 |
Correct |
42 ms |
7248 KB |
Output is correct |
66 |
Correct |
47 ms |
7244 KB |
Output is correct |
67 |
Correct |
44 ms |
7260 KB |
Output is correct |
68 |
Correct |
38 ms |
7224 KB |
Output is correct |
69 |
Correct |
51 ms |
7232 KB |
Output is correct |
70 |
Correct |
505 ms |
36980 KB |
Output is correct |
71 |
Correct |
45 ms |
7196 KB |
Output is correct |
72 |
Correct |
378 ms |
68828 KB |
Output is correct |
73 |
Correct |
397 ms |
68752 KB |
Output is correct |
74 |
Correct |
1 ms |
316 KB |
Output is correct |
75 |
Correct |
0 ms |
212 KB |
Output is correct |
76 |
Correct |
0 ms |
212 KB |
Output is correct |
77 |
Correct |
0 ms |
316 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
4 ms |
1240 KB |
Output is correct |
80 |
Correct |
554 ms |
68824 KB |
Output is correct |
81 |
Correct |
555 ms |
68956 KB |
Output is correct |
82 |
Correct |
489 ms |
68884 KB |
Output is correct |
83 |
Correct |
471 ms |
68992 KB |
Output is correct |
84 |
Correct |
483 ms |
68836 KB |
Output is correct |
85 |
Correct |
494 ms |
68812 KB |
Output is correct |
86 |
Correct |
122 ms |
26712 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |