#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define X first
#define Y second
using namespace std;
map <int, int> m;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, A, B;
cin >> n >> A >> B;
int ans = 0, MOD = log10(A) - log10(__gcd(A, B+1)) + log10(B) > 18 ? (long long)(1e18+1) : A / __gcd(A, B+1) * B;
while (n--) {
int l, r;
cin >> l >> r;
int L = l % MOD, R = r % MOD;
if (r - l >= MOD) ans = MOD;
else if (L < R) m[L]++, m[R+1]--;
else if (L > R) m[L]++, m[MOD]--, m[0]++, m[R+1]--;
else if (l == r) m[L]++, m[L+1]--;
else ans = MOD;
}
int sum = 0, f = 1, l;
if (ans != MOD) {
for (auto seg:m) {
//cout << seg.X << ' ' << seg.Y << endl;
sum += seg.Y;
if (sum and f) l = seg.X, f = 0;
else if (!sum) ans += seg.X - l, f = 1;
}
}
cout << ans << endl;
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:33:32: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
33 | else if (!sum) ans += seg.X - l, f = 1;
| ~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
7 ms |
1388 KB |
Output is correct |
3 |
Correct |
7 ms |
1388 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
8 ms |
1388 KB |
Output is correct |
17 |
Correct |
74 ms |
8684 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
300 ms |
2924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
743 ms |
63132 KB |
Output is correct |
3 |
Correct |
747 ms |
65536 KB |
Output is correct |
4 |
Correct |
790 ms |
65516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
743 ms |
63132 KB |
Output is correct |
3 |
Correct |
747 ms |
65536 KB |
Output is correct |
4 |
Correct |
790 ms |
65516 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
752 ms |
65516 KB |
Output is correct |
7 |
Correct |
757 ms |
65516 KB |
Output is correct |
8 |
Correct |
736 ms |
65516 KB |
Output is correct |
9 |
Correct |
820 ms |
65748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
743 ms |
63132 KB |
Output is correct |
3 |
Correct |
747 ms |
65536 KB |
Output is correct |
4 |
Correct |
790 ms |
65516 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
74 ms |
9196 KB |
Output is correct |
7 |
Correct |
67 ms |
9196 KB |
Output is correct |
8 |
Correct |
69 ms |
9196 KB |
Output is correct |
9 |
Correct |
73 ms |
9196 KB |
Output is correct |
10 |
Correct |
68 ms |
9196 KB |
Output is correct |
11 |
Correct |
64 ms |
9324 KB |
Output is correct |
12 |
Correct |
75 ms |
9196 KB |
Output is correct |
13 |
Correct |
74 ms |
9196 KB |
Output is correct |
14 |
Correct |
67 ms |
9196 KB |
Output is correct |
15 |
Correct |
75 ms |
9196 KB |
Output is correct |
16 |
Correct |
76 ms |
9196 KB |
Output is correct |
17 |
Correct |
69 ms |
9196 KB |
Output is correct |
18 |
Correct |
731 ms |
65516 KB |
Output is correct |
19 |
Correct |
775 ms |
65628 KB |
Output is correct |
20 |
Correct |
832 ms |
65644 KB |
Output is correct |
21 |
Correct |
67 ms |
8940 KB |
Output is correct |
22 |
Correct |
72 ms |
8940 KB |
Output is correct |
23 |
Correct |
126 ms |
2700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
78 ms |
8684 KB |
Output is correct |
3 |
Correct |
76 ms |
8556 KB |
Output is correct |
4 |
Correct |
791 ms |
63188 KB |
Output is correct |
5 |
Correct |
73 ms |
7916 KB |
Output is correct |
6 |
Correct |
76 ms |
7916 KB |
Output is correct |
7 |
Correct |
73 ms |
7916 KB |
Output is correct |
8 |
Correct |
76 ms |
7916 KB |
Output is correct |
9 |
Correct |
72 ms |
7916 KB |
Output is correct |
10 |
Correct |
85 ms |
8064 KB |
Output is correct |
11 |
Correct |
69 ms |
7916 KB |
Output is correct |
12 |
Correct |
76 ms |
7916 KB |
Output is correct |
13 |
Correct |
75 ms |
8044 KB |
Output is correct |
14 |
Correct |
819 ms |
63340 KB |
Output is correct |
15 |
Correct |
65 ms |
6892 KB |
Output is correct |
16 |
Correct |
733 ms |
63116 KB |
Output is correct |
17 |
Correct |
734 ms |
62956 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
7 ms |
1388 KB |
Output is correct |
3 |
Correct |
7 ms |
1388 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
8 ms |
1388 KB |
Output is correct |
17 |
Correct |
74 ms |
8684 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
0 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
2 ms |
492 KB |
Output is correct |
26 |
Correct |
1 ms |
492 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
300 ms |
2924 KB |
Output is correct |
29 |
Correct |
1 ms |
620 KB |
Output is correct |
30 |
Correct |
743 ms |
63132 KB |
Output is correct |
31 |
Correct |
747 ms |
65536 KB |
Output is correct |
32 |
Correct |
790 ms |
65516 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
752 ms |
65516 KB |
Output is correct |
35 |
Correct |
757 ms |
65516 KB |
Output is correct |
36 |
Correct |
736 ms |
65516 KB |
Output is correct |
37 |
Correct |
820 ms |
65748 KB |
Output is correct |
38 |
Correct |
1 ms |
364 KB |
Output is correct |
39 |
Correct |
74 ms |
9196 KB |
Output is correct |
40 |
Correct |
67 ms |
9196 KB |
Output is correct |
41 |
Correct |
69 ms |
9196 KB |
Output is correct |
42 |
Correct |
73 ms |
9196 KB |
Output is correct |
43 |
Correct |
68 ms |
9196 KB |
Output is correct |
44 |
Correct |
64 ms |
9324 KB |
Output is correct |
45 |
Correct |
75 ms |
9196 KB |
Output is correct |
46 |
Correct |
74 ms |
9196 KB |
Output is correct |
47 |
Correct |
67 ms |
9196 KB |
Output is correct |
48 |
Correct |
75 ms |
9196 KB |
Output is correct |
49 |
Correct |
76 ms |
9196 KB |
Output is correct |
50 |
Correct |
69 ms |
9196 KB |
Output is correct |
51 |
Correct |
731 ms |
65516 KB |
Output is correct |
52 |
Correct |
775 ms |
65628 KB |
Output is correct |
53 |
Correct |
832 ms |
65644 KB |
Output is correct |
54 |
Correct |
67 ms |
8940 KB |
Output is correct |
55 |
Correct |
72 ms |
8940 KB |
Output is correct |
56 |
Correct |
126 ms |
2700 KB |
Output is correct |
57 |
Correct |
1 ms |
364 KB |
Output is correct |
58 |
Correct |
78 ms |
8684 KB |
Output is correct |
59 |
Correct |
76 ms |
8556 KB |
Output is correct |
60 |
Correct |
791 ms |
63188 KB |
Output is correct |
61 |
Correct |
73 ms |
7916 KB |
Output is correct |
62 |
Correct |
76 ms |
7916 KB |
Output is correct |
63 |
Correct |
73 ms |
7916 KB |
Output is correct |
64 |
Correct |
76 ms |
7916 KB |
Output is correct |
65 |
Correct |
72 ms |
7916 KB |
Output is correct |
66 |
Correct |
85 ms |
8064 KB |
Output is correct |
67 |
Correct |
69 ms |
7916 KB |
Output is correct |
68 |
Correct |
76 ms |
7916 KB |
Output is correct |
69 |
Correct |
75 ms |
8044 KB |
Output is correct |
70 |
Correct |
819 ms |
63340 KB |
Output is correct |
71 |
Correct |
65 ms |
6892 KB |
Output is correct |
72 |
Correct |
733 ms |
63116 KB |
Output is correct |
73 |
Correct |
734 ms |
62956 KB |
Output is correct |
74 |
Correct |
1 ms |
364 KB |
Output is correct |
75 |
Correct |
1 ms |
364 KB |
Output is correct |
76 |
Correct |
1 ms |
364 KB |
Output is correct |
77 |
Correct |
1 ms |
364 KB |
Output is correct |
78 |
Correct |
1 ms |
364 KB |
Output is correct |
79 |
Correct |
7 ms |
1388 KB |
Output is correct |
80 |
Correct |
799 ms |
73964 KB |
Output is correct |
81 |
Correct |
807 ms |
72300 KB |
Output is correct |
82 |
Correct |
811 ms |
71532 KB |
Output is correct |
83 |
Correct |
839 ms |
82028 KB |
Output is correct |
84 |
Correct |
871 ms |
80624 KB |
Output is correct |
85 |
Correct |
794 ms |
83264 KB |
Output is correct |
86 |
Correct |
133 ms |
12924 KB |
Output is correct |
87 |
Correct |
1 ms |
364 KB |
Output is correct |