Submission #210742

# Submission time Handle Problem Language Result Execution time Memory
210742 2020-03-18T09:45:12 Z islingr Strange Device (APIO19_strange_device) C++14
100 / 100
2248 ms 30968 KB
/*
	22/02/2020
	islingr
*/

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)

#define all(x) begin(x), end(x)
#define eb(x...) emplace_back(x)

using ll = int64_t;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

struct event {
	ll l, r;
	event(ll a, ll b) : l{a}, r{b} { }
	bool operator<(const event &e) const { return r < e.r; }
};

const ll inf = 1e18;

ll solve () {
	int n; ll a, b; cin >> n >> a >> b;
	ll g = __gcd(a, b + 1), p;
	if (a / g > inf / b) p = inf;
	else p = a / g * b;

	vector<event> v; v.reserve(2 * n);
	rep(i, 0, n) {
		ll l, r; cin >> l >> r;
		if (r - l + 1 < p) {
			l %= p; r %= p;
			if (l <= r) v.eb(l, r);
			else v.eb(0, r), v.eb(l, p - 1);
		} else return p;
	}
	sort(all(v));
	ll ans = 0;
	while (!v.empty()) {
		event top = v.back(); v.pop_back();
		while (!v.empty() && top.l <= v.back().r) {
			ckmin(top.l, v.back().l);
			v.pop_back();
		}
		ans += top.r - top.l + 1;
	}
	return ans;
}

