# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
934923 |
2024-02-28T07:53:06 Z |
IBory |
New Home (APIO18_new_home) |
C++17 |
|
2063 ms |
509476 KB |
#include <bits/stdc++.h>
#define pii pair<int, int>
using namespace std;
const int SZ = 1 << 20;
int P[SZ], S[SZ], X[SZ], ans[SZ];
multiset<int> CX[SZ];
struct Seg {
priority_queue<int> P[SZ], E[SZ];
int T[SZ << 1];
Seg() {
fill(T, T + SZ * 2, -1E9);
}
void Update(int i, int v, bool e, int sL = 1, int sR = SZ, int n = 1) {
(e ? E[i] : P[i]).push(v);
while (!E[i].empty() && !P[i].empty() && E[i].top() == P[i].top()) E[i].pop(), P[i].pop();
T[i += SZ - 1] = (P[i].empty() ? -1e9 : P[i].top());
while (i >>= 1) T[i] = max(T[i * 2], T[i * 2 + 1]);
}
int Query(int L, int R, int sL = 1, int sR = SZ, int n = 1) {
if (R < sL || sR < L) return -1e9;
if (L <= sL && sR <= R) return T[n];
int mid = (sL + sR) >> 1;
return max(Query(L, R, sL, mid, n * 2), Query(L, R, mid + 1, sR, n * 2 + 1));
}
} T1, T2;
vector<int> UX;
int Find(int x) {
return lower_bound(UX.begin(), UX.end(), x) - UX.begin();
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int N, K, Q;
cin >> N >> K >> Q;
vector<pii> ord;
for (int i = 1; i <= N; ++i) {
int a, b;
cin >> P[i] >> S[i] >> a >> b;
P[i] <<= 1;
ord.emplace_back(a, i);
ord.emplace_back(b + 1, -i);
}
for (int i = 1; i <= Q; ++i) {
int t;
cin >> X[i] >> t;
X[i] <<= 1;
ord.emplace_back(t, SZ + i);
}
sort(ord.begin(), ord.end());
UX.push_back(-1); UX.push_back(1); UX.push_back(1e8);
for (auto [_, id] : ord) {
// Line Add
if (0 < id && id < SZ) {
int pos = P[abs(id)], type = S[abs(id)];
UX.push_back(pos);
auto it = CX[type].insert(pos);
if (it != CX[type].begin()) {
int h = abs(pos - *prev(it)) / 2;
UX.push_back(*prev(it) + h);
}
if (next(it) != CX[type].end()) {
int h = abs(pos - *next(it)) / 2;
UX.push_back(pos + h);
}
}
// Line Erase
else if (id < 0) {
int pos = P[abs(id)], type = S[abs(id)];
auto it = CX[type].find(pos);
if (it != CX[type].begin() && next(it) != CX[type].end()) {
int h = abs(*next(it) - *prev(it)) / 2;
UX.push_back(*prev(it) + h);
}
CX[type].erase(it);
}
else UX.push_back(X[id - SZ]);
}
sort(UX.begin(), UX.end());
UX.erase(unique(UX.begin(), UX.end()), UX.end());
memset(ans, 0xf3, sizeof(ans));
int curOpen = 0, L_LIM = 1, R_LIM = UX.size() - 1;
for (auto [_, id] : ord) {
// Line Add/Erase
if (id < SZ) {
int pos = P[abs(id)], type = S[abs(id)], x = Find(pos);
bool out = id < 0;
if (CX[type].empty()) curOpen++;
auto it = (out ? CX[type].find(pos) : CX[type].insert(pos));
bool isPrev = it != CX[type].begin();
bool isNext = next(it) != CX[type].end();
int ph = (isPrev ? Find(pos - (pos - *prev(it)) / 2) : L_LIM);
int nh = (isNext ? Find(pos + (*next(it) - pos) / 2) : R_LIM);
int all = (isPrev && isNext ? Find(*next(it) - (*next(it) - *prev(it)) / 2) : 0);
// Add
T2.Update(ph, pos, out);
T1.Update(nh, -pos, out);
// Modify
if (isNext) {
T2.Update(isPrev ? all : L_LIM, *next(it), !out);
T2.Update(nh, *next(it), out);
}
if (isPrev) {
T1.Update(isNext ? all : R_LIM, -*prev(it), !out);
T1.Update(ph, -*prev(it), out);
}
if (out) CX[type].erase(it);
if (CX[type].empty()) curOpen--;
}
// Query
else if (curOpen == K) {
id -= SZ;
int x = X[id], p = Find(x);
int b1 = T1.Query(p, SZ);
int b2 = T2.Query(1, p);
ans[id] = max(x + b1, b2 - x);
}
}
for (int i = 1; i <= Q; ++i) cout << (ans[i] < 0 ? -1 : ans[i] / 2) << '\n';
return 0;
}
Compilation message
new_home.cpp: In member function 'void Seg::Update(int, int, bool, int, int, int)':
new_home.cpp:18:7: warning: operation on 'i' may be undefined [-Wsequence-point]
18 | T[i += SZ - 1] = (P[i].empty() ? -1e9 : P[i].top());
| ~~^~~~~~~~~
new_home.cpp: In function 'int main()':
new_home.cpp:90:45: warning: unused variable 'x' [-Wunused-variable]
90 | int pos = P[abs(id)], type = S[abs(id)], x = Find(pos);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
205648 KB |
Output is correct |
2 |
Correct |
45 ms |
205564 KB |
Output is correct |
3 |
Correct |
46 ms |
205808 KB |
Output is correct |
4 |
Correct |
45 ms |
205648 KB |
Output is correct |
5 |
Correct |
46 ms |
205788 KB |
Output is correct |
6 |
Correct |
50 ms |
205800 KB |
Output is correct |
7 |
Correct |
51 ms |
205744 KB |
Output is correct |
8 |
Correct |
46 ms |
205916 KB |
Output is correct |
9 |
Correct |
46 ms |
205872 KB |
Output is correct |
10 |
Correct |
50 ms |
205904 KB |
Output is correct |
11 |
Correct |
45 ms |
205888 KB |
Output is correct |
12 |
Correct |
48 ms |
205916 KB |
Output is correct |
13 |
Correct |
45 ms |
205656 KB |
Output is correct |
14 |
Correct |
45 ms |
205808 KB |
Output is correct |
15 |
Correct |
52 ms |
205656 KB |
Output is correct |
16 |
Correct |
51 ms |
205900 KB |
Output is correct |
17 |
Correct |
46 ms |
205904 KB |
Output is correct |
18 |
Correct |
45 ms |
205908 KB |
Output is correct |
19 |
Correct |
46 ms |
205796 KB |
Output is correct |
20 |
Correct |
46 ms |
205908 KB |
Output is correct |
21 |
Correct |
45 ms |
205648 KB |
Output is correct |
22 |
Correct |
46 ms |
205660 KB |
Output is correct |
23 |
Correct |
45 ms |
205836 KB |
Output is correct |
24 |
Correct |
45 ms |
205796 KB |
Output is correct |
25 |
Correct |
50 ms |
205852 KB |
Output is correct |
26 |
Correct |
46 ms |
205700 KB |
Output is correct |
27 |
Correct |
47 ms |
205676 KB |
Output is correct |
28 |
Correct |
52 ms |
205644 KB |
Output is correct |
29 |
Correct |
48 ms |
205980 KB |
Output is correct |
30 |
Correct |
45 ms |
205648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
205648 KB |
Output is correct |
2 |
Correct |
45 ms |
205564 KB |
Output is correct |
3 |
Correct |
46 ms |
205808 KB |
Output is correct |
4 |
Correct |
45 ms |
205648 KB |
Output is correct |
5 |
Correct |
46 ms |
205788 KB |
Output is correct |
6 |
Correct |
50 ms |
205800 KB |
Output is correct |
7 |
Correct |
51 ms |
205744 KB |
Output is correct |
8 |
Correct |
46 ms |
205916 KB |
Output is correct |
9 |
Correct |
46 ms |
205872 KB |
Output is correct |
10 |
Correct |
50 ms |
205904 KB |
Output is correct |
11 |
Correct |
45 ms |
205888 KB |
Output is correct |
12 |
Correct |
48 ms |
205916 KB |
Output is correct |
13 |
Correct |
45 ms |
205656 KB |
Output is correct |
14 |
Correct |
45 ms |
205808 KB |
Output is correct |
15 |
Correct |
52 ms |
205656 KB |
Output is correct |
16 |
Correct |
51 ms |
205900 KB |
Output is correct |
17 |
Correct |
46 ms |
205904 KB |
Output is correct |
18 |
Correct |
45 ms |
205908 KB |
Output is correct |
19 |
Correct |
46 ms |
205796 KB |
Output is correct |
20 |
Correct |
46 ms |
205908 KB |
Output is correct |
21 |
Correct |
45 ms |
205648 KB |
Output is correct |
22 |
Correct |
46 ms |
205660 KB |
Output is correct |
23 |
Correct |
45 ms |
205836 KB |
Output is correct |
24 |
Correct |
45 ms |
205796 KB |
Output is correct |
25 |
Correct |
50 ms |
205852 KB |
Output is correct |
26 |
Correct |
46 ms |
205700 KB |
Output is correct |
27 |
Correct |
47 ms |
205676 KB |
Output is correct |
28 |
Correct |
52 ms |
205644 KB |
Output is correct |
29 |
Correct |
48 ms |
205980 KB |
Output is correct |
30 |
Correct |
45 ms |
205648 KB |
Output is correct |
31 |
Correct |
624 ms |
239228 KB |
Output is correct |
32 |
Correct |
195 ms |
218052 KB |
Output is correct |
33 |
Correct |
580 ms |
239060 KB |
Output is correct |
34 |
Correct |
627 ms |
237888 KB |
Output is correct |
35 |
Correct |
585 ms |
239564 KB |
Output is correct |
36 |
Correct |
612 ms |
240112 KB |
Output is correct |
37 |
Correct |
428 ms |
238492 KB |
Output is correct |
38 |
Correct |
396 ms |
238740 KB |
Output is correct |
39 |
Correct |
309 ms |
238112 KB |
Output is correct |
40 |
Correct |
320 ms |
238432 KB |
Output is correct |
41 |
Correct |
325 ms |
228356 KB |
Output is correct |
42 |
Correct |
374 ms |
228040 KB |
Output is correct |
43 |
Correct |
163 ms |
220208 KB |
Output is correct |
44 |
Correct |
315 ms |
228216 KB |
Output is correct |
45 |
Correct |
373 ms |
227976 KB |
Output is correct |
46 |
Correct |
298 ms |
227580 KB |
Output is correct |
47 |
Correct |
185 ms |
224396 KB |
Output is correct |
48 |
Correct |
186 ms |
225392 KB |
Output is correct |
49 |
Correct |
218 ms |
226504 KB |
Output is correct |
50 |
Correct |
220 ms |
226004 KB |
Output is correct |
51 |
Correct |
235 ms |
226780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2063 ms |
292436 KB |
Output is correct |
2 |
Runtime error |
705 ms |
506316 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
811 ms |
509476 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
205648 KB |
Output is correct |
2 |
Correct |
45 ms |
205564 KB |
Output is correct |
3 |
Correct |
46 ms |
205808 KB |
Output is correct |
4 |
Correct |
45 ms |
205648 KB |
Output is correct |
5 |
Correct |
46 ms |
205788 KB |
Output is correct |
6 |
Correct |
50 ms |
205800 KB |
Output is correct |
7 |
Correct |
51 ms |
205744 KB |
Output is correct |
8 |
Correct |
46 ms |
205916 KB |
Output is correct |
9 |
Correct |
46 ms |
205872 KB |
Output is correct |
10 |
Correct |
50 ms |
205904 KB |
Output is correct |
11 |
Correct |
45 ms |
205888 KB |
Output is correct |
12 |
Correct |
48 ms |
205916 KB |
Output is correct |
13 |
Correct |
45 ms |
205656 KB |
Output is correct |
14 |
Correct |
45 ms |
205808 KB |
Output is correct |
15 |
Correct |
52 ms |
205656 KB |
Output is correct |
16 |
Correct |
51 ms |
205900 KB |
Output is correct |
17 |
Correct |
46 ms |
205904 KB |
Output is correct |
18 |
Correct |
45 ms |
205908 KB |
Output is correct |
19 |
Correct |
46 ms |
205796 KB |
Output is correct |
20 |
Correct |
46 ms |
205908 KB |
Output is correct |
21 |
Correct |
45 ms |
205648 KB |
Output is correct |
22 |
Correct |
46 ms |
205660 KB |
Output is correct |
23 |
Correct |
45 ms |
205836 KB |
Output is correct |
24 |
Correct |
45 ms |
205796 KB |
Output is correct |
25 |
Correct |
50 ms |
205852 KB |
Output is correct |
26 |
Correct |
46 ms |
205700 KB |
Output is correct |
27 |
Correct |
47 ms |
205676 KB |
Output is correct |
28 |
Correct |
52 ms |
205644 KB |
Output is correct |
29 |
Correct |
48 ms |
205980 KB |
Output is correct |
30 |
Correct |
45 ms |
205648 KB |
Output is correct |
31 |
Correct |
624 ms |
239228 KB |
Output is correct |
32 |
Correct |
195 ms |
218052 KB |
Output is correct |
33 |
Correct |
580 ms |
239060 KB |
Output is correct |
34 |
Correct |
627 ms |
237888 KB |
Output is correct |
35 |
Correct |
585 ms |
239564 KB |
Output is correct |
36 |
Correct |
612 ms |
240112 KB |
Output is correct |
37 |
Correct |
428 ms |
238492 KB |
Output is correct |
38 |
Correct |
396 ms |
238740 KB |
Output is correct |
39 |
Correct |
309 ms |
238112 KB |
Output is correct |
40 |
Correct |
320 ms |
238432 KB |
Output is correct |
41 |
Correct |
325 ms |
228356 KB |
Output is correct |
42 |
Correct |
374 ms |
228040 KB |
Output is correct |
43 |
Correct |
163 ms |
220208 KB |
Output is correct |
44 |
Correct |
315 ms |
228216 KB |
Output is correct |
45 |
Correct |
373 ms |
227976 KB |
Output is correct |
46 |
Correct |
298 ms |
227580 KB |
Output is correct |
47 |
Correct |
185 ms |
224396 KB |
Output is correct |
48 |
Correct |
186 ms |
225392 KB |
Output is correct |
49 |
Correct |
218 ms |
226504 KB |
Output is correct |
50 |
Correct |
220 ms |
226004 KB |
Output is correct |
51 |
Correct |
235 ms |
226780 KB |
Output is correct |
52 |
Correct |
167 ms |
221016 KB |
Output is correct |
53 |
Correct |
167 ms |
219432 KB |
Output is correct |
54 |
Correct |
291 ms |
227012 KB |
Output is correct |
55 |
Correct |
271 ms |
226104 KB |
Output is correct |
56 |
Correct |
237 ms |
225020 KB |
Output is correct |
57 |
Correct |
285 ms |
227632 KB |
Output is correct |
58 |
Correct |
243 ms |
225160 KB |
Output is correct |
59 |
Correct |
220 ms |
223944 KB |
Output is correct |
60 |
Correct |
309 ms |
227292 KB |
Output is correct |
61 |
Correct |
120 ms |
220036 KB |
Output is correct |
62 |
Correct |
160 ms |
221464 KB |
Output is correct |
63 |
Correct |
261 ms |
224616 KB |
Output is correct |
64 |
Correct |
288 ms |
225476 KB |
Output is correct |
65 |
Correct |
292 ms |
227380 KB |
Output is correct |
66 |
Correct |
295 ms |
228188 KB |
Output is correct |
67 |
Correct |
186 ms |
218616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
205648 KB |
Output is correct |
2 |
Correct |
45 ms |
205564 KB |
Output is correct |
3 |
Correct |
46 ms |
205808 KB |
Output is correct |
4 |
Correct |
45 ms |
205648 KB |
Output is correct |
5 |
Correct |
46 ms |
205788 KB |
Output is correct |
6 |
Correct |
50 ms |
205800 KB |
Output is correct |
7 |
Correct |
51 ms |
205744 KB |
Output is correct |
8 |
Correct |
46 ms |
205916 KB |
Output is correct |
9 |
Correct |
46 ms |
205872 KB |
Output is correct |
10 |
Correct |
50 ms |
205904 KB |
Output is correct |
11 |
Correct |
45 ms |
205888 KB |
Output is correct |
12 |
Correct |
48 ms |
205916 KB |
Output is correct |
13 |
Correct |
45 ms |
205656 KB |
Output is correct |
14 |
Correct |
45 ms |
205808 KB |
Output is correct |
15 |
Correct |
52 ms |
205656 KB |
Output is correct |
16 |
Correct |
51 ms |
205900 KB |
Output is correct |
17 |
Correct |
46 ms |
205904 KB |
Output is correct |
18 |
Correct |
45 ms |
205908 KB |
Output is correct |
19 |
Correct |
46 ms |
205796 KB |
Output is correct |
20 |
Correct |
46 ms |
205908 KB |
Output is correct |
21 |
Correct |
45 ms |
205648 KB |
Output is correct |
22 |
Correct |
46 ms |
205660 KB |
Output is correct |
23 |
Correct |
45 ms |
205836 KB |
Output is correct |
24 |
Correct |
45 ms |
205796 KB |
Output is correct |
25 |
Correct |
50 ms |
205852 KB |
Output is correct |
26 |
Correct |
46 ms |
205700 KB |
Output is correct |
27 |
Correct |
47 ms |
205676 KB |
Output is correct |
28 |
Correct |
52 ms |
205644 KB |
Output is correct |
29 |
Correct |
48 ms |
205980 KB |
Output is correct |
30 |
Correct |
45 ms |
205648 KB |
Output is correct |
31 |
Correct |
624 ms |
239228 KB |
Output is correct |
32 |
Correct |
195 ms |
218052 KB |
Output is correct |
33 |
Correct |
580 ms |
239060 KB |
Output is correct |
34 |
Correct |
627 ms |
237888 KB |
Output is correct |
35 |
Correct |
585 ms |
239564 KB |
Output is correct |
36 |
Correct |
612 ms |
240112 KB |
Output is correct |
37 |
Correct |
428 ms |
238492 KB |
Output is correct |
38 |
Correct |
396 ms |
238740 KB |
Output is correct |
39 |
Correct |
309 ms |
238112 KB |
Output is correct |
40 |
Correct |
320 ms |
238432 KB |
Output is correct |
41 |
Correct |
325 ms |
228356 KB |
Output is correct |
42 |
Correct |
374 ms |
228040 KB |
Output is correct |
43 |
Correct |
163 ms |
220208 KB |
Output is correct |
44 |
Correct |
315 ms |
228216 KB |
Output is correct |
45 |
Correct |
373 ms |
227976 KB |
Output is correct |
46 |
Correct |
298 ms |
227580 KB |
Output is correct |
47 |
Correct |
185 ms |
224396 KB |
Output is correct |
48 |
Correct |
186 ms |
225392 KB |
Output is correct |
49 |
Correct |
218 ms |
226504 KB |
Output is correct |
50 |
Correct |
220 ms |
226004 KB |
Output is correct |
51 |
Correct |
235 ms |
226780 KB |
Output is correct |
52 |
Correct |
2063 ms |
292436 KB |
Output is correct |
53 |
Runtime error |
705 ms |
506316 KB |
Execution killed with signal 11 |
54 |
Halted |
0 ms |
0 KB |
- |