Submission #947346

# Submission time Handle Problem Language Result Execution time Memory
947346 2024-03-16T00:32:02 Z MinaRagy06 Strange Device (APIO19_strange_device) C++17
100 / 100
586 ms 73496 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n;
	ll a, b;
	cin >> n >> a >> b;
	ll m;
	if (a / gcd(a, b + 1) <= (ll) 2e18 / b) {
		m = a * b / gcd(a, b + 1);
	} else {
		m = 2e18;
	}
	array<ll, 2> q[n];
	vector<ll> v = {0, m};
	for (int i = 0; i < n; i++) {
		auto &[l, r] = q[i];
		cin >> l >> r;
		if (r - l >= m) {
			cout << m << '\n';
			return 0;
		}
		ll s = l % m, e = r % m;
		v.push_back(s);
		v.push_back(e + 1);
	}
	sort(v.begin(), v.end());
	v.resize(unique(v.begin(), v.end()) - v.begin());
	int toadd[v.size()]{};
	auto add2 = [&] (ll x, int y) {
		int p = lower_bound(v.begin(), v.end(), x) - v.begin();
		toadd[p] += y;
	};
	auto add = [&] (ll l, ll r) {
		add2(l, 1);
		add2(r + 1, -1);
	};
	for (int i = 0; i < n; i++) {
		auto &[l, r] = q[i];
		ll s = l % m, e = r % m;
		if (e - s == r - l) {
			add(s, e);
			continue;
		}
		add(s, m - 1);
		add(0, e);
	}
	int cnt = 0;
	ll ans = 0;
	for (int i = 0; i < v.size(); i++) {
		if (cnt) {
			ans += v[i] - v[i - 1];
		}
		cnt += toadd[i];
	}
	cout << ans << '\n';
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for (int i = 0; i < v.size(); i++) {
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 5 ms 1232 KB Output is correct
3 Correct 5 ms 1372 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 456 KB Output is correct
16 Correct 4 ms 1372 KB Output is correct
17 Correct 48 ms 7760 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 263 ms 57532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 470 ms 73212 KB Output is correct
3 Correct 507 ms 72848 KB Output is correct
4 Correct 473 ms 73044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 470 ms 73212 KB Output is correct
3 Correct 507 ms 72848 KB Output is correct
4 Correct 473 ms 73044 KB Output is correct
5 Correct 1 ms 456 KB Output is correct
6 Correct 458 ms 72760 KB Output is correct
7 Correct 452 ms 72988 KB Output is correct
8 Correct 497 ms 73132 KB Output is correct
9 Correct 556 ms 73112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 470 ms 73212 KB Output is correct
3 Correct 507 ms 72848 KB Output is correct
4 Correct 473 ms 73044 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 52 ms 7688 KB Output is correct
7 Correct 47 ms 7632 KB Output is correct
8 Correct 41 ms 7628 KB Output is correct
9 Correct 50 ms 7680 KB Output is correct
10 Correct 49 ms 7620 KB Output is correct
11 Correct 57 ms 7804 KB Output is correct
12 Correct 45 ms 7736 KB Output is correct
13 Correct 49 ms 7616 KB Output is correct
14 Correct 45 ms 7624 KB Output is correct
15 Correct 47 ms 7636 KB Output is correct
16 Correct 62 ms 7624 KB Output is correct
17 Correct 46 ms 7616 KB Output is correct
18 Correct 480 ms 72848 KB Output is correct
19 Correct 495 ms 72956 KB Output is correct
20 Correct 564 ms 73496 KB Output is correct
21 Correct 49 ms 7624 KB Output is correct
22 Correct 46 ms 7816 KB Output is correct
23 Correct 98 ms 25768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 49 ms 7652 KB Output is correct
3 Correct 50 ms 7700 KB Output is correct
4 Correct 554 ms 72580 KB Output is correct
5 Correct 51 ms 7628 KB Output is correct
6 Correct 50 ms 7620 KB Output is correct
7 Correct 50 ms 7620 KB Output is correct
8 Correct 47 ms 7620 KB Output is correct
9 Correct 52 ms 7616 KB Output is correct
10 Correct 48 ms 7688 KB Output is correct
11 Correct 53 ms 7688 KB Output is correct
12 Correct 46 ms 7628 KB Output is correct
13 Correct 54 ms 7712 KB Output is correct
14 Correct 561 ms 73064 KB Output is correct
15 Correct 48 ms 7684 KB Output is correct
16 Correct 481 ms 72928 KB Output is correct
17 Correct 472 ms 72932 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 5 ms 1232 KB Output is correct
3 Correct 5 ms 1372 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 456 KB Output is correct
16 Correct 4 ms 1372 KB Output is correct
17 Correct 48 ms 7760 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 263 ms 57532 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 470 ms 73212 KB Output is correct
31 Correct 507 ms 72848 KB Output is correct
32 Correct 473 ms 73044 KB Output is correct
33 Correct 1 ms 456 KB Output is correct
34 Correct 458 ms 72760 KB Output is correct
35 Correct 452 ms 72988 KB Output is correct
36 Correct 497 ms 73132 KB Output is correct
37 Correct 556 ms 73112 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 52 ms 7688 KB Output is correct
40 Correct 47 ms 7632 KB Output is correct
41 Correct 41 ms 7628 KB Output is correct
42 Correct 50 ms 7680 KB Output is correct
43 Correct 49 ms 7620 KB Output is correct
44 Correct 57 ms 7804 KB Output is correct
45 Correct 45 ms 7736 KB Output is correct
46 Correct 49 ms 7616 KB Output is correct
47 Correct 45 ms 7624 KB Output is correct
48 Correct 47 ms 7636 KB Output is correct
49 Correct 62 ms 7624 KB Output is correct
50 Correct 46 ms 7616 KB Output is correct
51 Correct 480 ms 72848 KB Output is correct
52 Correct 495 ms 72956 KB Output is correct
53 Correct 564 ms 73496 KB Output is correct
54 Correct 49 ms 7624 KB Output is correct
55 Correct 46 ms 7816 KB Output is correct
56 Correct 98 ms 25768 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 49 ms 7652 KB Output is correct
59 Correct 50 ms 7700 KB Output is correct
60 Correct 554 ms 72580 KB Output is correct
61 Correct 51 ms 7628 KB Output is correct
62 Correct 50 ms 7620 KB Output is correct
63 Correct 50 ms 7620 KB Output is correct
64 Correct 47 ms 7620 KB Output is correct
65 Correct 52 ms 7616 KB Output is correct
66 Correct 48 ms 7688 KB Output is correct
67 Correct 53 ms 7688 KB Output is correct
68 Correct 46 ms 7628 KB Output is correct
69 Correct 54 ms 7712 KB Output is correct
70 Correct 561 ms 73064 KB Output is correct
71 Correct 48 ms 7684 KB Output is correct
72 Correct 481 ms 72928 KB Output is correct
73 Correct 472 ms 72932 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 5 ms 1372 KB Output is correct
80 Correct 523 ms 73136 KB Output is correct
81 Correct 526 ms 72936 KB Output is correct
82 Correct 531 ms 73364 KB Output is correct
83 Correct 529 ms 72976 KB Output is correct
84 Correct 514 ms 72784 KB Output is correct
85 Correct 586 ms 72924 KB Output is correct
86 Correct 101 ms 25784 KB Output is correct
87 Correct 1 ms 344 KB Output is correct