#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, A, B;
vector<pair<ll, ll>> segs;
void solve2() {
ll ans = 0;
for(auto & [l, r] : segs) {
cin >> l >> r;
ans += r - l + 1;
}
cout << ans << endl;
}
ll gcd(ll a, ll b) {
return b ? gcd(b, a % b) : a;
}
//x(B+1) == 0
//x(b+1)
main() {
cin >> n >> A >> B;
segs.resize(n);
ll C = A / (gcd(B + 1, A));
__int128 X = C;
__int128 Y = B;
__int128 Z = X * Y;
ll cycle;
if(Z >= 1e18) cycle = 1e18;
else cycle = Z;
vector<pair<ll, bool>> evt;
for(auto & [l, r] : segs) {
cin >> l >> r;
r++;
if(l >= cycle) {
ll tmp = (l / cycle) * cycle;
l -= tmp;
r -= tmp;
}
if(r >= cycle*2) {
cout << cycle << endl;
return 0;
}
if(r >= cycle) {
evt.push_back({l, true});
evt.push_back({0, true});
evt.push_back({r - cycle, false});
} else {
evt.push_back({l, true});
evt.push_back({r, false});
}
}
sort(evt.begin(), evt.end());
ll prev = 0;
int cnt = 0;
ll ans = 0;
for(auto [t, b] : evt) {
ll delta = t - prev;
prev = t;
if(cnt > 0) ans += delta;
if(b) cnt++;
else cnt--;
}
if(cnt > 0) ans += cycle - prev;
cout << ans << endl;
}
Compilation message
strange_device.cpp:21:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
21 | main() {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
14 ms |
1456 KB |
Output is correct |
3 |
Correct |
16 ms |
1432 KB |
Output is correct |
4 |
Correct |
1 ms |
296 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 |
296 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 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 |
14 ms |
1456 KB |
Output is correct |
17 |
Correct |
142 ms |
8724 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
312 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
973 ms |
49024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1448 ms |
52360 KB |
Output is correct |
3 |
Correct |
1384 ms |
49300 KB |
Output is correct |
4 |
Correct |
1400 ms |
49404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1448 ms |
52360 KB |
Output is correct |
3 |
Correct |
1384 ms |
49300 KB |
Output is correct |
4 |
Correct |
1400 ms |
49404 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1394 ms |
49348 KB |
Output is correct |
7 |
Correct |
1369 ms |
49356 KB |
Output is correct |
8 |
Correct |
1418 ms |
49496 KB |
Output is correct |
9 |
Correct |
1458 ms |
49400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1448 ms |
52360 KB |
Output is correct |
3 |
Correct |
1384 ms |
49300 KB |
Output is correct |
4 |
Correct |
1400 ms |
49404 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
159 ms |
8840 KB |
Output is correct |
7 |
Correct |
147 ms |
8836 KB |
Output is correct |
8 |
Correct |
141 ms |
8776 KB |
Output is correct |
9 |
Correct |
138 ms |
8736 KB |
Output is correct |
10 |
Correct |
152 ms |
8836 KB |
Output is correct |
11 |
Correct |
149 ms |
8888 KB |
Output is correct |
12 |
Correct |
137 ms |
8764 KB |
Output is correct |
13 |
Correct |
143 ms |
8792 KB |
Output is correct |
14 |
Correct |
171 ms |
8836 KB |
Output is correct |
15 |
Correct |
145 ms |
8916 KB |
Output is correct |
16 |
Correct |
146 ms |
8944 KB |
Output is correct |
17 |
Correct |
144 ms |
8836 KB |
Output is correct |
18 |
Correct |
1400 ms |
49336 KB |
Output is correct |
19 |
Correct |
1409 ms |
49288 KB |
Output is correct |
20 |
Correct |
1523 ms |
49264 KB |
Output is correct |
21 |
Correct |
161 ms |
8764 KB |
Output is correct |
22 |
Correct |
142 ms |
8852 KB |
Output is correct |
23 |
Correct |
452 ms |
27420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
148 ms |
8732 KB |
Output is correct |
3 |
Correct |
147 ms |
8948 KB |
Output is correct |
4 |
Correct |
1589 ms |
52380 KB |
Output is correct |
5 |
Correct |
152 ms |
8976 KB |
Output is correct |
6 |
Correct |
163 ms |
8896 KB |
Output is correct |
7 |
Correct |
146 ms |
8840 KB |
Output is correct |
8 |
Correct |
145 ms |
8812 KB |
Output is correct |
9 |
Correct |
155 ms |
8932 KB |
Output is correct |
10 |
Correct |
160 ms |
8732 KB |
Output is correct |
11 |
Correct |
140 ms |
8768 KB |
Output is correct |
12 |
Correct |
142 ms |
8764 KB |
Output is correct |
13 |
Correct |
140 ms |
8800 KB |
Output is correct |
14 |
Correct |
1553 ms |
52340 KB |
Output is correct |
15 |
Correct |
150 ms |
8724 KB |
Output is correct |
16 |
Correct |
1375 ms |
53244 KB |
Output is correct |
17 |
Correct |
1358 ms |
53472 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
14 ms |
1456 KB |
Output is correct |
3 |
Correct |
16 ms |
1432 KB |
Output is correct |
4 |
Correct |
1 ms |
296 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 |
296 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 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 |
14 ms |
1456 KB |
Output is correct |
17 |
Correct |
142 ms |
8724 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 |
292 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
312 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
973 ms |
49024 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1448 ms |
52360 KB |
Output is correct |
31 |
Correct |
1384 ms |
49300 KB |
Output is correct |
32 |
Correct |
1400 ms |
49404 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1394 ms |
49348 KB |
Output is correct |
35 |
Correct |
1369 ms |
49356 KB |
Output is correct |
36 |
Correct |
1418 ms |
49496 KB |
Output is correct |
37 |
Correct |
1458 ms |
49400 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
159 ms |
8840 KB |
Output is correct |
40 |
Correct |
147 ms |
8836 KB |
Output is correct |
41 |
Correct |
141 ms |
8776 KB |
Output is correct |
42 |
Correct |
138 ms |
8736 KB |
Output is correct |
43 |
Correct |
152 ms |
8836 KB |
Output is correct |
44 |
Correct |
149 ms |
8888 KB |
Output is correct |
45 |
Correct |
137 ms |
8764 KB |
Output is correct |
46 |
Correct |
143 ms |
8792 KB |
Output is correct |
47 |
Correct |
171 ms |
8836 KB |
Output is correct |
48 |
Correct |
145 ms |
8916 KB |
Output is correct |
49 |
Correct |
146 ms |
8944 KB |
Output is correct |
50 |
Correct |
144 ms |
8836 KB |
Output is correct |
51 |
Correct |
1400 ms |
49336 KB |
Output is correct |
52 |
Correct |
1409 ms |
49288 KB |
Output is correct |
53 |
Correct |
1523 ms |
49264 KB |
Output is correct |
54 |
Correct |
161 ms |
8764 KB |
Output is correct |
55 |
Correct |
142 ms |
8852 KB |
Output is correct |
56 |
Correct |
452 ms |
27420 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
148 ms |
8732 KB |
Output is correct |
59 |
Correct |
147 ms |
8948 KB |
Output is correct |
60 |
Correct |
1589 ms |
52380 KB |
Output is correct |
61 |
Correct |
152 ms |
8976 KB |
Output is correct |
62 |
Correct |
163 ms |
8896 KB |
Output is correct |
63 |
Correct |
146 ms |
8840 KB |
Output is correct |
64 |
Correct |
145 ms |
8812 KB |
Output is correct |
65 |
Correct |
155 ms |
8932 KB |
Output is correct |
66 |
Correct |
160 ms |
8732 KB |
Output is correct |
67 |
Correct |
140 ms |
8768 KB |
Output is correct |
68 |
Correct |
142 ms |
8764 KB |
Output is correct |
69 |
Correct |
140 ms |
8800 KB |
Output is correct |
70 |
Correct |
1553 ms |
52340 KB |
Output is correct |
71 |
Correct |
150 ms |
8724 KB |
Output is correct |
72 |
Correct |
1375 ms |
53244 KB |
Output is correct |
73 |
Correct |
1358 ms |
53472 KB |
Output is correct |
74 |
Correct |
1 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
340 KB |
Output is correct |
76 |
Correct |
0 ms |
212 KB |
Output is correct |
77 |
Correct |
0 ms |
296 KB |
Output is correct |
78 |
Correct |
1 ms |
300 KB |
Output is correct |
79 |
Correct |
15 ms |
1488 KB |
Output is correct |
80 |
Correct |
1551 ms |
84520 KB |
Output is correct |
81 |
Correct |
1542 ms |
84592 KB |
Output is correct |
82 |
Correct |
1512 ms |
84512 KB |
Output is correct |
83 |
Correct |
1478 ms |
84472 KB |
Output is correct |
84 |
Correct |
1494 ms |
84608 KB |
Output is correct |
85 |
Correct |
1484 ms |
84696 KB |
Output is correct |
86 |
Correct |
441 ms |
31924 KB |
Output is correct |
87 |
Correct |
1 ms |
296 KB |
Output is correct |