#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define _size(x) (int)x.size()
#define BIT(i, x) ((x >> i) & 1)
#define MASK(n) ((1 << n) - 1)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define FOR(i, a, b) for (int i = a, _b = (b); i <= _b; i++)
#define FORD(i, a, b) for (int i = a, _b = (b); i >= _b; i--)
#define FORB1(i, mask) for (int i = mask; i > 0; i ^= i & - i)
#define FORB0(i, n, mask) for (int i = ((1 << n) - 1) ^ mask; i > 0; i ^= i & - i)
#define FORALL(i, a) for (auto i: a)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
struct storeNode {
int x, t, a, b;
};
struct queryNode {
int l, y, id;
};
int n, k, q;
vector<storeNode> store;
vector<queryNode> qu;
namespace subtask12 {
const int inf = 1e9;
void main() {
vector<pair<int, int>> g;
FOR(i, 1, n) g.push_back({store[i].a, i}), g.push_back({store[i].b, - i});
REP(i, q) g.push_back({qu[i].y, 0});
sort(g.begin(), g.end(), [&] (const pair<int, int> a, pair<int, int> b) { return a.fi != b.fi ? a.fi < b.fi : a.se > b.se; });
sort(qu.begin(), qu.end(), [&] (const queryNode a, queryNode b) { return a.y < b.y; });
vector<int> ans(q);
vector<multiset<int>> mts(k + 1);
int i = 0, z = 0;
while (i < _size(g)) {
int j = i;
while (j < _size(g) && g[j].fi == g[i].fi && g[j].se > 0) {
int id = g[j].se;
mts[store[id].t].insert(store[id].x);
j++;
}
while (j < _size(g) && g[j].fi == g[i].fi && g[j].se == 0) j++;
while (z < q && qu[z].y == g[i].fi) {
int res = - 1;
FOR(id, 1, k) {
if (mts[id].empty()) {
res = - 1;
break;
}
auto it = mts[id].lower_bound(qu[z].l);
int _res = inf;
if (it != mts[id].end()) _res = min(_res, *it - qu[z].l);
if (it != mts[id].begin()) {
--it;
_res = min(_res, qu[z].l - *it);
}
res = max(res, _res);
}
ans[qu[z].id] = res;
z++;
}
while (j < _size(g) && g[j].fi == g[i].fi) {
int id = - g[j].se;
mts[store[id].t].erase(mts[store[id].t].find(store[id].x));
j++;
}
i = j;
}
REP(i, q) cout << ans[i] << '\n';
}
}
bool checkSub34() {
FOR(i, 1, n) if (store[i].a != 1) return false;
return true;
}
namespace subtask34 {
const int inf = 1e9;
struct segNode {
int value, lazy = - inf;
segNode operator + (segNode o) const {
return {max(value, o.value), - inf};
}
};
struct segTree {
vector<segNode> ST;
void init(int n) {
ST.resize(4 * n + 4);
}
void down(int id, int l, int r) {
int t = ST[id].lazy;
if (t == - inf) return ;
ST[id].value = max(ST[id].value, t);
if (l != r) {
ST[id * 2].lazy = max(ST[id * 2].lazy, t);
ST[id * 2 + 1].lazy = max(ST[id * 2 + 1].lazy, t);
}
ST[id].lazy = - inf;
}
void update(int id, int l, int r, int u, int v, int val) {
down(id, l, r);
if (r < u || v < l) return ;
if (u <= l && r <= v) {
ST[id].value = max(ST[id].value, val);
if (l != r) {
ST[id * 2].lazy = max(ST[id * 2].lazy, val);
ST[id * 2 + 1].lazy = max(ST[id * 2 + 1].lazy, val);
}
return ;
}
int mid = (l + r) / 2;
update(id * 2, l, mid, u, v, val);
update(id * 2 + 1, mid + 1, r, u, v, val);
ST[id] = ST[id * 2] + ST[id * 2 + 1];
}
int get(int id, int l, int r, int u, int v) {
down(id, l, r);
if (r < u || v < l) return - inf;
if (u <= l && r <= v) return ST[id].value;
int mid = (l + r) / 2;
return max(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
}
} st[2];
void main() {
vector<int> vtx;
FOR(i, 1, n) vtx.push_back(store[i].x);
REP(i, q) vtx.push_back(qu[i].l);
sort(vtx.begin(), vtx.end());
vtx.resize(unique(vtx.begin(), vtx.end()) - vtx.begin());
vector<multiset<int>> mts(k + 1);
FOR(i, 1, n) mts[store[i].t].insert(lower_bound(vtx.begin(), vtx.end(), store[i].x) - vtx.begin());
st[0].init(n), st[1].init(n);
FOR(i, 1, k) {
if (mts[i].empty()) continue;
st[0].update(1, 0, _size(vtx) - 1, 0, *mts[i].begin(), vtx[*mts[i].begin()]);
for (auto it = mts[i].begin(); it != mts[i].end(); it++) {
auto nit = it;
nit++;
if (nit == mts[i].end()) break;
int id = *it, nid = *nit;
int pos = lower_bound(vtx.begin(), vtx.end(), (vtx[id] + vtx[nid] + 1) / 2) - vtx.begin();
st[0].update(1, 0, _size(vtx) - 1, pos, nid, vtx[nid]);
if (pos > id) st[1].update(1, 0, _size(vtx) - 1, id, pos - 1, - vtx[id]);
}
auto it = mts[i].end();
it--;
st[1].update(1, 0, _size(vtx) - 1, *it, _size(vtx) - 1, - vtx[*it]);
}
vector<pair<int, int>> g;
FOR(i, 1, n) g.push_back({store[i].b, - i});
REP(i, q) g.push_back({qu[i].y, i});
sort(g.begin(), g.end(), [&] (const pair<int, int> a, pair<int, int> b) { return a.fi != b.fi ? a.fi < b.fi : a.se > b.se; });
int ok = 0;
vector<int> cnt(k + 1), ans(q);
FOR(i, 1, n) cnt[store[i].t]++;
FOR(i, 1, k) ok += (!cnt[i]);
FORALL(e, g) {
if (e.se > 0) {
if (ok) ans[e.se] = - 1;
else {
int pos = lower_bound(vtx.begin(), vtx.end(), qu[e.se].l) - vtx.begin();
ans[e.se] = max(st[0].get(1, 0, _size(vtx) - 1, pos, pos) - vtx[pos], vtx[pos] + st[1].get(1, 0, _size(vtx) - 1, pos, pos));
}
}
else break;
}
REP(i, q) cout << ans[i] << '\n';
}
}
int main() {
fastio;
cin >> n >> k >> q;
store.resize(n + 1);
FOR(i, 1, n) {
int x, t, a, b;
cin >> x >> t >> a >> b;
store[i] = {x, t, a, b};
}
qu.resize(q);
REP(i, q) {
cin >> qu[i].l >> qu[i].y;
qu[i].id = i;
}
if (max(n, q) <= 60000 && k <= 400) subtask12::main();
else if (checkSub34()) subtask34::main();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1542 ms |
6852 KB |
Output is correct |
32 |
Correct |
68 ms |
5080 KB |
Output is correct |
33 |
Correct |
127 ms |
5064 KB |
Output is correct |
34 |
Correct |
1240 ms |
5120 KB |
Output is correct |
35 |
Correct |
659 ms |
6820 KB |
Output is correct |
36 |
Correct |
148 ms |
6688 KB |
Output is correct |
37 |
Correct |
118 ms |
4288 KB |
Output is correct |
38 |
Correct |
70 ms |
4308 KB |
Output is correct |
39 |
Correct |
65 ms |
4052 KB |
Output is correct |
40 |
Correct |
65 ms |
4052 KB |
Output is correct |
41 |
Correct |
196 ms |
4284 KB |
Output is correct |
42 |
Correct |
155 ms |
4044 KB |
Output is correct |
43 |
Correct |
165 ms |
7096 KB |
Output is correct |
44 |
Correct |
164 ms |
4288 KB |
Output is correct |
45 |
Correct |
94 ms |
4436 KB |
Output is correct |
46 |
Correct |
55 ms |
4084 KB |
Output is correct |
47 |
Correct |
49 ms |
4044 KB |
Output is correct |
48 |
Correct |
47 ms |
4224 KB |
Output is correct |
49 |
Correct |
62 ms |
4044 KB |
Output is correct |
50 |
Correct |
137 ms |
4052 KB |
Output is correct |
51 |
Correct |
53 ms |
4044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
297 ms |
96704 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
309 ms |
89988 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1542 ms |
6852 KB |
Output is correct |
32 |
Correct |
68 ms |
5080 KB |
Output is correct |
33 |
Correct |
127 ms |
5064 KB |
Output is correct |
34 |
Correct |
1240 ms |
5120 KB |
Output is correct |
35 |
Correct |
659 ms |
6820 KB |
Output is correct |
36 |
Correct |
148 ms |
6688 KB |
Output is correct |
37 |
Correct |
118 ms |
4288 KB |
Output is correct |
38 |
Correct |
70 ms |
4308 KB |
Output is correct |
39 |
Correct |
65 ms |
4052 KB |
Output is correct |
40 |
Correct |
65 ms |
4052 KB |
Output is correct |
41 |
Correct |
196 ms |
4284 KB |
Output is correct |
42 |
Correct |
155 ms |
4044 KB |
Output is correct |
43 |
Correct |
165 ms |
7096 KB |
Output is correct |
44 |
Correct |
164 ms |
4288 KB |
Output is correct |
45 |
Correct |
94 ms |
4436 KB |
Output is correct |
46 |
Correct |
55 ms |
4084 KB |
Output is correct |
47 |
Correct |
49 ms |
4044 KB |
Output is correct |
48 |
Correct |
47 ms |
4224 KB |
Output is correct |
49 |
Correct |
62 ms |
4044 KB |
Output is correct |
50 |
Correct |
137 ms |
4052 KB |
Output is correct |
51 |
Correct |
53 ms |
4044 KB |
Output is correct |
52 |
Incorrect |
25 ms |
1880 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1542 ms |
6852 KB |
Output is correct |
32 |
Correct |
68 ms |
5080 KB |
Output is correct |
33 |
Correct |
127 ms |
5064 KB |
Output is correct |
34 |
Correct |
1240 ms |
5120 KB |
Output is correct |
35 |
Correct |
659 ms |
6820 KB |
Output is correct |
36 |
Correct |
148 ms |
6688 KB |
Output is correct |
37 |
Correct |
118 ms |
4288 KB |
Output is correct |
38 |
Correct |
70 ms |
4308 KB |
Output is correct |
39 |
Correct |
65 ms |
4052 KB |
Output is correct |
40 |
Correct |
65 ms |
4052 KB |
Output is correct |
41 |
Correct |
196 ms |
4284 KB |
Output is correct |
42 |
Correct |
155 ms |
4044 KB |
Output is correct |
43 |
Correct |
165 ms |
7096 KB |
Output is correct |
44 |
Correct |
164 ms |
4288 KB |
Output is correct |
45 |
Correct |
94 ms |
4436 KB |
Output is correct |
46 |
Correct |
55 ms |
4084 KB |
Output is correct |
47 |
Correct |
49 ms |
4044 KB |
Output is correct |
48 |
Correct |
47 ms |
4224 KB |
Output is correct |
49 |
Correct |
62 ms |
4044 KB |
Output is correct |
50 |
Correct |
137 ms |
4052 KB |
Output is correct |
51 |
Correct |
53 ms |
4044 KB |
Output is correct |
52 |
Runtime error |
297 ms |
96704 KB |
Execution killed with signal 11 |
53 |
Halted |
0 ms |
0 KB |
- |