#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
constexpr int inf = 1000000100;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REP3(i, l, r) for (int i = (l); i < (r); ++i)
#define RVP(i, n) for (int i = (n - 1); i >= 0; --i)
#define ALL(x) (x).begin(), (x).end()
struct PriqueErase {
priority_queue<int, vector<int>, greater<int>> a, b;
void push(int x) { a.push(x); }
void erase(int x) { b.push(x); }
int top() {
while (not a.empty()) {
const int v = a.top();
if (b.empty() or v != b.top()) {
return v;
} else {
a.pop();
b.pop();
}
}
return inf;
}
};
int cnt_sp[2000000];
struct RIEPM {
int n, siz;
vector<PriqueErase> data;
RIEPM(int n_) : n(n_) {
siz = 1;
while (siz < n) siz <<= 1;
data.assign(2 * siz, PriqueErase());
}
void replace(int l, int r1, int r2, int v) {
assert(0 <= l and l <= r1 and l <= r2 and r1 <= n and r2 <= n);
vector<int> vs;
for (int li = l + siz, ri = r1 + siz; li < ri; li >>= 1, ri >>= 1) {
if (li & 1) {
++cnt_sp[li++];
vs.push_back(li - 1);
}
if (ri & 1) {
++cnt_sp[--ri];
vs.push_back(ri);
}
}
for (int li = l + siz, ri = r2 + siz; li < ri; li >>= 1, ri >>= 1) {
if (li & 1) {
--cnt_sp[li++];
vs.push_back(li - 1);
}
if (ri & 1) {
--cnt_sp[--ri];
vs.push_back(ri);
}
}
for (const int i : vs) {
if (cnt_sp[i] == 1) data[i].push(v);
if (cnt_sp[i] == -1) data[i].erase(v);
cnt_sp[i] = 0;
}
}
void push(int l, int r, int v) {
assert(0 <= l and l <= r and r <= n);
for (l += siz, r += siz; l < r; l >>= 1, r >>= 1) {
if (l & 1) data[l++].push(v);
if (r & 1) data[--r].push(v);
}
}
void erase(int l, int r, int v) {
assert(0 <= l and l <= r and r <= n);
for (l += siz, r += siz; l < r; l >>= 1, r >>= 1) {
if (l & 1) data[l++].erase(v);
if (r & 1) data[--r].erase(v);
}
}
int top(int i) {
assert(0 <= i and i < n);
i += siz;
int res = inf;
while (i != 0) {
res = min(res, data[i].top());
i >>= 1;
}
return res;
}
};
int main() {
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
fill(cnt_sp, cnt_sp + 2000000, 0);
int N, K, Q;
cin >> N >> K >> Q;
vector<int> X(N), T(N), A(N), B(N);
REP(i, N) {
scanf("%d%d%d%d", &X[i], &T[i], &A[i], &B[i]);
// cin >> X[i] >> T[i] >> A[i] >> B[i];
--T[i];
}
vector<int> L(Q), Y(Q);
REP(i, Q) scanf("%d%d", &L[i], &Y[i]); // cin >> L[i] >> Y[i];
auto reverse_points = [&]() {
REP(i, N) X[i] = inf - X[i];
REP(i, Q) L[i] = inf - L[i];
};
auto solve = [&]() {
vector<int> press;
press.reserve(N + Q);
REP(i, N) press.push_back(X[i]);
REP(i, Q) press.push_back(L[i]);
sort(ALL(press));
press.erase(unique(ALL(press)), press.end());
auto get_key = [&](int i) { return (int)(lower_bound(ALL(press), i) - press.begin()); };
const int M = (int)press.size();
RIEPM hp(M);
vector<tuple<int, int, int, int>> event;
event.reserve(2 * N + Q);
REP(i, N) {
event.push_back({A[i], 0, X[i], T[i]});
event.push_back({B[i] + 1, 1, X[i], T[i]});
}
REP(i, Q) event.push_back({Y[i], 2, L[i], i});
sort(ALL(event));
vector<map<int, int>> pd(K);
vector<int> res(Q, -1);
int cnt_zero = K;
for (const auto &[c, qt, p, i] : event) {
if (qt == 0) {
if (pd[i].empty()) --cnt_zero;
auto [itr, vld] = pd[i].insert({p, 1});
if (not vld) {
++itr->second;
continue;
}
auto itr_r = itr;
++itr_r;
if (itr_r == pd[i].end()) {
hp.push(get_key(p), M, p);
} else {
hp.push(get_key(p), get_key((p + itr_r->first + 2) / 2), p);
}
if (itr == pd[i].begin()) continue;
auto itr_l = itr;
--itr_l;
const int l_id = get_key(itr_l->first);
if (itr_r != pd[i].end()) {
hp.replace(l_id, get_key((itr_l->first + p + 2) / 2),
get_key((itr_l->first + itr_r->first + 2) / 2), itr_l->first);
} else {
hp.replace(l_id, get_key((itr_l->first + p + 2) / 2), M, itr_l->first);
}
}
if (qt == 1) {
auto itr = pd[i].find(p);
if (--(itr->second) != 0) {
continue;
}
pd[i].erase(p);
if (pd[i].empty()) ++cnt_zero;
auto itr_r = pd[i].upper_bound(p);
if (itr_r != pd[i].end()) {
hp.erase(get_key(p), get_key((p + itr_r->first + 2) / 2), p);
} else {
hp.erase(get_key(p), M, p);
}
if (itr_r == pd[i].begin()) continue;
auto itr_l = itr_r;
--itr_l;
const int l_id = get_key(itr_l->first);
if (itr_r != pd[i].end()) {
hp.replace(l_id, get_key((itr_l->first + itr_r->first + 2) / 2),
get_key((itr_l->first + p + 2) / 2), itr_l->first);
} else {
hp.replace(l_id, M, get_key((itr_l->first + p + 2) / 2), itr_l->first);
}
}
if (qt == 2) {
if (cnt_zero != 0) continue;
const int pi = get_key(p);
const int vi = hp.top(pi);
if (vi == inf) continue;
res[i] = p - vi;
}
}
return res;
};
const auto res1 = solve();
reverse_points();
const auto res2 = solve();
REP(i, Q) {
const int ans = max(res1[i], res2[i]);
printf("%d\n", ans);
// cout << ans << '\n';
}
}
Compilation message
new_home.cpp: In function 'int main()':
new_home.cpp:118:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
118 | scanf("%d%d%d%d", &X[i], &T[i], &A[i], &B[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:123:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
123 | REP(i, Q) scanf("%d%d", &L[i], &Y[i]); // cin >> L[i] >> Y[i];
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8020 KB |
Output is correct |
2 |
Correct |
4 ms |
8020 KB |
Output is correct |
3 |
Correct |
5 ms |
8020 KB |
Output is correct |
4 |
Correct |
4 ms |
8020 KB |
Output is correct |
5 |
Correct |
4 ms |
8148 KB |
Output is correct |
6 |
Correct |
7 ms |
8276 KB |
Output is correct |
7 |
Correct |
5 ms |
8276 KB |
Output is correct |
8 |
Correct |
6 ms |
8376 KB |
Output is correct |
9 |
Correct |
5 ms |
8276 KB |
Output is correct |
10 |
Correct |
7 ms |
8276 KB |
Output is correct |
11 |
Correct |
6 ms |
8276 KB |
Output is correct |
12 |
Correct |
7 ms |
8276 KB |
Output is correct |
13 |
Correct |
5 ms |
8276 KB |
Output is correct |
14 |
Correct |
5 ms |
8276 KB |
Output is correct |
15 |
Correct |
6 ms |
8276 KB |
Output is correct |
16 |
Correct |
5 ms |
8276 KB |
Output is correct |
17 |
Correct |
6 ms |
8276 KB |
Output is correct |
18 |
Correct |
5 ms |
8276 KB |
Output is correct |
19 |
Correct |
6 ms |
8276 KB |
Output is correct |
20 |
Correct |
6 ms |
8276 KB |
Output is correct |
21 |
Correct |
4 ms |
8200 KB |
Output is correct |
22 |
Correct |
5 ms |
8276 KB |
Output is correct |
23 |
Correct |
6 ms |
8276 KB |
Output is correct |
24 |
Correct |
6 ms |
8276 KB |
Output is correct |
25 |
Correct |
6 ms |
8328 KB |
Output is correct |
26 |
Correct |
6 ms |
8276 KB |
Output is correct |
27 |
Correct |
7 ms |
8148 KB |
Output is correct |
28 |
Correct |
6 ms |
8276 KB |
Output is correct |
29 |
Correct |
5 ms |
8300 KB |
Output is correct |
30 |
Correct |
6 ms |
8276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8020 KB |
Output is correct |
2 |
Correct |
4 ms |
8020 KB |
Output is correct |
3 |
Correct |
5 ms |
8020 KB |
Output is correct |
4 |
Correct |
4 ms |
8020 KB |
Output is correct |
5 |
Correct |
4 ms |
8148 KB |
Output is correct |
6 |
Correct |
7 ms |
8276 KB |
Output is correct |
7 |
Correct |
5 ms |
8276 KB |
Output is correct |
8 |
Correct |
6 ms |
8376 KB |
Output is correct |
9 |
Correct |
5 ms |
8276 KB |
Output is correct |
10 |
Correct |
7 ms |
8276 KB |
Output is correct |
11 |
Correct |
6 ms |
8276 KB |
Output is correct |
12 |
Correct |
7 ms |
8276 KB |
Output is correct |
13 |
Correct |
5 ms |
8276 KB |
Output is correct |
14 |
Correct |
5 ms |
8276 KB |
Output is correct |
15 |
Correct |
6 ms |
8276 KB |
Output is correct |
16 |
Correct |
5 ms |
8276 KB |
Output is correct |
17 |
Correct |
6 ms |
8276 KB |
Output is correct |
18 |
Correct |
5 ms |
8276 KB |
Output is correct |
19 |
Correct |
6 ms |
8276 KB |
Output is correct |
20 |
Correct |
6 ms |
8276 KB |
Output is correct |
21 |
Correct |
4 ms |
8200 KB |
Output is correct |
22 |
Correct |
5 ms |
8276 KB |
Output is correct |
23 |
Correct |
6 ms |
8276 KB |
Output is correct |
24 |
Correct |
6 ms |
8276 KB |
Output is correct |
25 |
Correct |
6 ms |
8328 KB |
Output is correct |
26 |
Correct |
6 ms |
8276 KB |
Output is correct |
27 |
Correct |
7 ms |
8148 KB |
Output is correct |
28 |
Correct |
6 ms |
8276 KB |
Output is correct |
29 |
Correct |
5 ms |
8300 KB |
Output is correct |
30 |
Correct |
6 ms |
8276 KB |
Output is correct |
31 |
Correct |
1507 ms |
48280 KB |
Output is correct |
32 |
Correct |
105 ms |
13432 KB |
Output is correct |
33 |
Correct |
1206 ms |
42348 KB |
Output is correct |
34 |
Correct |
1558 ms |
47904 KB |
Output is correct |
35 |
Correct |
1471 ms |
46632 KB |
Output is correct |
36 |
Correct |
1077 ms |
42584 KB |
Output is correct |
37 |
Correct |
820 ms |
43212 KB |
Output is correct |
38 |
Correct |
658 ms |
41264 KB |
Output is correct |
39 |
Correct |
579 ms |
41836 KB |
Output is correct |
40 |
Correct |
575 ms |
41340 KB |
Output is correct |
41 |
Correct |
969 ms |
45096 KB |
Output is correct |
42 |
Correct |
950 ms |
46068 KB |
Output is correct |
43 |
Correct |
79 ms |
13832 KB |
Output is correct |
44 |
Correct |
947 ms |
44376 KB |
Output is correct |
45 |
Correct |
953 ms |
43684 KB |
Output is correct |
46 |
Correct |
936 ms |
42052 KB |
Output is correct |
47 |
Correct |
440 ms |
42284 KB |
Output is correct |
48 |
Correct |
505 ms |
43988 KB |
Output is correct |
49 |
Correct |
606 ms |
44856 KB |
Output is correct |
50 |
Correct |
612 ms |
46204 KB |
Output is correct |
51 |
Correct |
630 ms |
44456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4121 ms |
273900 KB |
Output is correct |
2 |
Correct |
3440 ms |
252636 KB |
Output is correct |
3 |
Correct |
1828 ms |
249316 KB |
Output is correct |
4 |
Correct |
3972 ms |
271196 KB |
Output is correct |
5 |
Correct |
2949 ms |
246196 KB |
Output is correct |
6 |
Correct |
3141 ms |
247956 KB |
Output is correct |
7 |
Correct |
1783 ms |
252136 KB |
Output is correct |
8 |
Correct |
3686 ms |
269892 KB |
Output is correct |
9 |
Correct |
4259 ms |
270592 KB |
Output is correct |
10 |
Correct |
4198 ms |
270332 KB |
Output is correct |
11 |
Correct |
3472 ms |
257052 KB |
Output is correct |
12 |
Correct |
3730 ms |
258304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5086 ms |
278900 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8020 KB |
Output is correct |
2 |
Correct |
4 ms |
8020 KB |
Output is correct |
3 |
Correct |
5 ms |
8020 KB |
Output is correct |
4 |
Correct |
4 ms |
8020 KB |
Output is correct |
5 |
Correct |
4 ms |
8148 KB |
Output is correct |
6 |
Correct |
7 ms |
8276 KB |
Output is correct |
7 |
Correct |
5 ms |
8276 KB |
Output is correct |
8 |
Correct |
6 ms |
8376 KB |
Output is correct |
9 |
Correct |
5 ms |
8276 KB |
Output is correct |
10 |
Correct |
7 ms |
8276 KB |
Output is correct |
11 |
Correct |
6 ms |
8276 KB |
Output is correct |
12 |
Correct |
7 ms |
8276 KB |
Output is correct |
13 |
Correct |
5 ms |
8276 KB |
Output is correct |
14 |
Correct |
5 ms |
8276 KB |
Output is correct |
15 |
Correct |
6 ms |
8276 KB |
Output is correct |
16 |
Correct |
5 ms |
8276 KB |
Output is correct |
17 |
Correct |
6 ms |
8276 KB |
Output is correct |
18 |
Correct |
5 ms |
8276 KB |
Output is correct |
19 |
Correct |
6 ms |
8276 KB |
Output is correct |
20 |
Correct |
6 ms |
8276 KB |
Output is correct |
21 |
Correct |
4 ms |
8200 KB |
Output is correct |
22 |
Correct |
5 ms |
8276 KB |
Output is correct |
23 |
Correct |
6 ms |
8276 KB |
Output is correct |
24 |
Correct |
6 ms |
8276 KB |
Output is correct |
25 |
Correct |
6 ms |
8328 KB |
Output is correct |
26 |
Correct |
6 ms |
8276 KB |
Output is correct |
27 |
Correct |
7 ms |
8148 KB |
Output is correct |
28 |
Correct |
6 ms |
8276 KB |
Output is correct |
29 |
Correct |
5 ms |
8300 KB |
Output is correct |
30 |
Correct |
6 ms |
8276 KB |
Output is correct |
31 |
Correct |
1507 ms |
48280 KB |
Output is correct |
32 |
Correct |
105 ms |
13432 KB |
Output is correct |
33 |
Correct |
1206 ms |
42348 KB |
Output is correct |
34 |
Correct |
1558 ms |
47904 KB |
Output is correct |
35 |
Correct |
1471 ms |
46632 KB |
Output is correct |
36 |
Correct |
1077 ms |
42584 KB |
Output is correct |
37 |
Correct |
820 ms |
43212 KB |
Output is correct |
38 |
Correct |
658 ms |
41264 KB |
Output is correct |
39 |
Correct |
579 ms |
41836 KB |
Output is correct |
40 |
Correct |
575 ms |
41340 KB |
Output is correct |
41 |
Correct |
969 ms |
45096 KB |
Output is correct |
42 |
Correct |
950 ms |
46068 KB |
Output is correct |
43 |
Correct |
79 ms |
13832 KB |
Output is correct |
44 |
Correct |
947 ms |
44376 KB |
Output is correct |
45 |
Correct |
953 ms |
43684 KB |
Output is correct |
46 |
Correct |
936 ms |
42052 KB |
Output is correct |
47 |
Correct |
440 ms |
42284 KB |
Output is correct |
48 |
Correct |
505 ms |
43988 KB |
Output is correct |
49 |
Correct |
606 ms |
44856 KB |
Output is correct |
50 |
Correct |
612 ms |
46204 KB |
Output is correct |
51 |
Correct |
630 ms |
44456 KB |
Output is correct |
52 |
Correct |
461 ms |
48032 KB |
Output is correct |
53 |
Correct |
445 ms |
46636 KB |
Output is correct |
54 |
Correct |
849 ms |
51608 KB |
Output is correct |
55 |
Correct |
769 ms |
45796 KB |
Output is correct |
56 |
Correct |
671 ms |
46328 KB |
Output is correct |
57 |
Correct |
886 ms |
45584 KB |
Output is correct |
58 |
Correct |
758 ms |
46988 KB |
Output is correct |
59 |
Correct |
673 ms |
47464 KB |
Output is correct |
60 |
Correct |
877 ms |
45868 KB |
Output is correct |
61 |
Correct |
80 ms |
19608 KB |
Output is correct |
62 |
Correct |
447 ms |
46976 KB |
Output is correct |
63 |
Correct |
681 ms |
50004 KB |
Output is correct |
64 |
Correct |
766 ms |
49796 KB |
Output is correct |
65 |
Correct |
913 ms |
48936 KB |
Output is correct |
66 |
Correct |
941 ms |
45296 KB |
Output is correct |
67 |
Correct |
224 ms |
17036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
8020 KB |
Output is correct |
2 |
Correct |
4 ms |
8020 KB |
Output is correct |
3 |
Correct |
5 ms |
8020 KB |
Output is correct |
4 |
Correct |
4 ms |
8020 KB |
Output is correct |
5 |
Correct |
4 ms |
8148 KB |
Output is correct |
6 |
Correct |
7 ms |
8276 KB |
Output is correct |
7 |
Correct |
5 ms |
8276 KB |
Output is correct |
8 |
Correct |
6 ms |
8376 KB |
Output is correct |
9 |
Correct |
5 ms |
8276 KB |
Output is correct |
10 |
Correct |
7 ms |
8276 KB |
Output is correct |
11 |
Correct |
6 ms |
8276 KB |
Output is correct |
12 |
Correct |
7 ms |
8276 KB |
Output is correct |
13 |
Correct |
5 ms |
8276 KB |
Output is correct |
14 |
Correct |
5 ms |
8276 KB |
Output is correct |
15 |
Correct |
6 ms |
8276 KB |
Output is correct |
16 |
Correct |
5 ms |
8276 KB |
Output is correct |
17 |
Correct |
6 ms |
8276 KB |
Output is correct |
18 |
Correct |
5 ms |
8276 KB |
Output is correct |
19 |
Correct |
6 ms |
8276 KB |
Output is correct |
20 |
Correct |
6 ms |
8276 KB |
Output is correct |
21 |
Correct |
4 ms |
8200 KB |
Output is correct |
22 |
Correct |
5 ms |
8276 KB |
Output is correct |
23 |
Correct |
6 ms |
8276 KB |
Output is correct |
24 |
Correct |
6 ms |
8276 KB |
Output is correct |
25 |
Correct |
6 ms |
8328 KB |
Output is correct |
26 |
Correct |
6 ms |
8276 KB |
Output is correct |
27 |
Correct |
7 ms |
8148 KB |
Output is correct |
28 |
Correct |
6 ms |
8276 KB |
Output is correct |
29 |
Correct |
5 ms |
8300 KB |
Output is correct |
30 |
Correct |
6 ms |
8276 KB |
Output is correct |
31 |
Correct |
1507 ms |
48280 KB |
Output is correct |
32 |
Correct |
105 ms |
13432 KB |
Output is correct |
33 |
Correct |
1206 ms |
42348 KB |
Output is correct |
34 |
Correct |
1558 ms |
47904 KB |
Output is correct |
35 |
Correct |
1471 ms |
46632 KB |
Output is correct |
36 |
Correct |
1077 ms |
42584 KB |
Output is correct |
37 |
Correct |
820 ms |
43212 KB |
Output is correct |
38 |
Correct |
658 ms |
41264 KB |
Output is correct |
39 |
Correct |
579 ms |
41836 KB |
Output is correct |
40 |
Correct |
575 ms |
41340 KB |
Output is correct |
41 |
Correct |
969 ms |
45096 KB |
Output is correct |
42 |
Correct |
950 ms |
46068 KB |
Output is correct |
43 |
Correct |
79 ms |
13832 KB |
Output is correct |
44 |
Correct |
947 ms |
44376 KB |
Output is correct |
45 |
Correct |
953 ms |
43684 KB |
Output is correct |
46 |
Correct |
936 ms |
42052 KB |
Output is correct |
47 |
Correct |
440 ms |
42284 KB |
Output is correct |
48 |
Correct |
505 ms |
43988 KB |
Output is correct |
49 |
Correct |
606 ms |
44856 KB |
Output is correct |
50 |
Correct |
612 ms |
46204 KB |
Output is correct |
51 |
Correct |
630 ms |
44456 KB |
Output is correct |
52 |
Correct |
4121 ms |
273900 KB |
Output is correct |
53 |
Correct |
3440 ms |
252636 KB |
Output is correct |
54 |
Correct |
1828 ms |
249316 KB |
Output is correct |
55 |
Correct |
3972 ms |
271196 KB |
Output is correct |
56 |
Correct |
2949 ms |
246196 KB |
Output is correct |
57 |
Correct |
3141 ms |
247956 KB |
Output is correct |
58 |
Correct |
1783 ms |
252136 KB |
Output is correct |
59 |
Correct |
3686 ms |
269892 KB |
Output is correct |
60 |
Correct |
4259 ms |
270592 KB |
Output is correct |
61 |
Correct |
4198 ms |
270332 KB |
Output is correct |
62 |
Correct |
3472 ms |
257052 KB |
Output is correct |
63 |
Correct |
3730 ms |
258304 KB |
Output is correct |
64 |
Execution timed out |
5086 ms |
278900 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |