#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define N 1000005
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
int x[N], ans[N], y[N], l[N], t[N], a[N], b[N];
int n, k, q;
vector<int> tmp;
vector<pair<int, int> > sh[N];
multiset<pair<int, int> > in;
vector<pair<pair<int, int>, pair<int, int> > > lol;
int seg[N];
void update(int id, int l, int r, int L, int R, int v){
if(l >= L && r <= R){
seg[id] = max(seg[id], v);
return;
}
if(l > R || r < L) return;
int m = (l + r) >> 1;
update(id << 1, l, m, L, R, v);
update(id << 1 | 1, m + 1, r, L, R, v);
}
int query(int id, int l, int r, int x){
if(x < l || x > r) return 0;
if(l == r) return seg[id];
int m = (l + r) >> 1;
return max(seg[id], max(query(id << 1, l, m, x), query(id << 1 | 1, m + 1, r, x)));
}
void solve(){
lol.clear();
memset(seg, 0, sizeof seg);
for(int i = 1; i <= k; ++i){
in.clear();
in.insert({INF, 1});
in.insert({-INF, 1});
for(auto& x : sh[i]){
if(x.ss > 0){
auto r = in.insert({x.ss, -x.ff});
auto l = r++;
auto it = l--;
lol.push_back({{(r -> ff + l -> ff) / 2, r -> ff}, {-r -> ss, x.ff - 1}});
in.insert({r -> ff, -x.ff});
in.erase(r);
} else {
auto r = in.lower_bound({-x.ss, -1000000});
auto l = r++;
auto it = l--;
lol.push_back({{(it -> ff + l -> ff) / 2, it -> ff}, {-it -> ss, x.ff - 1}});
lol.push_back({{(it -> ff + r -> ff) / 2, r -> ff}, {-r -> ss, x.ff - 1}});
in.insert({r -> ff, -x.ff});
in.erase(it);
in.erase(r);
}
}
auto r = in.begin();
auto l = r++;
lol.push_back({{(r -> ff + l -> ff) / 2, r -> ff}, {-r -> ss, tmp.size()}});
}
for(int i = 1; i <= q; ++i)
lol.push_back({{l[i], 1'000'000'000}, {i, y[i]}});
sort(lol.begin(), lol.end());
for(auto& x : lol){
if(x.ff.ss != 1'000'000'000){
if(x.ss.ff <= x.ss.ss && x.ff.ss > 0){
update(1, 1, 300'005, x.ss.ff, x.ss.ss, x.ff.ss);
}
}
else
ans[x.ss.ff] = max(ans[x.ss.ff], query(1, 1, 300'005, x.ss.ss) - x.ff.ff);
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
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];
l[i] <<= 1;
tmp.push_back(y[i]);
}
sort(tmp.begin(), tmp.end());
tmp.resize(unique(tmp.begin(), tmp.end()) - tmp.begin());
for(int i = 1; i <= q; ++i)
y[i] = upper_bound(tmp.begin(), tmp.end(), y[i]) - tmp.begin();
for(int i = 1; i <= n; ++i){
a[i] = lower_bound(tmp.begin(), tmp.end(), a[i]) - tmp.begin() + 1;
b[i] = lower_bound(tmp.begin(), tmp.end(), b[i] + 1) - tmp.begin() + 1;
if(a[i] < b[i]){
x[i] <<= 1;
sh[t[i]].push_back({a[i], x[i]});
sh[t[i]].push_back({b[i], -x[i]});
}
}
for(int i = 1; i <= k; ++i)
sort(sh[i].begin(), sh[i].end());
solve();
for(int i = 1; i <= q; ++i)
l[i] = 200'000'002 - l[i];
for(int i = 1; i <= k; ++i)
for(auto& x : sh[i])
if(x.ss > 0)
x.ss = 200'000'002 - x.ss;
else
x.ss = -200'000'002 - x.ss;
solve();
for(int i = 1; i <= q; ++i){
if(ans[i] > 400'000'002)
cout<<"-1\n";
else
cout<<ans[i] / 2<<'\n';
}
}
Compilation message
new_home.cpp: In function 'void solve()':
new_home.cpp:49:22: warning: variable 'it' set but not used [-Wunused-but-set-variable]
auto it = l--;
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
27776 KB |
Output is correct |
2 |
Correct |
21 ms |
27776 KB |
Output is correct |
3 |
Correct |
21 ms |
27776 KB |
Output is correct |
4 |
Correct |
22 ms |
27776 KB |
Output is correct |
5 |
Correct |
22 ms |
27904 KB |
Output is correct |
6 |
Correct |
22 ms |
27904 KB |
Output is correct |
7 |
Correct |
23 ms |
27904 KB |
Output is correct |
8 |
Correct |
23 ms |
27904 KB |
Output is correct |
9 |
Correct |
23 ms |
27904 KB |
Output is correct |
10 |
Correct |
24 ms |
27904 KB |
Output is correct |
11 |
Correct |
23 ms |
27904 KB |
Output is correct |
12 |
Correct |
22 ms |
27904 KB |
Output is correct |
13 |
Correct |
22 ms |
27904 KB |
Output is correct |
14 |
Correct |
23 ms |
27904 KB |
Output is correct |
15 |
Correct |
23 ms |
27904 KB |
Output is correct |
16 |
Correct |
22 ms |
28032 KB |
Output is correct |
17 |
Correct |
22 ms |
27904 KB |
Output is correct |
18 |
Correct |
22 ms |
27904 KB |
Output is correct |
19 |
Correct |
22 ms |
27904 KB |
Output is correct |
20 |
Correct |
22 ms |
27904 KB |
Output is correct |
21 |
Correct |
22 ms |
28032 KB |
Output is correct |
22 |
Correct |
22 ms |
27904 KB |
Output is correct |
23 |
Correct |
22 ms |
27904 KB |
Output is correct |
24 |
Correct |
22 ms |
28032 KB |
Output is correct |
25 |
Correct |
23 ms |
27904 KB |
Output is correct |
26 |
Correct |
23 ms |
27904 KB |
Output is correct |
27 |
Correct |
21 ms |
27904 KB |
Output is correct |
28 |
Correct |
23 ms |
27904 KB |
Output is correct |
29 |
Correct |
22 ms |
27904 KB |
Output is correct |
30 |
Correct |
24 ms |
27904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
27776 KB |
Output is correct |
2 |
Correct |
21 ms |
27776 KB |
Output is correct |
3 |
Correct |
21 ms |
27776 KB |
Output is correct |
4 |
Correct |
22 ms |
27776 KB |
Output is correct |
5 |
Correct |
22 ms |
27904 KB |
Output is correct |
6 |
Correct |
22 ms |
27904 KB |
Output is correct |
7 |
Correct |
23 ms |
27904 KB |
Output is correct |
8 |
Correct |
23 ms |
27904 KB |
Output is correct |
9 |
Correct |
23 ms |
27904 KB |
Output is correct |
10 |
Correct |
24 ms |
27904 KB |
Output is correct |
11 |
Correct |
23 ms |
27904 KB |
Output is correct |
12 |
Correct |
22 ms |
27904 KB |
Output is correct |
13 |
Correct |
22 ms |
27904 KB |
Output is correct |
14 |
Correct |
23 ms |
27904 KB |
Output is correct |
15 |
Correct |
23 ms |
27904 KB |
Output is correct |
16 |
Correct |
22 ms |
28032 KB |
Output is correct |
17 |
Correct |
22 ms |
27904 KB |
Output is correct |
18 |
Correct |
22 ms |
27904 KB |
Output is correct |
19 |
Correct |
22 ms |
27904 KB |
Output is correct |
20 |
Correct |
22 ms |
27904 KB |
Output is correct |
21 |
Correct |
22 ms |
28032 KB |
Output is correct |
22 |
Correct |
22 ms |
27904 KB |
Output is correct |
23 |
Correct |
22 ms |
27904 KB |
Output is correct |
24 |
Correct |
22 ms |
28032 KB |
Output is correct |
25 |
Correct |
23 ms |
27904 KB |
Output is correct |
26 |
Correct |
23 ms |
27904 KB |
Output is correct |
27 |
Correct |
21 ms |
27904 KB |
Output is correct |
28 |
Correct |
23 ms |
27904 KB |
Output is correct |
29 |
Correct |
22 ms |
27904 KB |
Output is correct |
30 |
Correct |
24 ms |
27904 KB |
Output is correct |
31 |
Correct |
350 ms |
36116 KB |
Output is correct |
32 |
Correct |
202 ms |
35036 KB |
Output is correct |
33 |
Correct |
370 ms |
35640 KB |
Output is correct |
34 |
Correct |
340 ms |
36064 KB |
Output is correct |
35 |
Correct |
358 ms |
35528 KB |
Output is correct |
36 |
Correct |
372 ms |
35556 KB |
Output is correct |
37 |
Correct |
324 ms |
35424 KB |
Output is correct |
38 |
Correct |
345 ms |
35288 KB |
Output is correct |
39 |
Correct |
292 ms |
35200 KB |
Output is correct |
40 |
Correct |
301 ms |
35104 KB |
Output is correct |
41 |
Correct |
298 ms |
35428 KB |
Output is correct |
42 |
Correct |
295 ms |
35560 KB |
Output is correct |
43 |
Correct |
159 ms |
36072 KB |
Output is correct |
44 |
Correct |
289 ms |
35712 KB |
Output is correct |
45 |
Correct |
283 ms |
35572 KB |
Output is correct |
46 |
Correct |
265 ms |
35552 KB |
Output is correct |
47 |
Correct |
224 ms |
35044 KB |
Output is correct |
48 |
Correct |
222 ms |
35032 KB |
Output is correct |
49 |
Correct |
249 ms |
35300 KB |
Output is correct |
50 |
Correct |
270 ms |
35808 KB |
Output is correct |
51 |
Correct |
244 ms |
35428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1111 ms |
76992 KB |
Output is correct |
2 |
Incorrect |
1114 ms |
89284 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
980 ms |
127936 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
27776 KB |
Output is correct |
2 |
Correct |
21 ms |
27776 KB |
Output is correct |
3 |
Correct |
21 ms |
27776 KB |
Output is correct |
4 |
Correct |
22 ms |
27776 KB |
Output is correct |
5 |
Correct |
22 ms |
27904 KB |
Output is correct |
6 |
Correct |
22 ms |
27904 KB |
Output is correct |
7 |
Correct |
23 ms |
27904 KB |
Output is correct |
8 |
Correct |
23 ms |
27904 KB |
Output is correct |
9 |
Correct |
23 ms |
27904 KB |
Output is correct |
10 |
Correct |
24 ms |
27904 KB |
Output is correct |
11 |
Correct |
23 ms |
27904 KB |
Output is correct |
12 |
Correct |
22 ms |
27904 KB |
Output is correct |
13 |
Correct |
22 ms |
27904 KB |
Output is correct |
14 |
Correct |
23 ms |
27904 KB |
Output is correct |
15 |
Correct |
23 ms |
27904 KB |
Output is correct |
16 |
Correct |
22 ms |
28032 KB |
Output is correct |
17 |
Correct |
22 ms |
27904 KB |
Output is correct |
18 |
Correct |
22 ms |
27904 KB |
Output is correct |
19 |
Correct |
22 ms |
27904 KB |
Output is correct |
20 |
Correct |
22 ms |
27904 KB |
Output is correct |
21 |
Correct |
22 ms |
28032 KB |
Output is correct |
22 |
Correct |
22 ms |
27904 KB |
Output is correct |
23 |
Correct |
22 ms |
27904 KB |
Output is correct |
24 |
Correct |
22 ms |
28032 KB |
Output is correct |
25 |
Correct |
23 ms |
27904 KB |
Output is correct |
26 |
Correct |
23 ms |
27904 KB |
Output is correct |
27 |
Correct |
21 ms |
27904 KB |
Output is correct |
28 |
Correct |
23 ms |
27904 KB |
Output is correct |
29 |
Correct |
22 ms |
27904 KB |
Output is correct |
30 |
Correct |
24 ms |
27904 KB |
Output is correct |
31 |
Correct |
350 ms |
36116 KB |
Output is correct |
32 |
Correct |
202 ms |
35036 KB |
Output is correct |
33 |
Correct |
370 ms |
35640 KB |
Output is correct |
34 |
Correct |
340 ms |
36064 KB |
Output is correct |
35 |
Correct |
358 ms |
35528 KB |
Output is correct |
36 |
Correct |
372 ms |
35556 KB |
Output is correct |
37 |
Correct |
324 ms |
35424 KB |
Output is correct |
38 |
Correct |
345 ms |
35288 KB |
Output is correct |
39 |
Correct |
292 ms |
35200 KB |
Output is correct |
40 |
Correct |
301 ms |
35104 KB |
Output is correct |
41 |
Correct |
298 ms |
35428 KB |
Output is correct |
42 |
Correct |
295 ms |
35560 KB |
Output is correct |
43 |
Correct |
159 ms |
36072 KB |
Output is correct |
44 |
Correct |
289 ms |
35712 KB |
Output is correct |
45 |
Correct |
283 ms |
35572 KB |
Output is correct |
46 |
Correct |
265 ms |
35552 KB |
Output is correct |
47 |
Correct |
224 ms |
35044 KB |
Output is correct |
48 |
Correct |
222 ms |
35032 KB |
Output is correct |
49 |
Correct |
249 ms |
35300 KB |
Output is correct |
50 |
Correct |
270 ms |
35808 KB |
Output is correct |
51 |
Correct |
244 ms |
35428 KB |
Output is correct |
52 |
Correct |
352 ms |
40040 KB |
Output is correct |
53 |
Correct |
350 ms |
39976 KB |
Output is correct |
54 |
Correct |
332 ms |
36064 KB |
Output is correct |
55 |
Correct |
300 ms |
36192 KB |
Output is correct |
56 |
Correct |
304 ms |
39656 KB |
Output is correct |
57 |
Correct |
299 ms |
35560 KB |
Output is correct |
58 |
Correct |
321 ms |
36192 KB |
Output is correct |
59 |
Correct |
314 ms |
39648 KB |
Output is correct |
60 |
Correct |
297 ms |
35936 KB |
Output is correct |
61 |
Correct |
188 ms |
39912 KB |
Output is correct |
62 |
Correct |
340 ms |
39912 KB |
Output is correct |
63 |
Correct |
335 ms |
39780 KB |
Output is correct |
64 |
Correct |
316 ms |
35812 KB |
Output is correct |
65 |
Correct |
311 ms |
35808 KB |
Output is correct |
66 |
Correct |
291 ms |
35808 KB |
Output is correct |
67 |
Correct |
221 ms |
35432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
27776 KB |
Output is correct |
2 |
Correct |
21 ms |
27776 KB |
Output is correct |
3 |
Correct |
21 ms |
27776 KB |
Output is correct |
4 |
Correct |
22 ms |
27776 KB |
Output is correct |
5 |
Correct |
22 ms |
27904 KB |
Output is correct |
6 |
Correct |
22 ms |
27904 KB |
Output is correct |
7 |
Correct |
23 ms |
27904 KB |
Output is correct |
8 |
Correct |
23 ms |
27904 KB |
Output is correct |
9 |
Correct |
23 ms |
27904 KB |
Output is correct |
10 |
Correct |
24 ms |
27904 KB |
Output is correct |
11 |
Correct |
23 ms |
27904 KB |
Output is correct |
12 |
Correct |
22 ms |
27904 KB |
Output is correct |
13 |
Correct |
22 ms |
27904 KB |
Output is correct |
14 |
Correct |
23 ms |
27904 KB |
Output is correct |
15 |
Correct |
23 ms |
27904 KB |
Output is correct |
16 |
Correct |
22 ms |
28032 KB |
Output is correct |
17 |
Correct |
22 ms |
27904 KB |
Output is correct |
18 |
Correct |
22 ms |
27904 KB |
Output is correct |
19 |
Correct |
22 ms |
27904 KB |
Output is correct |
20 |
Correct |
22 ms |
27904 KB |
Output is correct |
21 |
Correct |
22 ms |
28032 KB |
Output is correct |
22 |
Correct |
22 ms |
27904 KB |
Output is correct |
23 |
Correct |
22 ms |
27904 KB |
Output is correct |
24 |
Correct |
22 ms |
28032 KB |
Output is correct |
25 |
Correct |
23 ms |
27904 KB |
Output is correct |
26 |
Correct |
23 ms |
27904 KB |
Output is correct |
27 |
Correct |
21 ms |
27904 KB |
Output is correct |
28 |
Correct |
23 ms |
27904 KB |
Output is correct |
29 |
Correct |
22 ms |
27904 KB |
Output is correct |
30 |
Correct |
24 ms |
27904 KB |
Output is correct |
31 |
Correct |
350 ms |
36116 KB |
Output is correct |
32 |
Correct |
202 ms |
35036 KB |
Output is correct |
33 |
Correct |
370 ms |
35640 KB |
Output is correct |
34 |
Correct |
340 ms |
36064 KB |
Output is correct |
35 |
Correct |
358 ms |
35528 KB |
Output is correct |
36 |
Correct |
372 ms |
35556 KB |
Output is correct |
37 |
Correct |
324 ms |
35424 KB |
Output is correct |
38 |
Correct |
345 ms |
35288 KB |
Output is correct |
39 |
Correct |
292 ms |
35200 KB |
Output is correct |
40 |
Correct |
301 ms |
35104 KB |
Output is correct |
41 |
Correct |
298 ms |
35428 KB |
Output is correct |
42 |
Correct |
295 ms |
35560 KB |
Output is correct |
43 |
Correct |
159 ms |
36072 KB |
Output is correct |
44 |
Correct |
289 ms |
35712 KB |
Output is correct |
45 |
Correct |
283 ms |
35572 KB |
Output is correct |
46 |
Correct |
265 ms |
35552 KB |
Output is correct |
47 |
Correct |
224 ms |
35044 KB |
Output is correct |
48 |
Correct |
222 ms |
35032 KB |
Output is correct |
49 |
Correct |
249 ms |
35300 KB |
Output is correct |
50 |
Correct |
270 ms |
35808 KB |
Output is correct |
51 |
Correct |
244 ms |
35428 KB |
Output is correct |
52 |
Correct |
1111 ms |
76992 KB |
Output is correct |
53 |
Incorrect |
1114 ms |
89284 KB |
Output isn't correct |
54 |
Halted |
0 ms |
0 KB |
- |