Submission #366907

# Submission time Handle Problem Language Result Execution time Memory
366907 2021-02-15T17:45:11 Z SeDunion Strange Device (APIO19_strange_device) C++17
100 / 100
782 ms 39692 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 66;

int n; ll A, B;

vector<pair<ll,ll>> v;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n >> A >> B;
	ll g = gcd(A, B + 1), I;
	if (A / g > ll(2e18) / B) {
		I = ll(2e18);
	} else {
		I = A * B / g;
	}
	for (int i = 1 ; i <= n ; ++ i) {
		ll l, r;
		cin >> l >> r;
		if (r - l + 1 >= I) {
			cout << I << "\n";
			return 0;
		}
		ll L = l % I, R = r % I;
		if (L <= R) {
			v.emplace_back(L, +1);
			v.emplace_back(R + 1, -1);
		} else {
			v.emplace_back(0, +1);
			v.emplace_back(R + 1, -1);
			v.emplace_back(L, +1);
			v.emplace_back(I, -1);
		}
	}
	sort(v.begin(), v.end());
	ll k = 0, l = -1, Ans = 0;
	for (auto [i, t] : v) {
		if (t == +1) {
			if (k++ == 0) l = i;
		} else if (--k == 0) Ans += i - l, l = i;
	}
	cout << Ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 9 ms 1392 KB Output is correct
3 Correct 7 ms 1392 KB Output is correct
4 Correct 0 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 384 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 7 ms 1392 KB Output is correct
17 Correct 72 ms 7584 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 1 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 1 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 426 ms 34492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 602 ms 35516 KB Output is correct
3 Correct 643 ms 35388 KB Output is correct
4 Correct 592 ms 35516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 602 ms 35516 KB Output is correct
3 Correct 643 ms 35388 KB Output is correct
4 Correct 592 ms 35516 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 638 ms 35512 KB Output is correct
7 Correct 603 ms 35644 KB Output is correct
8 Correct 613 ms 34808 KB Output is correct
9 Correct 703 ms 35096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 602 ms 35516 KB Output is correct
3 Correct 643 ms 35388 KB Output is correct
4 Correct 592 ms 35516 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 60 ms 7268 KB Output is correct
7 Correct 64 ms 7400 KB Output is correct
8 Correct 60 ms 7392 KB Output is correct
9 Correct 65 ms 7268 KB Output is correct
10 Correct 60 ms 7268 KB Output is correct
11 Correct 61 ms 7268 KB Output is correct
12 Correct 57 ms 7268 KB Output is correct
13 Correct 64 ms 7268 KB Output is correct
14 Correct 59 ms 7268 KB Output is correct
15 Correct 68 ms 7388 KB Output is correct
16 Correct 79 ms 7268 KB Output is correct
17 Correct 60 ms 7268 KB Output is correct
18 Correct 618 ms 35900 KB Output is correct
19 Correct 584 ms 36352 KB Output is correct
20 Correct 711 ms 35556 KB Output is correct
21 Correct 67 ms 7268 KB Output is correct
22 Correct 54 ms 7268 KB Output is correct
23 Correct 177 ms 26832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 65 ms 7268 KB Output is correct
3 Correct 65 ms 7268 KB Output is correct
4 Correct 738 ms 35408 KB Output is correct
5 Correct 81 ms 7268 KB Output is correct
6 Correct 65 ms 7268 KB Output is correct
7 Correct 64 ms 7268 KB Output is correct
8 Correct 68 ms 7392 KB Output is correct
9 Correct 64 ms 7268 KB Output is correct
10 Correct 68 ms 7392 KB Output is correct
11 Correct 64 ms 7268 KB Output is correct
12 Correct 59 ms 7432 KB Output is correct
13 Correct 69 ms 7268 KB Output is correct
14 Correct 715 ms 39484 KB Output is correct
15 Correct 70 ms 7412 KB Output is correct
16 Correct 578 ms 39520 KB Output is correct
17 Correct 626 ms 39620 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 9 ms 1392 KB Output is correct
3 Correct 7 ms 1392 KB Output is correct
4 Correct 0 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 384 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 7 ms 1392 KB Output is correct
17 Correct 72 ms 7584 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 2 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 1 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 1 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 426 ms 34492 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 602 ms 35516 KB Output is correct
31 Correct 643 ms 35388 KB Output is correct
32 Correct 592 ms 35516 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 638 ms 35512 KB Output is correct
35 Correct 603 ms 35644 KB Output is correct
36 Correct 613 ms 34808 KB Output is correct
37 Correct 703 ms 35096 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 60 ms 7268 KB Output is correct
40 Correct 64 ms 7400 KB Output is correct
41 Correct 60 ms 7392 KB Output is correct
42 Correct 65 ms 7268 KB Output is correct
43 Correct 60 ms 7268 KB Output is correct
44 Correct 61 ms 7268 KB Output is correct
45 Correct 57 ms 7268 KB Output is correct
46 Correct 64 ms 7268 KB Output is correct
47 Correct 59 ms 7268 KB Output is correct
48 Correct 68 ms 7388 KB Output is correct
49 Correct 79 ms 7268 KB Output is correct
50 Correct 60 ms 7268 KB Output is correct
51 Correct 618 ms 35900 KB Output is correct
52 Correct 584 ms 36352 KB Output is correct
53 Correct 711 ms 35556 KB Output is correct
54 Correct 67 ms 7268 KB Output is correct
55 Correct 54 ms 7268 KB Output is correct
56 Correct 177 ms 26832 KB Output is correct
57 Correct 1 ms 364 KB Output is correct
58 Correct 65 ms 7268 KB Output is correct
59 Correct 65 ms 7268 KB Output is correct
60 Correct 738 ms 35408 KB Output is correct
61 Correct 81 ms 7268 KB Output is correct
62 Correct 65 ms 7268 KB Output is correct
63 Correct 64 ms 7268 KB Output is correct
64 Correct 68 ms 7392 KB Output is correct
65 Correct 64 ms 7268 KB Output is correct
66 Correct 68 ms 7392 KB Output is correct
67 Correct 64 ms 7268 KB Output is correct
68 Correct 59 ms 7432 KB Output is correct
69 Correct 69 ms 7268 KB Output is correct
70 Correct 715 ms 39484 KB Output is correct
71 Correct 70 ms 7412 KB Output is correct
72 Correct 578 ms 39520 KB Output is correct
73 Correct 626 ms 39620 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 6 ms 1392 KB Output is correct
80 Correct 781 ms 39484 KB Output is correct
81 Correct 782 ms 39484 KB Output is correct
82 Correct 686 ms 39424 KB Output is correct
83 Correct 721 ms 39692 KB Output is correct
84 Correct 701 ms 39620 KB Output is correct
85 Correct 704 ms 39628 KB Output is correct
86 Correct 173 ms 26704 KB Output is correct
87 Correct 1 ms 364 KB Output is correct