# include <stdio.h>
# include <bits/stdc++.h>
#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y) for (int i = x; i <= y; i ++)
#define FOr(i,x,y) for (int i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to... Red
using namespace std;
inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }
inline bool isvowel (char c) {
c = tolower(c);
if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
return 0;
}
const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;
const int M = 22;
const int pri = 997;
const int Magic = 2101;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int n, q, k;
int x[N], t[N], a[N], b[N];
int l[N], y[N];
int ans[N];
vector < int > pp;
inline void solve () {
for (int i = 1; i <= n; i ++)
pp.pb(a[i]), pp.pb(b[i]);
for (int i = 1; i <= q; i ++) {
pp.pb(y[i]);
}
sort(every(pp));
pp.resize(unique(every(pp)) - pp.begin());
vector < vector < pair < int, int > > > add(pp.size() + 2);
vector < vector < pair < int, int > > > del(pp.size() + 2);
vector < vector < pair < int, int > > > query(pp.size() + 2);
multiset < int > bl[k + 1];
for (int i = 1; i <= k; i ++)
bl[i].clear();
for (int i = 1; i <= n; i ++) {
a[i] = lower_bound(every(pp), a[i]) - pp.begin();
b[i] = lower_bound(every(pp), b[i]) - pp.begin();
add[a[i]].pb(mp(x[i], t[i]));
del[b[i]].pb(mp(x[i], t[i]));
}
for (int i = 1; i <= q; i ++) {
y[i] = lower_bound(every(pp), y[i]) - pp.begin();
query[y[i]].pb(mp(l[i], i));
}
for (int vv = 0; vv < pp.size(); vv ++) {
for (auto it : add[vv]) bl[it.S].insert(it.F);
for (auto q : query[vv]) {
int res = 0;
for (int w = 1; w <= k; w ++) {
if (bl[w].empty()) {
res = -1;
break;
}
int cur = inf;
auto l = bl[w].upper_bound(q.F);
if (l != bl[w].end()) {
cur = min(cur, *l - q.F);
}
if (l != bl[w].begin()) {
--l;
cur = min(cur, q.F - *l);
}
// cout << cur << ' ' << w << '\n';
res = max(res, cur);
}
ans[q.S] = res;
}
for (auto it : del[vv]) bl[it.S].erase(bl[it.S].find(it.F));
}
for (int i = 1; i <= q; i ++)
cout << ans[i] << '\n';
}
int main () {
SpeedForce;
cin >> n >> k >> q;
for (int i = 1; i <= n; i ++) {
cin >> x[i] >> t[i] >> a[i] >> b[i];
}
for (int i = 1; i <= q; i ++) {
cin >> l[i] >> y[i];
}
if (k < 500) {
solve();
exit(0);
}
return Accepted;
}
// B...a D....
Compilation message
new_home.cpp: In function 'void solve()':
new_home.cpp:77:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int vv = 0; vv < pp.size(); vv ++) {
~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
576 KB |
Output is correct |
10 |
Correct |
4 ms |
564 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
3 ms |
512 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
3 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
3 ms |
512 KB |
Output is correct |
20 |
Correct |
3 ms |
512 KB |
Output is correct |
21 |
Correct |
3 ms |
512 KB |
Output is correct |
22 |
Correct |
3 ms |
640 KB |
Output is correct |
23 |
Correct |
3 ms |
512 KB |
Output is correct |
24 |
Correct |
4 ms |
624 KB |
Output is correct |
25 |
Correct |
3 ms |
512 KB |
Output is correct |
26 |
Correct |
4 ms |
512 KB |
Output is correct |
27 |
Correct |
3 ms |
512 KB |
Output is correct |
28 |
Correct |
3 ms |
512 KB |
Output is correct |
29 |
Correct |
3 ms |
512 KB |
Output is correct |
30 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
576 KB |
Output is correct |
10 |
Correct |
4 ms |
564 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
3 ms |
512 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
3 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
3 ms |
512 KB |
Output is correct |
20 |
Correct |
3 ms |
512 KB |
Output is correct |
21 |
Correct |
3 ms |
512 KB |
Output is correct |
22 |
Correct |
3 ms |
640 KB |
Output is correct |
23 |
Correct |
3 ms |
512 KB |
Output is correct |
24 |
Correct |
4 ms |
624 KB |
Output is correct |
25 |
Correct |
3 ms |
512 KB |
Output is correct |
26 |
Correct |
4 ms |
512 KB |
Output is correct |
27 |
Correct |
3 ms |
512 KB |
Output is correct |
28 |
Correct |
3 ms |
512 KB |
Output is correct |
29 |
Correct |
3 ms |
512 KB |
Output is correct |
30 |
Correct |
2 ms |
512 KB |
Output is correct |
31 |
Correct |
2762 ms |
27540 KB |
Output is correct |
32 |
Correct |
113 ms |
6484 KB |
Output is correct |
33 |
Correct |
324 ms |
25392 KB |
Output is correct |
34 |
Correct |
2281 ms |
25696 KB |
Output is correct |
35 |
Correct |
1453 ms |
27376 KB |
Output is correct |
36 |
Correct |
386 ms |
27224 KB |
Output is correct |
37 |
Correct |
263 ms |
24560 KB |
Output is correct |
38 |
Correct |
230 ms |
24536 KB |
Output is correct |
39 |
Correct |
164 ms |
24356 KB |
Output is correct |
40 |
Correct |
203 ms |
24304 KB |
Output is correct |
41 |
Correct |
371 ms |
24556 KB |
Output is correct |
42 |
Correct |
311 ms |
24432 KB |
Output is correct |
43 |
Correct |
350 ms |
9968 KB |
Output is correct |
44 |
Correct |
314 ms |
24560 KB |
Output is correct |
45 |
Correct |
222 ms |
24404 KB |
Output is correct |
46 |
Correct |
181 ms |
24428 KB |
Output is correct |
47 |
Correct |
144 ms |
23592 KB |
Output is correct |
48 |
Correct |
136 ms |
23384 KB |
Output is correct |
49 |
Correct |
137 ms |
23796 KB |
Output is correct |
50 |
Correct |
256 ms |
24284 KB |
Output is correct |
51 |
Correct |
137 ms |
23852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
216 ms |
20984 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
184 ms |
20348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
576 KB |
Output is correct |
10 |
Correct |
4 ms |
564 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
3 ms |
512 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
3 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
3 ms |
512 KB |
Output is correct |
20 |
Correct |
3 ms |
512 KB |
Output is correct |
21 |
Correct |
3 ms |
512 KB |
Output is correct |
22 |
Correct |
3 ms |
640 KB |
Output is correct |
23 |
Correct |
3 ms |
512 KB |
Output is correct |
24 |
Correct |
4 ms |
624 KB |
Output is correct |
25 |
Correct |
3 ms |
512 KB |
Output is correct |
26 |
Correct |
4 ms |
512 KB |
Output is correct |
27 |
Correct |
3 ms |
512 KB |
Output is correct |
28 |
Correct |
3 ms |
512 KB |
Output is correct |
29 |
Correct |
3 ms |
512 KB |
Output is correct |
30 |
Correct |
2 ms |
512 KB |
Output is correct |
31 |
Correct |
2762 ms |
27540 KB |
Output is correct |
32 |
Correct |
113 ms |
6484 KB |
Output is correct |
33 |
Correct |
324 ms |
25392 KB |
Output is correct |
34 |
Correct |
2281 ms |
25696 KB |
Output is correct |
35 |
Correct |
1453 ms |
27376 KB |
Output is correct |
36 |
Correct |
386 ms |
27224 KB |
Output is correct |
37 |
Correct |
263 ms |
24560 KB |
Output is correct |
38 |
Correct |
230 ms |
24536 KB |
Output is correct |
39 |
Correct |
164 ms |
24356 KB |
Output is correct |
40 |
Correct |
203 ms |
24304 KB |
Output is correct |
41 |
Correct |
371 ms |
24556 KB |
Output is correct |
42 |
Correct |
311 ms |
24432 KB |
Output is correct |
43 |
Correct |
350 ms |
9968 KB |
Output is correct |
44 |
Correct |
314 ms |
24560 KB |
Output is correct |
45 |
Correct |
222 ms |
24404 KB |
Output is correct |
46 |
Correct |
181 ms |
24428 KB |
Output is correct |
47 |
Correct |
144 ms |
23592 KB |
Output is correct |
48 |
Correct |
136 ms |
23384 KB |
Output is correct |
49 |
Correct |
137 ms |
23796 KB |
Output is correct |
50 |
Correct |
256 ms |
24284 KB |
Output is correct |
51 |
Correct |
137 ms |
23852 KB |
Output is correct |
52 |
Incorrect |
47 ms |
4824 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
576 KB |
Output is correct |
10 |
Correct |
4 ms |
564 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
3 ms |
512 KB |
Output is correct |
14 |
Correct |
3 ms |
512 KB |
Output is correct |
15 |
Correct |
3 ms |
512 KB |
Output is correct |
16 |
Correct |
3 ms |
512 KB |
Output is correct |
17 |
Correct |
3 ms |
512 KB |
Output is correct |
18 |
Correct |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
3 ms |
512 KB |
Output is correct |
20 |
Correct |
3 ms |
512 KB |
Output is correct |
21 |
Correct |
3 ms |
512 KB |
Output is correct |
22 |
Correct |
3 ms |
640 KB |
Output is correct |
23 |
Correct |
3 ms |
512 KB |
Output is correct |
24 |
Correct |
4 ms |
624 KB |
Output is correct |
25 |
Correct |
3 ms |
512 KB |
Output is correct |
26 |
Correct |
4 ms |
512 KB |
Output is correct |
27 |
Correct |
3 ms |
512 KB |
Output is correct |
28 |
Correct |
3 ms |
512 KB |
Output is correct |
29 |
Correct |
3 ms |
512 KB |
Output is correct |
30 |
Correct |
2 ms |
512 KB |
Output is correct |
31 |
Correct |
2762 ms |
27540 KB |
Output is correct |
32 |
Correct |
113 ms |
6484 KB |
Output is correct |
33 |
Correct |
324 ms |
25392 KB |
Output is correct |
34 |
Correct |
2281 ms |
25696 KB |
Output is correct |
35 |
Correct |
1453 ms |
27376 KB |
Output is correct |
36 |
Correct |
386 ms |
27224 KB |
Output is correct |
37 |
Correct |
263 ms |
24560 KB |
Output is correct |
38 |
Correct |
230 ms |
24536 KB |
Output is correct |
39 |
Correct |
164 ms |
24356 KB |
Output is correct |
40 |
Correct |
203 ms |
24304 KB |
Output is correct |
41 |
Correct |
371 ms |
24556 KB |
Output is correct |
42 |
Correct |
311 ms |
24432 KB |
Output is correct |
43 |
Correct |
350 ms |
9968 KB |
Output is correct |
44 |
Correct |
314 ms |
24560 KB |
Output is correct |
45 |
Correct |
222 ms |
24404 KB |
Output is correct |
46 |
Correct |
181 ms |
24428 KB |
Output is correct |
47 |
Correct |
144 ms |
23592 KB |
Output is correct |
48 |
Correct |
136 ms |
23384 KB |
Output is correct |
49 |
Correct |
137 ms |
23796 KB |
Output is correct |
50 |
Correct |
256 ms |
24284 KB |
Output is correct |
51 |
Correct |
137 ms |
23852 KB |
Output is correct |
52 |
Incorrect |
216 ms |
20984 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |