Submission #734541

# Submission time Handle Problem Language Result Execution time Memory
734541 2023-05-02T15:31:18 Z hollwo_pelw New Home (APIO18_new_home) C++17
100 / 100
2032 ms 99208 KB
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>

using namespace std;
// using namespace __gnu_cxx;
// using namespace __gnu_pbds;

void Hollwo_Pelw();

signed main(){
#ifndef hollwo_pelw_local
	if (fopen(".inp", "r"))
		assert(freopen(".inp", "r", stdin)), assert(freopen(".out", "w", stdout));
#else
	using namespace chrono;
	auto start = steady_clock::now();
#endif
	cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
	int testcases = 1;
	// cin >> testcases;
	for (int test = 1; test <= testcases; test++){
		// cout << "Case #" << test << ": ";
		Hollwo_Pelw();
	}
#ifdef hollwo_pelw_local
	auto end = steady_clock::now();
	cout << "\nExecution time : " << duration_cast<milliseconds> (end - start).count() << "[ms]" << endl;
#endif
}

const int N = 3e5 + 5, maxC = 1e8;

int n, k, q, x[N], y[2 * N], st[N * 8], res[N];
vector<int> valy = {0};
vector<pair<int, int>> stores[N];

struct query_t {
	int x, y, id;
	bool operator < (const query_t &oth) const {
		return tuple<int, int, int>(x, y, id) < tuple<int, int, int>(oth.x, oth.y, oth.id); 
	}
} queries[N];
struct update_t {
	int x, v, ly, ry;
	bool operator < (const update_t &oth) const {
		return tuple<int, int, int, int>(x, v, ly, ry) < tuple<int, int, int, int>(oth.x, oth.v, oth.ly, oth.ry);
	}
};

struct cmp {
	bool operator () (const int &i, const int &j) const {
		return x[i] < x[j] || (x[i] == x[j] && i < j);
	}
};

inline void update(int l, int r, int v) {
	for (l += valy.size(), r += valy.size(); l < r; l >>= 1, r >>= 1) {
		if (l & 1) st[l] = max(st[l], v), l ++;
		if (r & 1) r --, st[r] = max(st[r], v);
	}
}

inline int query(int p) {
	int res = 0;
	for (p += valy.size(); p; p >>= 1) {
		res = max(res, st[p]);
	}
	return res;
}

void solve() {
	// cout << "SOLVE" << endl;

	map<int, int, cmp> mp;
	vector<update_t> upds;

	for (int i = 1; i <= k; i++) {
		// cout << "STORE " << i << '\n';
		mp[0] = mp[n + 1] = 0;

		for (auto [y, id] : stores[i]) {
			if (mp.count(id)) {
				// cout << "REM " << id << " at time " << y << '\n';
				auto p = mp.find(id), r = next(p), l = prev(p);
				upds.push_back({(x[p -> first] + x[r -> first] + 1) / 2, x[r -> first], r -> second, y});
				// cout << "-> " << upds.back().x << ' ' << upds.back().v << ' ' << upds.back().ly << ' ' << upds.back().ry << '\n';
				upds.push_back({(x[l -> first] + x[p -> first] + 1) / 2, x[p -> first], p -> second, y});
				// cout << "-> " << upds.back().x << ' ' << upds.back().v << ' ' << upds.back().ly << ' ' << upds.back().ry << '\n';
				r -> second = y;
				mp.erase(p);
			} else {
				// cout << "ADD " << id << " at time " << y << '\n';
				mp[id] = y;
				auto p = mp.find(id), r = next(p), l = prev(p);
				upds.push_back({(x[l -> first] + x[r -> first] + 1) / 2, x[r -> first], r -> second, y});
				// cout << "-> " << upds.back().x << ' ' << upds.back().v << ' ' << upds.back().ly << ' ' << upds.back().ry << '\n';
				r -> second = y;
			}
		}

		upds.push_back({0, 2 * maxC, mp[n + 1], (int) valy.size()});
	}
	sort(upds.begin(), upds.end());

	// cout << "--------------\n";

	memset(st, 0, sizeof st);
	for (int i = 1, j = 0; i <= q; i++) {
		// cout << "POS = " << queries[i].x << '\n';
		for (; j < (int) upds.size() && upds[j].x <= queries[i].x; j ++) {
			auto p = upds[j]; update(p.ly, p.ry, p.v);
			// cout << "UPD " << p.ly << ' ' << p.ry << ' ' << p.v << '\n';
		}
		// cout << "ASK time = " << queries[i].y << '\n';
		res[queries[i].id] = max(res[queries[i].id], query(queries[i].y) - queries[i].x);
	}
}

