// IOI 2021
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
////////////////////////////////////////////////////////////////////
const int N = 1e5 + 5;
typedef pair<ll, ll> pll;
ll GCD(ll a, ll b) { return !b ? a : GCD(b, a % b); }
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
mt19937 Rnd(time(0));
int n; cin >> n;
ll a, b; cin >> a >> b;
ll g = GCD(a, b + 1);
ll k = INF;
if (a / g <= INF / b) k = a * b / g;
vector<pll> V;
for (int i = 0; i < n; i++) {
ll l, r; cin >> l >> r;
if (r - l + 1 >= k) die(k);
l %= k, r %= k;
if (l <= r) V.push_back(make_pair(l, r));
else V.push_back(make_pair(0, r)), V.push_back(make_pair(l, k - 1));;
}
sort(all(V));
ll mx = 0, ans = 0;
for (auto [l, r] : V) {
mx = max(mx, l);
if (mx <= r) ans += r - mx + 1;
mx = max(mx, r + 1);
}
cout << ans << endl;
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:47:12: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
for (auto [l, r] : V) {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
1024 KB |
Output is correct |
3 |
Correct |
7 ms |
1152 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
424 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
1152 KB |
Output is correct |
17 |
Correct |
64 ms |
5736 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
433 ms |
41448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
551 ms |
26268 KB |
Output is correct |
3 |
Correct |
543 ms |
26324 KB |
Output is correct |
4 |
Correct |
547 ms |
26452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
551 ms |
26268 KB |
Output is correct |
3 |
Correct |
543 ms |
26324 KB |
Output is correct |
4 |
Correct |
547 ms |
26452 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
556 ms |
26308 KB |
Output is correct |
7 |
Correct |
519 ms |
26324 KB |
Output is correct |
8 |
Correct |
547 ms |
26356 KB |
Output is correct |
9 |
Correct |
588 ms |
26324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
551 ms |
26268 KB |
Output is correct |
3 |
Correct |
543 ms |
26324 KB |
Output is correct |
4 |
Correct |
547 ms |
26452 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
51 ms |
5740 KB |
Output is correct |
7 |
Correct |
55 ms |
5780 KB |
Output is correct |
8 |
Correct |
58 ms |
5740 KB |
Output is correct |
9 |
Correct |
60 ms |
5740 KB |
Output is correct |
10 |
Correct |
55 ms |
5736 KB |
Output is correct |
11 |
Correct |
54 ms |
5740 KB |
Output is correct |
12 |
Correct |
53 ms |
5740 KB |
Output is correct |
13 |
Correct |
63 ms |
5740 KB |
Output is correct |
14 |
Correct |
56 ms |
5740 KB |
Output is correct |
15 |
Correct |
56 ms |
5740 KB |
Output is correct |
16 |
Correct |
57 ms |
5744 KB |
Output is correct |
17 |
Correct |
60 ms |
5740 KB |
Output is correct |
18 |
Correct |
557 ms |
53440 KB |
Output is correct |
19 |
Correct |
518 ms |
53308 KB |
Output is correct |
20 |
Correct |
584 ms |
53308 KB |
Output is correct |
21 |
Correct |
56 ms |
5740 KB |
Output is correct |
22 |
Correct |
55 ms |
5732 KB |
Output is correct |
23 |
Correct |
166 ms |
18528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
57 ms |
5740 KB |
Output is correct |
3 |
Correct |
57 ms |
5744 KB |
Output is correct |
4 |
Correct |
596 ms |
26376 KB |
Output is correct |
5 |
Correct |
58 ms |
5740 KB |
Output is correct |
6 |
Correct |
58 ms |
5744 KB |
Output is correct |
7 |
Correct |
61 ms |
5736 KB |
Output is correct |
8 |
Correct |
62 ms |
5712 KB |
Output is correct |
9 |
Correct |
60 ms |
5740 KB |
Output is correct |
10 |
Correct |
57 ms |
5740 KB |
Output is correct |
11 |
Correct |
54 ms |
5696 KB |
Output is correct |
12 |
Correct |
79 ms |
5740 KB |
Output is correct |
13 |
Correct |
66 ms |
5740 KB |
Output is correct |
14 |
Correct |
568 ms |
26192 KB |
Output is correct |
15 |
Correct |
58 ms |
5740 KB |
Output is correct |
16 |
Correct |
526 ms |
53432 KB |
Output is correct |
17 |
Correct |
523 ms |
53404 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
1024 KB |
Output is correct |
3 |
Correct |
7 ms |
1152 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
424 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
1152 KB |
Output is correct |
17 |
Correct |
64 ms |
5736 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
433 ms |
41448 KB |
Output is correct |
29 |
Correct |
0 ms |
384 KB |
Output is correct |
30 |
Correct |
551 ms |
26268 KB |
Output is correct |
31 |
Correct |
543 ms |
26324 KB |
Output is correct |
32 |
Correct |
547 ms |
26452 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
556 ms |
26308 KB |
Output is correct |
35 |
Correct |
519 ms |
26324 KB |
Output is correct |
36 |
Correct |
547 ms |
26356 KB |
Output is correct |
37 |
Correct |
588 ms |
26324 KB |
Output is correct |
38 |
Correct |
0 ms |
384 KB |
Output is correct |
39 |
Correct |
51 ms |
5740 KB |
Output is correct |
40 |
Correct |
55 ms |
5780 KB |
Output is correct |
41 |
Correct |
58 ms |
5740 KB |
Output is correct |
42 |
Correct |
60 ms |
5740 KB |
Output is correct |
43 |
Correct |
55 ms |
5736 KB |
Output is correct |
44 |
Correct |
54 ms |
5740 KB |
Output is correct |
45 |
Correct |
53 ms |
5740 KB |
Output is correct |
46 |
Correct |
63 ms |
5740 KB |
Output is correct |
47 |
Correct |
56 ms |
5740 KB |
Output is correct |
48 |
Correct |
56 ms |
5740 KB |
Output is correct |
49 |
Correct |
57 ms |
5744 KB |
Output is correct |
50 |
Correct |
60 ms |
5740 KB |
Output is correct |
51 |
Correct |
557 ms |
53440 KB |
Output is correct |
52 |
Correct |
518 ms |
53308 KB |
Output is correct |
53 |
Correct |
584 ms |
53308 KB |
Output is correct |
54 |
Correct |
56 ms |
5740 KB |
Output is correct |
55 |
Correct |
55 ms |
5732 KB |
Output is correct |
56 |
Correct |
166 ms |
18528 KB |
Output is correct |
57 |
Correct |
1 ms |
384 KB |
Output is correct |
58 |
Correct |
57 ms |
5740 KB |
Output is correct |
59 |
Correct |
57 ms |
5744 KB |
Output is correct |
60 |
Correct |
596 ms |
26376 KB |
Output is correct |
61 |
Correct |
58 ms |
5740 KB |
Output is correct |
62 |
Correct |
58 ms |
5744 KB |
Output is correct |
63 |
Correct |
61 ms |
5736 KB |
Output is correct |
64 |
Correct |
62 ms |
5712 KB |
Output is correct |
65 |
Correct |
60 ms |
5740 KB |
Output is correct |
66 |
Correct |
57 ms |
5740 KB |
Output is correct |
67 |
Correct |
54 ms |
5696 KB |
Output is correct |
68 |
Correct |
79 ms |
5740 KB |
Output is correct |
69 |
Correct |
66 ms |
5740 KB |
Output is correct |
70 |
Correct |
568 ms |
26192 KB |
Output is correct |
71 |
Correct |
58 ms |
5740 KB |
Output is correct |
72 |
Correct |
526 ms |
53432 KB |
Output is correct |
73 |
Correct |
523 ms |
53404 KB |
Output is correct |
74 |
Correct |
0 ms |
384 KB |
Output is correct |
75 |
Correct |
0 ms |
384 KB |
Output is correct |
76 |
Correct |
0 ms |
384 KB |
Output is correct |
77 |
Correct |
0 ms |
384 KB |
Output is correct |
78 |
Correct |
1 ms |
384 KB |
Output is correct |
79 |
Correct |
6 ms |
1152 KB |
Output is correct |
80 |
Correct |
610 ms |
53568 KB |
Output is correct |
81 |
Correct |
599 ms |
53308 KB |
Output is correct |
82 |
Correct |
545 ms |
53312 KB |
Output is correct |
83 |
Correct |
600 ms |
53284 KB |
Output is correct |
84 |
Correct |
575 ms |
53440 KB |
Output is correct |
85 |
Correct |
572 ms |
53312 KB |
Output is correct |
86 |
Correct |
166 ms |
18788 KB |
Output is correct |
87 |
Correct |
1 ms |
384 KB |
Output is correct |