#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 600000000
#define MOD 1000000007
#define MAX_N (1<<20)
inline int dist(const multiset<int> &s, int d) {
if (s.empty()) return 0;
else return max(abs(d-*s.begin()), abs(d-*s.rbegin()));
}
struct SegTree {
multiset<int> seg[MAX_N*2-1];
void add(int a, int b, int x, int k=0, int l=0, int r=MAX_N) {
if (b <= l || r <= a) return;
if (a <= l && r <= b) {
seg[k].insert(x);
return;
}
add(a, b, x, k*2+1, l, (l+r)/2);
add(a, b, x, k*2+2, (l+r)/2, r);
}
void remove(int a, int b, int x, int k=0, int l=0, int r=MAX_N) {
if (b <= l || r <= a) return;
if (a <= l && r <= b) {
auto it = seg[k].find(x);
assert(it != seg[k].end());
seg[k].erase(it);
return;
}
remove(a, b, x, k*2+1, l, (l+r)/2);
remove(a, b, x, k*2+2, (l+r)/2, r);
}
int query(int k, int x) {
k += MAX_N-1;
int m = dist(seg[k], x);
while (k > 0) {
k = (k-1)/2;
m = max(m, dist(seg[k], x));
}
return m;
}
} seg;
int N, K, Q;
int X[300000], T[300000], A[300000], B[300000];
int L[300000], Y[300000];
#define MAX_Y 1000000
vector<int> Gopen[MAX_Y];
vector<int> Gclose[MAX_Y];
vector<int> Gquery[MAX_Y];
#define MAX_X 700000
int rangeL[MAX_X], rangeR[MAX_X];
int ans[300000];
vector<int> years, xs;
void addRange(int id) {
int l = lower_bound(all(xs), rangeL[id]) - xs.begin();
int r = upper_bound(all(xs), rangeR[id]) - xs.begin() - 1;
if (l > r) return;
seg.add(l, r+1, X[id]);
}
void removeRange(int id) {
int l = lower_bound(all(xs), rangeL[id]) - xs.begin();
int r = upper_bound(all(xs), rangeR[id]) - xs.begin() - 1;
if (l > r) return;
seg.remove(l, r+1, X[id]);
}
set<P> kind[300000]; // (pos, i)
void add(int k, P val) {
int x = val._2;
auto it = kind[k].lower_bound(val);
assert(it != kind[k].end() && it != kind[k].begin());
int b = (*it)._2;
int a = (*(--it))._2;
kind[k].insert(val);
removeRange(a);
removeRange(b);
rangeR[a] = rangeL[x] = (X[a]+X[x])/2;
rangeR[x] = rangeL[b] = (X[b]+X[x])/2;
addRange(a);
addRange(b);
addRange(x);
}
void remove(int k, P val) {
int x = val._2;
kind[k].erase(val);
auto it = kind[k].lower_bound(val);
assert(it != kind[k].end() && it != kind[k].begin());
int b = (*it)._2;
int a = (*(--it))._2;
removeRange(a);
removeRange(b);
removeRange(x);
rangeR[a] = rangeL[b] = (X[a]+X[b])/2;
addRange(a);
addRange(b);
}
int maxDist(int pos) {
int x = index(xs, pos);
return seg.query(x, pos);
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> N >> K >> Q;
rep(i, N) {
cin >> X[i] >> T[i] >> A[i] >> B[i];
X[i] *= 2;
xs.pb(X[i]);
T[i]--;
years.pb(A[i]);
years.pb(B[i]+1);
}
rep(i, Q) {
cin >> L[i] >> Y[i];
L[i] *= 2;
xs.pb(L[i]);
years.pb(Y[i]);
}
sort(all(years)); uniq(years);
assert(years.size() <= MAX_Y);
rep(i, N) Gopen[index(years, A[i])].pb(i);
rep(i, N) Gclose[index(years, B[i]+1)].pb(i);
rep(i, Q) Gquery[index(years, Y[i])].pb(i);
rep(i, Q) ans[i] = -2;
sort(all(xs)); uniq(xs);
assert(xs.size() <= MAX_X);
rep(k, K) {
int id1 = N+2*k, id2 = N+2*k+1;
X[id1] = -INF;
kind[k].insert(P(-INF, id1));
rangeL[id1] = -INF;
rangeR[id1] = 0;
addRange(id1);
X[id2] = +INF;
kind[k].insert(P(+INF, id2));
rangeL[id2] = 0;
rangeR[id2] = +INF;
addRange(id2);
}
rep(y, years.size()) {
for (int i : Gopen[y]) add(T[i], P(X[i], i));
for (int i : Gclose[y]) remove(T[i], P(X[i], i));
for (int q : Gquery[y]) {
int m = maxDist(L[q])/2;
if (m > 1e8) m = -1;
ans[q] = m;
}
}
rep(i, Q) cout << ans[i] << "\n";
return 0;
}
Compilation message
new_home.cpp: In function 'int main()':
new_home.cpp:17:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define rep(i, n) for (int i=0; i<(n); i++)
^
new_home.cpp:174:3: note: in expansion of macro 'rep'
rep(y, years.size()) {
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
156 ms |
183416 KB |
Output is correct |
2 |
Correct |
178 ms |
183528 KB |
Output is correct |
3 |
Correct |
161 ms |
183528 KB |
Output is correct |
4 |
Correct |
187 ms |
183528 KB |
Output is correct |
5 |
Correct |
162 ms |
183696 KB |
Output is correct |
6 |
Correct |
167 ms |
183896 KB |
Output is correct |
7 |
Correct |
169 ms |
183896 KB |
Output is correct |
8 |
Correct |
199 ms |
183984 KB |
Output is correct |
9 |
Correct |
160 ms |
183984 KB |
Output is correct |
10 |
Correct |
177 ms |
183984 KB |
Output is correct |
11 |
Correct |
180 ms |
183984 KB |
Output is correct |
12 |
Correct |
177 ms |
184188 KB |
Output is correct |
13 |
Correct |
186 ms |
184188 KB |
Output is correct |
14 |
Correct |
172 ms |
184188 KB |
Output is correct |
15 |
Correct |
171 ms |
184188 KB |
Output is correct |
16 |
Correct |
183 ms |
184296 KB |
Output is correct |
17 |
Correct |
193 ms |
184464 KB |
Output is correct |
18 |
Correct |
184 ms |
184464 KB |
Output is correct |
19 |
Correct |
162 ms |
184464 KB |
Output is correct |
20 |
Correct |
166 ms |
184464 KB |
Output is correct |
21 |
Correct |
163 ms |
184524 KB |
Output is correct |
22 |
Correct |
189 ms |
184524 KB |
Output is correct |
23 |
Correct |
160 ms |
184524 KB |
Output is correct |
24 |
Correct |
162 ms |
184524 KB |
Output is correct |
25 |
Correct |
177 ms |
184544 KB |
Output is correct |
26 |
Correct |
188 ms |
184544 KB |
Output is correct |
27 |
Correct |
183 ms |
184544 KB |
Output is correct |
28 |
Correct |
186 ms |
184544 KB |
Output is correct |
29 |
Correct |
201 ms |
184544 KB |
Output is correct |
30 |
Correct |
181 ms |
184544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
156 ms |
183416 KB |
Output is correct |
2 |
Correct |
178 ms |
183528 KB |
Output is correct |
3 |
Correct |
161 ms |
183528 KB |
Output is correct |
4 |
Correct |
187 ms |
183528 KB |
Output is correct |
5 |
Correct |
162 ms |
183696 KB |
Output is correct |
6 |
Correct |
167 ms |
183896 KB |
Output is correct |
7 |
Correct |
169 ms |
183896 KB |
Output is correct |
8 |
Correct |
199 ms |
183984 KB |
Output is correct |
9 |
Correct |
160 ms |
183984 KB |
Output is correct |
10 |
Correct |
177 ms |
183984 KB |
Output is correct |
11 |
Correct |
180 ms |
183984 KB |
Output is correct |
12 |
Correct |
177 ms |
184188 KB |
Output is correct |
13 |
Correct |
186 ms |
184188 KB |
Output is correct |
14 |
Correct |
172 ms |
184188 KB |
Output is correct |
15 |
Correct |
171 ms |
184188 KB |
Output is correct |
16 |
Correct |
183 ms |
184296 KB |
Output is correct |
17 |
Correct |
193 ms |
184464 KB |
Output is correct |
18 |
Correct |
184 ms |
184464 KB |
Output is correct |
19 |
Correct |
162 ms |
184464 KB |
Output is correct |
20 |
Correct |
166 ms |
184464 KB |
Output is correct |
21 |
Correct |
163 ms |
184524 KB |
Output is correct |
22 |
Correct |
189 ms |
184524 KB |
Output is correct |
23 |
Correct |
160 ms |
184524 KB |
Output is correct |
24 |
Correct |
162 ms |
184524 KB |
Output is correct |
25 |
Correct |
177 ms |
184544 KB |
Output is correct |
26 |
Correct |
188 ms |
184544 KB |
Output is correct |
27 |
Correct |
183 ms |
184544 KB |
Output is correct |
28 |
Correct |
186 ms |
184544 KB |
Output is correct |
29 |
Correct |
201 ms |
184544 KB |
Output is correct |
30 |
Correct |
181 ms |
184544 KB |
Output is correct |
31 |
Correct |
4394 ms |
225492 KB |
Output is correct |
32 |
Correct |
561 ms |
225492 KB |
Output is correct |
33 |
Correct |
1885 ms |
225492 KB |
Output is correct |
34 |
Correct |
3650 ms |
225492 KB |
Output is correct |
35 |
Correct |
3246 ms |
230704 KB |
Output is correct |
36 |
Correct |
2081 ms |
230704 KB |
Output is correct |
37 |
Correct |
1426 ms |
230704 KB |
Output is correct |
38 |
Correct |
1133 ms |
230704 KB |
Output is correct |
39 |
Correct |
809 ms |
230704 KB |
Output is correct |
40 |
Correct |
888 ms |
230704 KB |
Output is correct |
41 |
Correct |
1469 ms |
230704 KB |
Output is correct |
42 |
Correct |
1502 ms |
230704 KB |
Output is correct |
43 |
Correct |
385 ms |
230704 KB |
Output is correct |
44 |
Correct |
1313 ms |
232336 KB |
Output is correct |
45 |
Correct |
1177 ms |
235164 KB |
Output is correct |
46 |
Correct |
995 ms |
237952 KB |
Output is correct |
47 |
Correct |
725 ms |
240020 KB |
Output is correct |
48 |
Correct |
665 ms |
242884 KB |
Output is correct |
49 |
Correct |
875 ms |
245836 KB |
Output is correct |
50 |
Correct |
1102 ms |
249208 KB |
Output is correct |
51 |
Correct |
834 ms |
251700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
836 ms |
491048 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1177 ms |
520576 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
156 ms |
183416 KB |
Output is correct |
2 |
Correct |
178 ms |
183528 KB |
Output is correct |
3 |
Correct |
161 ms |
183528 KB |
Output is correct |
4 |
Correct |
187 ms |
183528 KB |
Output is correct |
5 |
Correct |
162 ms |
183696 KB |
Output is correct |
6 |
Correct |
167 ms |
183896 KB |
Output is correct |
7 |
Correct |
169 ms |
183896 KB |
Output is correct |
8 |
Correct |
199 ms |
183984 KB |
Output is correct |
9 |
Correct |
160 ms |
183984 KB |
Output is correct |
10 |
Correct |
177 ms |
183984 KB |
Output is correct |
11 |
Correct |
180 ms |
183984 KB |
Output is correct |
12 |
Correct |
177 ms |
184188 KB |
Output is correct |
13 |
Correct |
186 ms |
184188 KB |
Output is correct |
14 |
Correct |
172 ms |
184188 KB |
Output is correct |
15 |
Correct |
171 ms |
184188 KB |
Output is correct |
16 |
Correct |
183 ms |
184296 KB |
Output is correct |
17 |
Correct |
193 ms |
184464 KB |
Output is correct |
18 |
Correct |
184 ms |
184464 KB |
Output is correct |
19 |
Correct |
162 ms |
184464 KB |
Output is correct |
20 |
Correct |
166 ms |
184464 KB |
Output is correct |
21 |
Correct |
163 ms |
184524 KB |
Output is correct |
22 |
Correct |
189 ms |
184524 KB |
Output is correct |
23 |
Correct |
160 ms |
184524 KB |
Output is correct |
24 |
Correct |
162 ms |
184524 KB |
Output is correct |
25 |
Correct |
177 ms |
184544 KB |
Output is correct |
26 |
Correct |
188 ms |
184544 KB |
Output is correct |
27 |
Correct |
183 ms |
184544 KB |
Output is correct |
28 |
Correct |
186 ms |
184544 KB |
Output is correct |
29 |
Correct |
201 ms |
184544 KB |
Output is correct |
30 |
Correct |
181 ms |
184544 KB |
Output is correct |
31 |
Correct |
4394 ms |
225492 KB |
Output is correct |
32 |
Correct |
561 ms |
225492 KB |
Output is correct |
33 |
Correct |
1885 ms |
225492 KB |
Output is correct |
34 |
Correct |
3650 ms |
225492 KB |
Output is correct |
35 |
Correct |
3246 ms |
230704 KB |
Output is correct |
36 |
Correct |
2081 ms |
230704 KB |
Output is correct |
37 |
Correct |
1426 ms |
230704 KB |
Output is correct |
38 |
Correct |
1133 ms |
230704 KB |
Output is correct |
39 |
Correct |
809 ms |
230704 KB |
Output is correct |
40 |
Correct |
888 ms |
230704 KB |
Output is correct |
41 |
Correct |
1469 ms |
230704 KB |
Output is correct |
42 |
Correct |
1502 ms |
230704 KB |
Output is correct |
43 |
Correct |
385 ms |
230704 KB |
Output is correct |
44 |
Correct |
1313 ms |
232336 KB |
Output is correct |
45 |
Correct |
1177 ms |
235164 KB |
Output is correct |
46 |
Correct |
995 ms |
237952 KB |
Output is correct |
47 |
Correct |
725 ms |
240020 KB |
Output is correct |
48 |
Correct |
665 ms |
242884 KB |
Output is correct |
49 |
Correct |
875 ms |
245836 KB |
Output is correct |
50 |
Correct |
1102 ms |
249208 KB |
Output is correct |
51 |
Correct |
834 ms |
251700 KB |
Output is correct |
52 |
Correct |
2622 ms |
542216 KB |
Output is correct |
53 |
Correct |
2285 ms |
543652 KB |
Output is correct |
54 |
Correct |
4070 ms |
546184 KB |
Output is correct |
55 |
Correct |
1618 ms |
546184 KB |
Output is correct |
56 |
Correct |
1544 ms |
546184 KB |
Output is correct |
57 |
Correct |
1629 ms |
546184 KB |
Output is correct |
58 |
Correct |
1849 ms |
546184 KB |
Output is correct |
59 |
Correct |
1811 ms |
546184 KB |
Output is correct |
60 |
Correct |
1566 ms |
546184 KB |
Output is correct |
61 |
Correct |
362 ms |
546184 KB |
Output is correct |
62 |
Correct |
1680 ms |
563700 KB |
Output is correct |
63 |
Correct |
3163 ms |
566412 KB |
Output is correct |
64 |
Correct |
3411 ms |
566412 KB |
Output is correct |
65 |
Correct |
3679 ms |
566412 KB |
Output is correct |
66 |
Correct |
1734 ms |
566412 KB |
Output is correct |
67 |
Correct |
1308 ms |
566412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
156 ms |
183416 KB |
Output is correct |
2 |
Correct |
178 ms |
183528 KB |
Output is correct |
3 |
Correct |
161 ms |
183528 KB |
Output is correct |
4 |
Correct |
187 ms |
183528 KB |
Output is correct |
5 |
Correct |
162 ms |
183696 KB |
Output is correct |
6 |
Correct |
167 ms |
183896 KB |
Output is correct |
7 |
Correct |
169 ms |
183896 KB |
Output is correct |
8 |
Correct |
199 ms |
183984 KB |
Output is correct |
9 |
Correct |
160 ms |
183984 KB |
Output is correct |
10 |
Correct |
177 ms |
183984 KB |
Output is correct |
11 |
Correct |
180 ms |
183984 KB |
Output is correct |
12 |
Correct |
177 ms |
184188 KB |
Output is correct |
13 |
Correct |
186 ms |
184188 KB |
Output is correct |
14 |
Correct |
172 ms |
184188 KB |
Output is correct |
15 |
Correct |
171 ms |
184188 KB |
Output is correct |
16 |
Correct |
183 ms |
184296 KB |
Output is correct |
17 |
Correct |
193 ms |
184464 KB |
Output is correct |
18 |
Correct |
184 ms |
184464 KB |
Output is correct |
19 |
Correct |
162 ms |
184464 KB |
Output is correct |
20 |
Correct |
166 ms |
184464 KB |
Output is correct |
21 |
Correct |
163 ms |
184524 KB |
Output is correct |
22 |
Correct |
189 ms |
184524 KB |
Output is correct |
23 |
Correct |
160 ms |
184524 KB |
Output is correct |
24 |
Correct |
162 ms |
184524 KB |
Output is correct |
25 |
Correct |
177 ms |
184544 KB |
Output is correct |
26 |
Correct |
188 ms |
184544 KB |
Output is correct |
27 |
Correct |
183 ms |
184544 KB |
Output is correct |
28 |
Correct |
186 ms |
184544 KB |
Output is correct |
29 |
Correct |
201 ms |
184544 KB |
Output is correct |
30 |
Correct |
181 ms |
184544 KB |
Output is correct |
31 |
Correct |
4394 ms |
225492 KB |
Output is correct |
32 |
Correct |
561 ms |
225492 KB |
Output is correct |
33 |
Correct |
1885 ms |
225492 KB |
Output is correct |
34 |
Correct |
3650 ms |
225492 KB |
Output is correct |
35 |
Correct |
3246 ms |
230704 KB |
Output is correct |
36 |
Correct |
2081 ms |
230704 KB |
Output is correct |
37 |
Correct |
1426 ms |
230704 KB |
Output is correct |
38 |
Correct |
1133 ms |
230704 KB |
Output is correct |
39 |
Correct |
809 ms |
230704 KB |
Output is correct |
40 |
Correct |
888 ms |
230704 KB |
Output is correct |
41 |
Correct |
1469 ms |
230704 KB |
Output is correct |
42 |
Correct |
1502 ms |
230704 KB |
Output is correct |
43 |
Correct |
385 ms |
230704 KB |
Output is correct |
44 |
Correct |
1313 ms |
232336 KB |
Output is correct |
45 |
Correct |
1177 ms |
235164 KB |
Output is correct |
46 |
Correct |
995 ms |
237952 KB |
Output is correct |
47 |
Correct |
725 ms |
240020 KB |
Output is correct |
48 |
Correct |
665 ms |
242884 KB |
Output is correct |
49 |
Correct |
875 ms |
245836 KB |
Output is correct |
50 |
Correct |
1102 ms |
249208 KB |
Output is correct |
51 |
Correct |
834 ms |
251700 KB |
Output is correct |
52 |
Runtime error |
836 ms |
491048 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
53 |
Halted |
0 ms |
0 KB |
- |