void Hollwo_Pelw(){
	cin >> n >> k >> q;
	for (int i = 1, tp, ly, ry; i <= n; i++) {
		cin >> x[i] >> tp >> ly >> ry, ++ ry;
		stores[tp].push_back({ly, i});
		stores[tp].push_back({ry, i});
		valy.push_back(ly);
		valy.push_back(ry);
	}
	x[0] = - 2 * maxC, x[n + 1] = 2 * maxC;

	sort(valy.begin(), valy.end());
	for (int i = 1; i <= k; i++) {
		for (auto &[y, id] : stores[i])
			y = upper_bound(valy.begin(), valy.end(), y) - valy.begin() - 1; 
		sort(stores[i].begin(), stores[i].end());
	}
	for (int i = 1; i <= q; i++) {
		cin >> queries[i].x >> queries[i].y;
		queries[i].id = i;
		queries[i].y = upper_bound(valy.begin(), valy.end(), queries[i].y) - valy.begin() - 1;
	}

	sort(queries + 1, queries + q + 1);

	for (int iter = 2; iter --; ) {

		solve();

		for (int i = 1; i <= n; i++)
			x[i] = maxC - x[i];
		for (int i = 1; i <= q; i++)
			queries[i].x = maxC - queries[i].x;
		reverse(queries + 1, queries + q + 1);
	}

	for (int i = 1; i <= q; i++) {
		cout << (res[i] >= maxC ? -1 : res[i]) << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 16772 KB Output is correct
2 Correct 13 ms 16788 KB Output is correct
3 Correct 11 ms 16736 KB Output is correct
4 Correct 9 ms 16724 KB Output is correct
5 Correct 10 ms 16852 KB Output is correct
6 Correct 10 ms 16852 KB Output is correct
7 Correct 12 ms 16852 KB Output is correct
8 Correct 9 ms 16852 KB Output is correct
9 Correct 11 ms 16852 KB Output is correct
10 Correct 11 ms 16904 KB Output is correct
11 Correct 10 ms 16880 KB Output is correct
12 Correct 10 ms 16852 KB Output is correct
13 Correct 11 ms 16880 KB Output is correct
14 Correct 10 ms 16876 KB Output is correct
15 Correct 10 ms 16872 KB Output is correct
16 Correct 10 ms 16776 KB Output is correct
17 Correct 10 ms 16780 KB Output is correct
18 Correct 10 ms 16852 KB Output is correct
19 Correct 10 ms 16780 KB Output is correct
20 Correct 10 ms 16792 KB Output is correct
21 Correct 9 ms 16852 KB Output is correct
22 Correct 11 ms 16876 KB Output is correct
23 Correct 10 ms 16776 KB Output is correct
24 Correct 10 ms 16880 KB Output is correct
25 Correct 12 ms 16872 KB Output is correct
26 Correct 10 ms 16852 KB Output is correct
27 Correct 10 ms 16852 KB Output is correct
28 Correct 12 ms 16852 KB Output is correct
29 Correct 11 ms 16852 KB Output is correct
30 Correct 11 ms 16852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 16772 KB Output is correct
2 Correct 13 ms 16788 KB Output is correct
3 Correct 11 ms 16736 KB Output is correct
4 Correct 9 ms 16724 KB Output is correct
5 Correct 10 ms 16852 KB Output is correct
6 Correct 10 ms 16852 KB Output is correct
7 Correct 12 ms 16852 KB Output is correct
8 Correct 9 ms 16852 KB Output is correct
9 Correct 11 ms 16852 KB Output is correct
10 Correct 11 ms 16904 KB Output is correct
11 Correct 10 ms 16880 KB Output is correct
12 Correct 10 ms 16852 KB Output is correct
13 Correct 11 ms 16880 KB Output is correct
14 Correct 10 ms 16876 KB Output is correct
15 Correct 10 ms 16872 KB Output is correct
16 Correct 10 ms 16776 KB Output is correct
17 Correct 10 ms 16780 KB Output is correct
18 Correct 10 ms 16852 KB Output is correct
19 Correct 10 ms 16780 KB Output is correct
20 Correct 10 ms 16792 KB Output is correct
21 Correct 9 ms 16852 KB Output is correct
22 Correct 11 ms 16876 KB Output is correct
23 Correct 10 ms 16776 KB Output is correct
24 Correct 10 ms 16880 KB Output is correct
25 Correct 12 ms 16872 KB Output is correct
26 Correct 10 ms 16852 KB Output is correct
27 Correct 10 ms 16852 KB Output is correct
28 Correct 12 ms 16852 KB Output is correct
29 Correct 11 ms 16852 KB Output is correct
30 Correct 11 ms 16852 KB Output is correct
31 Correct 245 ms 30104 KB Output is correct
32 Correct 182 ms 27828 KB Output is correct
33 Correct 247 ms 29360 KB Output is correct
34 Correct 222 ms 30096 KB Output is correct
35 Correct 236 ms 29428 KB Output is correct
36 Correct 276 ms 29708 KB Output is correct
37 Correct 218 ms 29836 KB Output is correct
38 Correct 233 ms 29200 KB Output is correct
39 Correct 191 ms 29772 KB Output is correct
40 Correct 199 ms 29080 KB Output is correct
41 Correct 159 ms 29236 KB Output is correct
42 Correct 156 ms 29724 KB Output is correct
43 Correct 96 ms 29304 KB Output is correct
44 Correct 159 ms 29624 KB Output is correct
45 Correct 146 ms 29396 KB Output is correct
46 Correct 141 ms 29228 KB Output is correct
47 Correct 137 ms 29480 KB Output is correct
48 Correct 119 ms 29252 KB Output is correct
49 Correct 126 ms 29516 KB Output is correct
50 Correct 147 ms 29952 KB Output is correct
51 Correct 122 ms 29516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 737 ms 78016 KB Output is correct
2 Correct 1055 ms 75328 KB Output is correct
3 Correct 721 ms 97688 KB Output is correct
4 Correct 702 ms 78588 KB Output is correct
5 Correct 1576 ms 81880 KB Output is correct
6 Correct 1094 ms 76108 KB Output is correct
7 Correct 563 ms 97564 KB Output is correct
8 Correct 585 ms 77664 KB Output is correct
9 Correct 610 ms 76336 KB Output is correct
10 Correct 796 ms 74620 KB Output is correct
11 Correct 687 ms 74856 KB Output is correct
12 Correct 686 ms 74700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 927 ms 75544 KB Output is correct
2 Correct 830 ms 66604 KB Output is correct
3 Correct 1280 ms 75764 KB Output is correct
4 Correct 937 ms 97052 KB Output is correct
5 Correct 842 ms 77616 KB Output is correct
6 Correct 897 ms 78464 KB Output is correct
7 Correct 2032 ms 85608 KB Output is correct
8 Correct 1425 ms 76912 KB Output is correct
9 Correct 790 ms 97200 KB Output is correct
10 Correct 782 ms 77348 KB Output is correct
11 Correct 851 ms 75396 KB Output is correct
12 Correct 1047 ms 73708 KB Output is correct
13 Correct 764 ms 74276 KB Output is correct
14 Correct 763 ms 73172 KB Output is correct
15 Correct 843 ms 74468 KB Output is correct
16 Correct 858 ms 74372 KB Output is correct
17 Correct 933 ms 74684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 16772 KB Output is correct
2 Correct 13 ms 16788 KB Output is correct
3 Correct 11 ms 16736 KB Output is correct
4 Correct 9 ms 16724 KB Output is correct
5 Correct 10 ms 16852 KB Output is correct
6 Correct 10 ms 16852 KB Output is correct
7 Correct 12 ms 16852 KB Output is correct
8 Correct 9 ms 16852 KB Output is correct
9 Correct 11 ms 16852 KB Output is correct
10 Correct 11 ms 16904 KB Output is correct
11 Correct 10 ms 16880 KB Output is correct
12 Correct 10 ms 16852 KB Output is correct
13 Correct 11 ms 16880 KB Output is correct
14 Correct 10 ms 16876 KB Output is correct
15 Correct 10 ms 16872 KB Output is correct
16 Correct 10 ms 16776 KB Output is correct
17 Correct 10 ms 16780 KB Output is correct
18 Correct 10 ms 16852 KB Output is correct
19 Correct 10 ms 16780 KB Output is correct
20 Correct 10 ms 16792 KB Output is correct
21 Correct 9 ms 16852 KB Output is correct
22 Correct 11 ms 16876 KB Output is correct
23 Correct 10 ms 16776 KB Output is correct
24 Correct 10 ms 16880 KB Output is correct
25 Correct 12 ms 16872 KB Output is correct
26 Correct 10 ms 16852 KB Output is correct
27 Correct 10 ms 16852 KB Output is correct
28 Correct 12 ms 16852 KB Output is correct
29 Correct 11 ms 16852 KB Output is correct
30 Correct 11 ms 16852 KB Output is correct
31 Correct 245 ms 30104 KB Output is correct
32 Correct 182 ms 27828 KB Output is correct
33 Correct 247 ms 29360 KB Output is correct
34 Correct 222 ms 30096 KB Output is correct
35 Correct 236 ms 29428 KB Output is correct
36 Correct 276 ms 29708 KB Output is correct
37 Correct 218 ms 29836 KB Output is correct
38 Correct 233 ms 29200 KB Output is correct
39 Correct 191 ms 29772 KB Output is correct
40 Correct 199 ms 29080 KB Output is correct
41 Correct 159 ms 29236 KB Output is correct
42 Correct 156 ms 29724 KB Output is correct
43 Correct 96 ms 29304 KB Output is correct
44 Correct 159 ms 29624 KB Output is correct
45 Correct 146 ms 29396 KB Output is correct
46 Correct 141 ms 29228 KB Output is correct
47 Correct 137 ms 29480 KB Output is correct
48 Correct 119 ms 29252 KB Output is correct
49 Correct 126 ms 29516 KB Output is correct
50 Correct 147 ms 29952 KB Output is correct
51 Correct 122 ms 29516 KB Output is correct
52 Correct 195 ms 31236 KB Output is correct
53 Correct 201 ms 31168 KB Output is correct
54 Correct 199 ms 30276 KB Output is correct
55 Correct 169 ms 30048 KB Output is correct
56 Correct 162 ms 30456 KB Output is correct
57 Correct 167 ms 29580 KB Output is correct
58 Correct 168 ms 30272 KB Output is correct
59 Correct 169 ms 30628 KB Output is correct
60 Correct 159 ms 29936 KB Output is correct
61 Correct 98 ms 30600 KB Output is correct
62 Correct 183 ms 31284 KB Output is correct
63 Correct 195 ms 30416 KB Output is correct
64 Correct 183 ms 29972 KB Output is correct
65 Correct 179 ms 29876 KB Output is correct
66 Correct 151 ms 29712 KB Output is correct
67 Correct 150 ms 28016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 16772 KB Output is correct
2 Correct 13 ms 16788 KB Output is correct
3 Correct 11 ms 16736 KB Output is correct
4 Correct 9 ms 16724 KB Output is correct
5 Correct 10 ms 16852 KB Output is correct
6 Correct 10 ms 16852 KB Output is correct
7 Correct 12 ms 16852 KB Output is correct
8 Correct 9 ms 16852 KB Output is correct
9 Correct 11 ms 16852 KB Output is correct
10 Correct 11 ms 16904 KB Output is correct
11 Correct 10 ms 16880 KB Output is correct
12 Correct 10 ms 16852 KB Output is correct
13 Correct 11 ms 16880 KB Output is correct
14 Correct 10 ms 16876 KB Output is correct
15 Correct 10 ms 16872 KB Output is correct
16 Correct 10 ms 16776 KB Output is correct
17 Correct 10 ms 16780 KB Output is correct
18 Correct 10 ms 16852 KB Output is correct
19 Correct 10 ms 16780 KB Output is correct
20 Correct 10 ms 16792 KB Output is correct
21 Correct 9 ms 16852 KB Output is correct
22 Correct 11 ms 16876 KB Output is correct
23 Correct 10 ms 16776 KB Output is correct
24 Correct 10 ms 16880 KB Output is correct
25 Correct 12 ms 16872 KB Output is correct
26 Correct 10 ms 16852 KB Output is correct
27 Correct 10 ms 16852 KB Output is correct
28 Correct 12 ms 16852 KB Output is correct
29 Correct 11 ms 16852 KB Output is correct
30 Correct 11 ms 16852 KB Output is correct
31 Correct 245 ms 30104 KB Output is correct
32 Correct 182 ms 27828 KB Output is correct
33 Correct 247 ms 29360 KB Output is correct
34 Correct 222 ms 30096 KB Output is correct
35 Correct 236 ms 29428 KB Output is correct
36 Correct 276 ms 29708 KB Output is correct
37 Correct 218 ms 29836 KB Output is correct
38 Correct 233 ms 29200 KB Output is correct
39 Correct 191 ms 29772 KB Output is correct
40 Correct 199 ms 29080 KB Output is correct
41 Correct 159 ms 29236 KB Output is correct
42 Correct 156 ms 29724 KB Output is correct
43 Correct 96 ms 29304 KB Output is correct
44 Correct 159 ms 29624 KB Output is correct
45 Correct 146 ms 29396 KB Output is correct
46 Correct 141 ms 29228 KB Output is correct
47 Correct 137 ms 29480 KB Output is correct
48 Correct 119 ms 29252 KB Output is correct
49 Correct 126 ms 29516 KB Output is correct
50 Correct 147 ms 29952 KB Output is correct
51 Correct 122 ms 29516 KB Output is correct
52 Correct 737 ms 78016 KB Output is correct
53 Correct 1055 ms 75328 KB Output is correct
54 Correct 721 ms 97688 KB Output is correct
55 Correct 702 ms 78588 KB Output is correct
56 Correct 1576 ms 81880 KB Output is correct
57 Correct 1094 ms 76108 KB Output is correct
58 Correct 563 ms 97564 KB Output is correct
59 Correct 585 ms 77664 KB Output is correct
60 Correct 610 ms 76336 KB Output is correct
61 Correct 796 ms 74620 KB Output is correct
62 Correct 687 ms 74856 KB Output is correct
63 Correct 686 ms 74700 KB Output is correct
64 Correct 927 ms 75544 KB Output is correct
65 Correct 830 ms 66604 KB Output is correct
66 Correct 1280 ms 75764 KB Output is correct
67 Correct 937 ms 97052 KB Output is correct
68 Correct 842 ms 77616 KB Output is correct
69 Correct 897 ms 78464 KB Output is correct
70 Correct 2032 ms 85608 KB Output is correct
71 Correct 1425 ms 76912 KB Output is correct
72 Correct 790 ms 97200 KB Output is correct
73 Correct 782 ms 77348 KB Output is correct
74 Correct 851 ms 75396 KB Output is correct
75 Correct 1047 ms 73708 KB Output is correct
76 Correct 764 ms 74276 KB Output is correct
77 Correct 763 ms 73172 KB Output is correct
78 Correct 843 ms 74468 KB Output is correct
79 Correct 858 ms 74372 KB Output is correct
80 Correct 933 ms 74684 KB Output is correct
81 Correct 195 ms 31236 KB Output is correct
82 Correct 201 ms 31168 KB Output is correct
83 Correct 199 ms 30276 KB Output is correct
84 Correct 169 ms 30048 KB Output is correct
85 Correct 162 ms 30456 KB Output is correct
86 Correct 167 ms 29580 KB Output is correct
87 Correct 168 ms 30272 KB Output is correct
88 Correct 169 ms 30628 KB Output is correct
89 Correct 159 ms 29936 KB Output is correct
90 Correct 98 ms 30600 KB Output is correct
91 Correct 183 ms 31284 KB Output is correct
92 Correct 195 ms 30416 KB Output is correct
93 Correct 183 ms 29972 KB Output is correct
94 Correct 179 ms 29876 KB Output is correct
95 Correct 151 ms 29712 KB Output is correct
96 Correct 150 ms 28016 KB Output is correct
97 Correct 1156 ms 99096 KB Output is correct
98 Correct 945 ms 67220 KB Output is correct
99 Correct 1475 ms 77304 KB Output is correct
100 Correct 1146 ms 99208 KB Output is correct
101 Correct 1070 ms 79996 KB Output is correct
102 Correct 1544 ms 77872 KB Output is correct
103 Correct 1263 ms 77360 KB Output is correct
104 Correct 1387 ms 74864 KB Output is correct
105 Correct 1084 ms 76724 KB Output is correct
106 Correct 1191 ms 74372 KB Output is correct
107 Correct 927 ms 79120 KB Output is correct
108 Correct 965 ms 97264 KB Output is correct
109 Correct 855 ms 78444 KB Output is correct
110 Correct 992 ms 80072 KB Output is correct
111 Correct 1032 ms 97620 KB Output is correct
112 Correct 897 ms 78072 KB Output is correct
113 Correct 548 ms 96120 KB Output is correct
114 Correct 1107 ms 99036 KB Output is correct
115 Correct 1124 ms 97456 KB Output is correct
116 Correct 997 ms 79112 KB Output is correct
117 Correct 1084 ms 78272 KB Output is correct
118 Correct 1133 ms 77536 KB Output is correct
119 Correct 772 ms 68948 KB Output is correct
120 Correct 610 ms 74692 KB Output is correct
121 Correct 589 ms 75512 KB Output is correct
122 Correct 576 ms 75832 KB Output is correct
123 Correct 635 ms 76204 KB Output is correct
124 Correct 754 ms 76348 KB Output is correct
125 Correct 635 ms 76704 KB Output is correct
126 Correct 813 ms 78812 KB Output is correct