#include <bits/stdc++.h>
using namespace std;
struct interv{
long long l, r;
bool operator < (const interv &aux)const{
if(l != aux.l) return l < aux.l;
return r < aux.r;
}
};
interv a[2000005];
int n;
long long A, B;
int main()
{
cin >> n >> A >> B;
long long cm = A / __gcd(A, B + 1);
double lg1 = log2(cm), lg2 = log2((double)B);
long long prod = 0;
if(lg1 + lg2 <= 63) prod = 1LL * cm * B;
int m = n;
for(int i = 1; i <= n ; ++i){
cin >> a[i].l >> a[i].r;
if(prod != 0){
if(a[i].r - a[i].l + 1 >= prod){
a[i].l = 0; a[i].r = prod - 1;
continue ;
}
a[i].l %= prod, a[i].r %= prod;
if(a[i].r < a[i].l) a[++m].l = 0, a[m].r = a[i].r, a[i].r = prod - 1;
}
}
n = m;
sort(a + 1, a + n + 1);
long long Sol = 0, l = a[1].l, r = a[1].r;
for(int i = 2; i <= n ; ++i){
if(r < a[i].l){
Sol = Sol + (r - l + 1);
l = a[i].l; r = a[i].r;
}
else r = max(r, a[i].r);
}
Sol = Sol + (r - l + 1);
cout << Sol;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
40 ms |
888 KB |
Output is correct |
3 |
Correct |
28 ms |
888 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
30 ms |
888 KB |
Output is correct |
17 |
Correct |
273 ms |
5496 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
448 KB |
Output is correct |
5 |
Correct |
1863 ms |
23972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2654 ms |
27716 KB |
Output is correct |
3 |
Correct |
2646 ms |
27996 KB |
Output is correct |
4 |
Correct |
2660 ms |
26664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2654 ms |
27716 KB |
Output is correct |
3 |
Correct |
2646 ms |
27996 KB |
Output is correct |
4 |
Correct |
2660 ms |
26664 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2640 ms |
26824 KB |
Output is correct |
7 |
Correct |
2625 ms |
26820 KB |
Output is correct |
8 |
Correct |
2859 ms |
26544 KB |
Output is correct |
9 |
Correct |
2693 ms |
53196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2654 ms |
27716 KB |
Output is correct |
3 |
Correct |
2646 ms |
27996 KB |
Output is correct |
4 |
Correct |
2660 ms |
26664 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
265 ms |
5556 KB |
Output is correct |
7 |
Correct |
284 ms |
5712 KB |
Output is correct |
8 |
Correct |
264 ms |
5756 KB |
Output is correct |
9 |
Correct |
270 ms |
5624 KB |
Output is correct |
10 |
Correct |
267 ms |
5628 KB |
Output is correct |
11 |
Correct |
269 ms |
5724 KB |
Output is correct |
12 |
Correct |
268 ms |
5624 KB |
Output is correct |
13 |
Correct |
268 ms |
5752 KB |
Output is correct |
14 |
Correct |
280 ms |
5676 KB |
Output is correct |
15 |
Correct |
273 ms |
5596 KB |
Output is correct |
16 |
Correct |
269 ms |
5656 KB |
Output is correct |
17 |
Correct |
272 ms |
5624 KB |
Output is correct |
18 |
Correct |
2636 ms |
26632 KB |
Output is correct |
19 |
Correct |
2617 ms |
26668 KB |
Output is correct |
20 |
Correct |
2668 ms |
26556 KB |
Output is correct |
21 |
Correct |
267 ms |
5624 KB |
Output is correct |
22 |
Correct |
262 ms |
5624 KB |
Output is correct |
23 |
Correct |
919 ms |
18412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
266 ms |
5580 KB |
Output is correct |
3 |
Correct |
267 ms |
5612 KB |
Output is correct |
4 |
Correct |
2696 ms |
28076 KB |
Output is correct |
5 |
Correct |
269 ms |
5684 KB |
Output is correct |
6 |
Correct |
267 ms |
5680 KB |
Output is correct |
7 |
Correct |
278 ms |
5628 KB |
Output is correct |
8 |
Correct |
268 ms |
5680 KB |
Output is correct |
9 |
Correct |
267 ms |
5624 KB |
Output is correct |
10 |
Correct |
270 ms |
5624 KB |
Output is correct |
11 |
Correct |
272 ms |
5544 KB |
Output is correct |
12 |
Correct |
261 ms |
5624 KB |
Output is correct |
13 |
Correct |
269 ms |
5600 KB |
Output is correct |
14 |
Correct |
2713 ms |
28188 KB |
Output is correct |
15 |
Correct |
272 ms |
5624 KB |
Output is correct |
16 |
Correct |
2671 ms |
53220 KB |
Output is correct |
17 |
Correct |
2622 ms |
53212 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
40 ms |
888 KB |
Output is correct |
3 |
Correct |
28 ms |
888 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
30 ms |
888 KB |
Output is correct |
17 |
Correct |
273 ms |
5496 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
256 KB |
Output is correct |
24 |
Correct |
2 ms |
256 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
448 KB |
Output is correct |
28 |
Correct |
1863 ms |
23972 KB |
Output is correct |
29 |
Correct |
2 ms |
256 KB |
Output is correct |
30 |
Correct |
2654 ms |
27716 KB |
Output is correct |
31 |
Correct |
2646 ms |
27996 KB |
Output is correct |
32 |
Correct |
2660 ms |
26664 KB |
Output is correct |
33 |
Correct |
2 ms |
256 KB |
Output is correct |
34 |
Correct |
2640 ms |
26824 KB |
Output is correct |
35 |
Correct |
2625 ms |
26820 KB |
Output is correct |
36 |
Correct |
2859 ms |
26544 KB |
Output is correct |
37 |
Correct |
2693 ms |
53196 KB |
Output is correct |
38 |
Correct |
3 ms |
376 KB |
Output is correct |
39 |
Correct |
265 ms |
5556 KB |
Output is correct |
40 |
Correct |
284 ms |
5712 KB |
Output is correct |
41 |
Correct |
264 ms |
5756 KB |
Output is correct |
42 |
Correct |
270 ms |
5624 KB |
Output is correct |
43 |
Correct |
267 ms |
5628 KB |
Output is correct |
44 |
Correct |
269 ms |
5724 KB |
Output is correct |
45 |
Correct |
268 ms |
5624 KB |
Output is correct |
46 |
Correct |
268 ms |
5752 KB |
Output is correct |
47 |
Correct |
280 ms |
5676 KB |
Output is correct |
48 |
Correct |
273 ms |
5596 KB |
Output is correct |
49 |
Correct |
269 ms |
5656 KB |
Output is correct |
50 |
Correct |
272 ms |
5624 KB |
Output is correct |
51 |
Correct |
2636 ms |
26632 KB |
Output is correct |
52 |
Correct |
2617 ms |
26668 KB |
Output is correct |
53 |
Correct |
2668 ms |
26556 KB |
Output is correct |
54 |
Correct |
267 ms |
5624 KB |
Output is correct |
55 |
Correct |
262 ms |
5624 KB |
Output is correct |
56 |
Correct |
919 ms |
18412 KB |
Output is correct |
57 |
Correct |
2 ms |
256 KB |
Output is correct |
58 |
Correct |
266 ms |
5580 KB |
Output is correct |
59 |
Correct |
267 ms |
5612 KB |
Output is correct |
60 |
Correct |
2696 ms |
28076 KB |
Output is correct |
61 |
Correct |
269 ms |
5684 KB |
Output is correct |
62 |
Correct |
267 ms |
5680 KB |
Output is correct |
63 |
Correct |
278 ms |
5628 KB |
Output is correct |
64 |
Correct |
268 ms |
5680 KB |
Output is correct |
65 |
Correct |
267 ms |
5624 KB |
Output is correct |
66 |
Correct |
270 ms |
5624 KB |
Output is correct |
67 |
Correct |
272 ms |
5544 KB |
Output is correct |
68 |
Correct |
261 ms |
5624 KB |
Output is correct |
69 |
Correct |
269 ms |
5600 KB |
Output is correct |
70 |
Correct |
2713 ms |
28188 KB |
Output is correct |
71 |
Correct |
272 ms |
5624 KB |
Output is correct |
72 |
Correct |
2671 ms |
53220 KB |
Output is correct |
73 |
Correct |
2622 ms |
53212 KB |
Output is correct |
74 |
Correct |
2 ms |
256 KB |
Output is correct |
75 |
Correct |
2 ms |
376 KB |
Output is correct |
76 |
Correct |
2 ms |
376 KB |
Output is correct |
77 |
Correct |
2 ms |
256 KB |
Output is correct |
78 |
Correct |
2 ms |
256 KB |
Output is correct |
79 |
Correct |
28 ms |
888 KB |
Output is correct |
80 |
Correct |
2690 ms |
53348 KB |
Output is correct |
81 |
Correct |
2708 ms |
53244 KB |
Output is correct |
82 |
Correct |
2724 ms |
53368 KB |
Output is correct |
83 |
Correct |
2673 ms |
53212 KB |
Output is correct |
84 |
Correct |
2674 ms |
53148 KB |
Output is correct |
85 |
Correct |
2688 ms |
53220 KB |
Output is correct |
86 |
Correct |
869 ms |
18260 KB |
Output is correct |
87 |
Correct |
3 ms |
376 KB |
Output is correct |