signed main() { cout << solve(); }
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 26 ms 760 KB Output is correct
3 Correct 29 ms 760 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 26 ms 760 KB Output is correct
17 Correct 221 ms 2168 KB Output is correct
18 Correct 5 ms 128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 7 ms 380 KB Output is correct
3 Correct 7 ms 376 KB Output is correct
4 Correct 7 ms 376 KB Output is correct
5 Correct 1502 ms 16276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 2138 ms 16248 KB Output is correct
3 Correct 2139 ms 17272 KB Output is correct
4 Correct 2128 ms 16248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 2138 ms 16248 KB Output is correct
3 Correct 2139 ms 17272 KB Output is correct
4 Correct 2128 ms 16248 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 2143 ms 16224 KB Output is correct
7 Correct 2119 ms 16248 KB Output is correct
8 Correct 2127 ms 16248 KB Output is correct
9 Correct 2226 ms 16632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 2138 ms 16248 KB Output is correct
3 Correct 2139 ms 17272 KB Output is correct
4 Correct 2128 ms 16248 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 220 ms 2040 KB Output is correct
7 Correct 219 ms 2044 KB Output is correct
8 Correct 231 ms 2040 KB Output is correct
9 Correct 223 ms 2040 KB Output is correct
10 Correct 215 ms 3064 KB Output is correct
11 Correct 218 ms 2248 KB Output is correct
12 Correct 219 ms 2936 KB Output is correct
13 Correct 226 ms 3064 KB Output is correct
14 Correct 218 ms 3064 KB Output is correct
15 Correct 227 ms 3064 KB Output is correct
16 Correct 225 ms 3064 KB Output is correct
17 Correct 224 ms 3056 KB Output is correct
18 Correct 2191 ms 17016 KB Output is correct
19 Correct 2146 ms 16216 KB Output is correct
20 Correct 2235 ms 16120 KB Output is correct
21 Correct 219 ms 2040 KB Output is correct
22 Correct 217 ms 2040 KB Output is correct
23 Correct 723 ms 5752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 219 ms 2040 KB Output is correct
3 Correct 225 ms 2040 KB Output is correct
4 Correct 2246 ms 16120 KB Output is correct
5 Correct 222 ms 2044 KB Output is correct
6 Correct 221 ms 2040 KB Output is correct
7 Correct 220 ms 2040 KB Output is correct
8 Correct 223 ms 2040 KB Output is correct
9 Correct 221 ms 2040 KB Output is correct
10 Correct 220 ms 2040 KB Output is correct
11 Correct 222 ms 2044 KB Output is correct
12 Correct 216 ms 2040 KB Output is correct
13 Correct 226 ms 2040 KB Output is correct
14 Correct 2248 ms 16120 KB Output is correct
15 Correct 223 ms 2040 KB Output is correct
16 Correct 2139 ms 16120 KB Output is correct
17 Correct 2130 ms 16120 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 26 ms 760 KB Output is correct
3 Correct 29 ms 760 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 4 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 26 ms 760 KB Output is correct
17 Correct 221 ms 2168 KB Output is correct
18 Correct 5 ms 128 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 256 KB Output is correct
21 Correct 5 ms 380 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 7 ms 380 KB Output is correct
26 Correct 7 ms 376 KB Output is correct
27 Correct 7 ms 376 KB Output is correct
28 Correct 1502 ms 16276 KB Output is correct
29 Correct 5 ms 256 KB Output is correct
30 Correct 2138 ms 16248 KB Output is correct
31 Correct 2139 ms 17272 KB Output is correct
32 Correct 2128 ms 16248 KB Output is correct
33 Correct 5 ms 256 KB Output is correct
34 Correct 2143 ms 16224 KB Output is correct
35 Correct 2119 ms 16248 KB Output is correct
36 Correct 2127 ms 16248 KB Output is correct
37 Correct 2226 ms 16632 KB Output is correct
38 Correct 5 ms 256 KB Output is correct
39 Correct 220 ms 2040 KB Output is correct
40 Correct 219 ms 2044 KB Output is correct
41 Correct 231 ms 2040 KB Output is correct
42 Correct 223 ms 2040 KB Output is correct
43 Correct 215 ms 3064 KB Output is correct
44 Correct 218 ms 2248 KB Output is correct
45 Correct 219 ms 2936 KB Output is correct
46 Correct 226 ms 3064 KB Output is correct
47 Correct 218 ms 3064 KB Output is correct
48 Correct 227 ms 3064 KB Output is correct
49 Correct 225 ms 3064 KB Output is correct
50 Correct 224 ms 3056 KB Output is correct
51 Correct 2191 ms 17016 KB Output is correct
52 Correct 2146 ms 16216 KB Output is correct
53 Correct 2235 ms 16120 KB Output is correct
54 Correct 219 ms 2040 KB Output is correct
55 Correct 217 ms 2040 KB Output is correct
56 Correct 723 ms 5752 KB Output is correct
57 Correct 5 ms 256 KB Output is correct
58 Correct 219 ms 2040 KB Output is correct
59 Correct 225 ms 2040 KB Output is correct
60 Correct 2246 ms 16120 KB Output is correct
61 Correct 222 ms 2044 KB Output is correct
62 Correct 221 ms 2040 KB Output is correct
63 Correct 220 ms 2040 KB Output is correct
64 Correct 223 ms 2040 KB Output is correct
65 Correct 221 ms 2040 KB Output is correct
66 Correct 220 ms 2040 KB Output is correct
67 Correct 222 ms 2044 KB Output is correct
68 Correct 216 ms 2040 KB Output is correct
69 Correct 226 ms 2040 KB Output is correct
70 Correct 2248 ms 16120 KB Output is correct
71 Correct 223 ms 2040 KB Output is correct
72 Correct 2139 ms 16120 KB Output is correct
73 Correct 2130 ms 16120 KB Output is correct
74 Correct 5 ms 256 KB Output is correct
75 Correct 5 ms 256 KB Output is correct
76 Correct 5 ms 256 KB Output is correct
77 Correct 5 ms 256 KB Output is correct
78 Correct 5 ms 256 KB Output is correct
79 Correct 26 ms 888 KB Output is correct
80 Correct 2233 ms 28664 KB Output is correct
81 Correct 2240 ms 29432 KB Output is correct
82 Correct 2195 ms 30172 KB Output is correct
83 Correct 2232 ms 30968 KB Output is correct
84 Correct 2214 ms 28312 KB Output is correct
85 Correct 2219 ms 29056 KB Output is correct
86 Correct 713 ms 18168 KB Output is correct
87 Correct 5 ms 256 KB Output is correct