Submission #405266

# Submission time Handle Problem Language Result Execution time Memory
405266 2021-05-16T06:22:33 Z pavement Strange Device (APIO19_strange_device) C++17
100 / 100
631 ms 21136 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int N, A, B, P, f = -1, st, ans;
vector<ii> seg;

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> A >> B;
	if (A / __gcd(A, B + 1) > (1e18 + B - 1) / B) {
		for (int i = 1, l, r; i <= N; i++) {
			cin >> l >> r;
			ans += r - l + 1;
		}
		cout << ans << '\n';
		return 0;
	}
	P = A / __gcd(A, B + 1) * B;
	for (int i = 1, l, r; i <= N; i++) {
		cin >> l >> r;
		if (r - l + 1 >= 2 * P) return cout << P << '\n', 0;
		if (l + P - (l % P) > r) seg.eb(l % P, r % P);
		else seg.eb(l % P, P - 1), seg.eb(0, r % P);
	}
	sort(seg.begin(), seg.end());
	for (auto i : seg) {
		if (i.first > f) {
			if (f != -1) ans += f - st + 1;
			st = i.first;
		}
		f = max(f, i.second);
	}
	ans += f - st + 1;
	cout << ans << '\n';
}

Compilation message

strange_device.cpp:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   31 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 7 ms 996 KB Output is correct
3 Correct 7 ms 968 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 7 ms 1048 KB Output is correct
17 Correct 60 ms 5612 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 376 ms 21136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 578 ms 17124 KB Output is correct
3 Correct 538 ms 17136 KB Output is correct
4 Correct 536 ms 17104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 578 ms 17124 KB Output is correct
3 Correct 538 ms 17136 KB Output is correct
4 Correct 536 ms 17104 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 553 ms 17072 KB Output is correct
7 Correct 556 ms 17044 KB Output is correct
8 Correct 484 ms 17036 KB Output is correct
9 Correct 628 ms 17000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 578 ms 17124 KB Output is correct
3 Correct 538 ms 17136 KB Output is correct
4 Correct 536 ms 17104 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 49 ms 5680 KB Output is correct
7 Correct 55 ms 5592 KB Output is correct
8 Correct 49 ms 5660 KB Output is correct
9 Correct 56 ms 5712 KB Output is correct
10 Correct 50 ms 5688 KB Output is correct
11 Correct 51 ms 5700 KB Output is correct
12 Correct 50 ms 5692 KB Output is correct
13 Correct 61 ms 5600 KB Output is correct
14 Correct 46 ms 5688 KB Output is correct
15 Correct 57 ms 5688 KB Output is correct
16 Correct 51 ms 5676 KB Output is correct
17 Correct 50 ms 5692 KB Output is correct
18 Correct 483 ms 17224 KB Output is correct
19 Correct 591 ms 17056 KB Output is correct
20 Correct 557 ms 17060 KB Output is correct
21 Correct 54 ms 5340 KB Output is correct
22 Correct 46 ms 5344 KB Output is correct
23 Correct 155 ms 11948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 55 ms 5608 KB Output is correct
3 Correct 57 ms 5648 KB Output is correct
4 Correct 583 ms 17824 KB Output is correct
5 Correct 52 ms 5692 KB Output is correct
6 Correct 52 ms 5688 KB Output is correct
7 Correct 52 ms 5672 KB Output is correct
8 Correct 52 ms 5656 KB Output is correct
9 Correct 49 ms 5788 KB Output is correct
10 Correct 50 ms 5692 KB Output is correct
11 Correct 53 ms 5620 KB Output is correct
12 Correct 48 ms 5652 KB Output is correct
13 Correct 50 ms 5656 KB Output is correct
14 Correct 548 ms 18920 KB Output is correct
15 Correct 55 ms 5628 KB Output is correct
16 Correct 489 ms 17064 KB Output is correct
17 Correct 482 ms 17064 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 7 ms 996 KB Output is correct
3 Correct 7 ms 968 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 7 ms 1048 KB Output is correct
17 Correct 60 ms 5612 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 376 ms 21136 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 578 ms 17124 KB Output is correct
31 Correct 538 ms 17136 KB Output is correct
32 Correct 536 ms 17104 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 553 ms 17072 KB Output is correct
35 Correct 556 ms 17044 KB Output is correct
36 Correct 484 ms 17036 KB Output is correct
37 Correct 628 ms 17000 KB Output is correct
38 Correct 1 ms 316 KB Output is correct
39 Correct 49 ms 5680 KB Output is correct
40 Correct 55 ms 5592 KB Output is correct
41 Correct 49 ms 5660 KB Output is correct
42 Correct 56 ms 5712 KB Output is correct
43 Correct 50 ms 5688 KB Output is correct
44 Correct 51 ms 5700 KB Output is correct
45 Correct 50 ms 5692 KB Output is correct
46 Correct 61 ms 5600 KB Output is correct
47 Correct 46 ms 5688 KB Output is correct
48 Correct 57 ms 5688 KB Output is correct
49 Correct 51 ms 5676 KB Output is correct
50 Correct 50 ms 5692 KB Output is correct
51 Correct 483 ms 17224 KB Output is correct
52 Correct 591 ms 17056 KB Output is correct
53 Correct 557 ms 17060 KB Output is correct
54 Correct 54 ms 5340 KB Output is correct
55 Correct 46 ms 5344 KB Output is correct
56 Correct 155 ms 11948 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 55 ms 5608 KB Output is correct
59 Correct 57 ms 5648 KB Output is correct
60 Correct 583 ms 17824 KB Output is correct
61 Correct 52 ms 5692 KB Output is correct
62 Correct 52 ms 5688 KB Output is correct
63 Correct 52 ms 5672 KB Output is correct
64 Correct 52 ms 5656 KB Output is correct
65 Correct 49 ms 5788 KB Output is correct
66 Correct 50 ms 5692 KB Output is correct
67 Correct 53 ms 5620 KB Output is correct
68 Correct 48 ms 5652 KB Output is correct
69 Correct 50 ms 5656 KB Output is correct
70 Correct 548 ms 18920 KB Output is correct
71 Correct 55 ms 5628 KB Output is correct
72 Correct 489 ms 17064 KB Output is correct
73 Correct 482 ms 17064 KB Output is correct
74 Correct 1 ms 204 KB Output is correct
75 Correct 1 ms 316 KB Output is correct
76 Correct 1 ms 204 KB Output is correct
77 Correct 1 ms 320 KB Output is correct
78 Correct 1 ms 204 KB Output is correct
79 Correct 6 ms 976 KB Output is correct
80 Correct 582 ms 17044 KB Output is correct
81 Correct 631 ms 17096 KB Output is correct
82 Correct 523 ms 16972 KB Output is correct
83 Correct 530 ms 17060 KB Output is correct
84 Correct 524 ms 16932 KB Output is correct
85 Correct 536 ms 17144 KB Output is correct
86 Correct 159 ms 11928 KB Output is correct
87 Correct 1 ms 204 KB Output is correct