//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T,class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 100005
#define pii pair<ll, ll>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
ll inf = 1LL<<60;
ll mul(ll a, ll b) {
ll ret = 0;
while (b) {
if (a > inf) return inf;
if (b & 1) ret += a;
a += a;
b >>= 1;
if (ret > inf) return inf;
}
return ret;
}
int main() {
io
ll n, A, B;
cin >> n >> A >> B;
ll cy = mul(A / __gcd(A, B + 1), B);
vector<pii> ev;
for (int i = 0;i < n;i++) {
ll l, r;
cin >> l >> r;
if (r - l + 1 >= cy) {
cout << cy << "\n";
return 0;
}
l %= cy, r %= cy;
if (l <= r) {
ev.push_back({l, 1});
ev.push_back({r + 1, -1});
} else {
ev.push_back({l, 1});
ev.push_back({0, 1});
ev.push_back({r+1, -1});
}
}
ev.push_back({cy, 0});
sort(ev.begin(), ev.end());
ll prv = -1, val = 0, ans = 0;
int siz = ev.size();
for (int i = 0;i < siz;i++) {
int tmp = i;
ll to = val;
while (tmp < siz - 1 && ev[tmp+1].ff == ev[i].ff) {
to += ev[tmp].ss;
tmp++;
}
to += ev[tmp].ss;
if (val) ans += ev[i].ff - prv;
val = to;
prv = ev[i].ff;
i = tmp;
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
9 ms |
1240 KB |
Output is correct |
3 |
Correct |
8 ms |
1232 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 |
212 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
7 ms |
1296 KB |
Output is correct |
17 |
Correct |
64 ms |
5176 KB |
Output is correct |
18 |
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 |
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 |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
391 ms |
33908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
596 ms |
33940 KB |
Output is correct |
3 |
Correct |
613 ms |
33244 KB |
Output is correct |
4 |
Correct |
543 ms |
34336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
596 ms |
33940 KB |
Output is correct |
3 |
Correct |
613 ms |
33244 KB |
Output is correct |
4 |
Correct |
543 ms |
34336 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
532 ms |
34404 KB |
Output is correct |
7 |
Correct |
525 ms |
34348 KB |
Output is correct |
8 |
Correct |
574 ms |
34332 KB |
Output is correct |
9 |
Correct |
638 ms |
34364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
596 ms |
33940 KB |
Output is correct |
3 |
Correct |
613 ms |
33244 KB |
Output is correct |
4 |
Correct |
543 ms |
34336 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
55 ms |
5140 KB |
Output is correct |
7 |
Correct |
58 ms |
5076 KB |
Output is correct |
8 |
Correct |
52 ms |
5092 KB |
Output is correct |
9 |
Correct |
59 ms |
5216 KB |
Output is correct |
10 |
Correct |
55 ms |
5000 KB |
Output is correct |
11 |
Correct |
64 ms |
5124 KB |
Output is correct |
12 |
Correct |
53 ms |
5156 KB |
Output is correct |
13 |
Correct |
67 ms |
5084 KB |
Output is correct |
14 |
Correct |
54 ms |
4896 KB |
Output is correct |
15 |
Correct |
61 ms |
5188 KB |
Output is correct |
16 |
Correct |
69 ms |
5144 KB |
Output is correct |
17 |
Correct |
52 ms |
5092 KB |
Output is correct |
18 |
Correct |
537 ms |
33264 KB |
Output is correct |
19 |
Correct |
579 ms |
34456 KB |
Output is correct |
20 |
Correct |
698 ms |
34416 KB |
Output is correct |
21 |
Correct |
73 ms |
5184 KB |
Output is correct |
22 |
Correct |
51 ms |
5176 KB |
Output is correct |
23 |
Correct |
163 ms |
17432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
58 ms |
5144 KB |
Output is correct |
3 |
Correct |
57 ms |
5120 KB |
Output is correct |
4 |
Correct |
727 ms |
33248 KB |
Output is correct |
5 |
Correct |
56 ms |
5176 KB |
Output is correct |
6 |
Correct |
57 ms |
5188 KB |
Output is correct |
7 |
Correct |
60 ms |
5120 KB |
Output is correct |
8 |
Correct |
61 ms |
5176 KB |
Output is correct |
9 |
Correct |
57 ms |
5104 KB |
Output is correct |
10 |
Correct |
59 ms |
5092 KB |
Output is correct |
11 |
Correct |
61 ms |
5188 KB |
Output is correct |
12 |
Correct |
69 ms |
5140 KB |
Output is correct |
13 |
Correct |
55 ms |
5116 KB |
Output is correct |
14 |
Correct |
599 ms |
34388 KB |
Output is correct |
15 |
Correct |
56 ms |
5072 KB |
Output is correct |
16 |
Correct |
486 ms |
34324 KB |
Output is correct |
17 |
Correct |
486 ms |
33964 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 |
9 ms |
1240 KB |
Output is correct |
3 |
Correct |
8 ms |
1232 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 |
212 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
7 ms |
1296 KB |
Output is correct |
17 |
Correct |
64 ms |
5176 KB |
Output is correct |
18 |
Correct |
0 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 |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
391 ms |
33908 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
596 ms |
33940 KB |
Output is correct |
31 |
Correct |
613 ms |
33244 KB |
Output is correct |
32 |
Correct |
543 ms |
34336 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
532 ms |
34404 KB |
Output is correct |
35 |
Correct |
525 ms |
34348 KB |
Output is correct |
36 |
Correct |
574 ms |
34332 KB |
Output is correct |
37 |
Correct |
638 ms |
34364 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
55 ms |
5140 KB |
Output is correct |
40 |
Correct |
58 ms |
5076 KB |
Output is correct |
41 |
Correct |
52 ms |
5092 KB |
Output is correct |
42 |
Correct |
59 ms |
5216 KB |
Output is correct |
43 |
Correct |
55 ms |
5000 KB |
Output is correct |
44 |
Correct |
64 ms |
5124 KB |
Output is correct |
45 |
Correct |
53 ms |
5156 KB |
Output is correct |
46 |
Correct |
67 ms |
5084 KB |
Output is correct |
47 |
Correct |
54 ms |
4896 KB |
Output is correct |
48 |
Correct |
61 ms |
5188 KB |
Output is correct |
49 |
Correct |
69 ms |
5144 KB |
Output is correct |
50 |
Correct |
52 ms |
5092 KB |
Output is correct |
51 |
Correct |
537 ms |
33264 KB |
Output is correct |
52 |
Correct |
579 ms |
34456 KB |
Output is correct |
53 |
Correct |
698 ms |
34416 KB |
Output is correct |
54 |
Correct |
73 ms |
5184 KB |
Output is correct |
55 |
Correct |
51 ms |
5176 KB |
Output is correct |
56 |
Correct |
163 ms |
17432 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
58 ms |
5144 KB |
Output is correct |
59 |
Correct |
57 ms |
5120 KB |
Output is correct |
60 |
Correct |
727 ms |
33248 KB |
Output is correct |
61 |
Correct |
56 ms |
5176 KB |
Output is correct |
62 |
Correct |
57 ms |
5188 KB |
Output is correct |
63 |
Correct |
60 ms |
5120 KB |
Output is correct |
64 |
Correct |
61 ms |
5176 KB |
Output is correct |
65 |
Correct |
57 ms |
5104 KB |
Output is correct |
66 |
Correct |
59 ms |
5092 KB |
Output is correct |
67 |
Correct |
61 ms |
5188 KB |
Output is correct |
68 |
Correct |
69 ms |
5140 KB |
Output is correct |
69 |
Correct |
55 ms |
5116 KB |
Output is correct |
70 |
Correct |
599 ms |
34388 KB |
Output is correct |
71 |
Correct |
56 ms |
5072 KB |
Output is correct |
72 |
Correct |
486 ms |
34324 KB |
Output is correct |
73 |
Correct |
486 ms |
33964 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
6 ms |
1240 KB |
Output is correct |
80 |
Correct |
691 ms |
55100 KB |
Output is correct |
81 |
Correct |
679 ms |
54952 KB |
Output is correct |
82 |
Correct |
652 ms |
54888 KB |
Output is correct |
83 |
Correct |
648 ms |
52152 KB |
Output is correct |
84 |
Correct |
652 ms |
52252 KB |
Output is correct |
85 |
Correct |
661 ms |
52140 KB |
Output is correct |
86 |
Correct |
162 ms |
26604 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |