//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<pair<int,int>,null_type,less<pair<int,int> >,rb_tree_tag,tree_order_statistics_node_update> super_set;
#define endl '\n'
const int DIM = 3E5+7;
const int SZ = 407;
const int INF = 1E9+7;
set<pair<int,int> > K[SZ];
struct node{
int t,x,type,pos;
};
bool mc(node &a,node &b){
if (a.t==b.t)
return (a.type==0)<(b.type==0);
return a.t<b.t;
}
int ans[DIM];
int n,q,k;
int solve(){
vector<node> events;
for(int i = 1;i<=n;++i){
int x,t,l,r;
cin>>x>>t>>l>>r;
events.push_back({l,x,t,i});
events.push_back({r+1,x,t,-i});
}
for(int i = 1;i<=q;++i){
int x,t;
cin>>x>>t;
events.push_back({t,x,0,i});
}
sort(events.begin(),events.end(),mc);
for(auto to:events){
if (to.type==0){
int dist = 0;
for(int i = 1;i<=k;++i){
int d = INF;
auto lb = K[i].lower_bound({to.x,INF});
if (lb!=K[i].begin()){
lb = prev(lb);
d = min(d,to.x-lb->first);
}
auto rb = K[i].lower_bound({to.x,0});
if (rb!=K[i].end()){
d = min(d,rb->first-to.x);
}
dist = max(dist,d);
}
if (dist==INF)
ans[to.pos] = -1;
else ans[to.pos] = dist;
}
else{
if (to.pos<0)
K[to.type].erase({to.x,-to.pos});
else K[to.type].insert({to.x,to.pos});
}
}
for(int i = 1;i<=q;++i)
cout<<ans[i]<<endl;
return 1;
}
vector<int> V[DIM];
super_set S;
int get(int l,int r){
return S.order_of_key({r,INF})-S.order_of_key({l-1,INF});
}
int solve1(){
for(int i = 1;i<=n;++i){
int x,t,a,b;
cin>>x>>t>>a>>b;
V[t].push_back(x);
}
vector<node> events;
for(int i = 1;i<=k;++i){
sort(V[i].begin(),V[i].end());
for(int j = 0;j<V[i].size();++j){
int prev = j==0?-INF:V[i][j-1],next = j==V[i].size()-1?INF:V[i][j+1];
int l = max(0,(V[i][j]+prev)/2);
int r = min(int(1E9),(V[i][j]+next)/2);
events.push_back({l,V[i][j],i,0});
events.push_back({r,V[i][j],-i,0});
}
}
for(int i = 1;i<=q;++i){
int x,t;
cin>>x>>t;
events.push_back({t,x,0,i});
}
sort(events.begin(),events.end(),mc);
for(auto to:events){
if (to.type==0){
int l = 0,r = 1E9;
while(l!=r){
int tm = (l+r)/2;
if (get(to.x-tm,to.x+tm)==k)
r = tm;
else l = tm+1;
}
if (l==1E9)
ans[to.pos] = -1;
else ans[to.pos] = l;
}
else{
if (to.type<0)
S.erase({to.x,-to.type});
else S.insert({to.x,to.type});
}
}
for(int i = 1;i<=q;++i)
cout<<ans[i]<<endl;
return 1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>k>>q;
if (k<=400)
solve();
else
solve1();
return 0;
}
Compilation message
new_home.cpp: In function 'int solve1()':
new_home.cpp:84:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for(int j = 0;j<V[i].size();++j){
| ~^~~~~~~~~~~~
new_home.cpp:85:52: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | int prev = j==0?-INF:V[i][j-1],next = j==V[i].size()-1?INF:V[i][j+1];
| ~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7384 KB |
Output is correct |
2 |
Correct |
6 ms |
7372 KB |
Output is correct |
3 |
Correct |
5 ms |
7372 KB |
Output is correct |
4 |
Correct |
5 ms |
7372 KB |
Output is correct |
5 |
Correct |
6 ms |
7412 KB |
Output is correct |
6 |
Correct |
7 ms |
7372 KB |
Output is correct |
7 |
Correct |
7 ms |
7436 KB |
Output is correct |
8 |
Correct |
6 ms |
7372 KB |
Output is correct |
9 |
Correct |
7 ms |
7372 KB |
Output is correct |
10 |
Correct |
6 ms |
7372 KB |
Output is correct |
11 |
Correct |
6 ms |
7372 KB |
Output is correct |
12 |
Correct |
6 ms |
7372 KB |
Output is correct |
13 |
Correct |
6 ms |
7372 KB |
Output is correct |
14 |
Correct |
7 ms |
7372 KB |
Output is correct |
15 |
Correct |
8 ms |
7372 KB |
Output is correct |
16 |
Correct |
7 ms |
7372 KB |
Output is correct |
17 |
Correct |
6 ms |
7372 KB |
Output is correct |
18 |
Correct |
6 ms |
7372 KB |
Output is correct |
19 |
Correct |
6 ms |
7372 KB |
Output is correct |
20 |
Correct |
6 ms |
7372 KB |
Output is correct |
21 |
Correct |
7 ms |
7372 KB |
Output is correct |
22 |
Correct |
7 ms |
7372 KB |
Output is correct |
23 |
Correct |
8 ms |
7332 KB |
Output is correct |
24 |
Correct |
7 ms |
7372 KB |
Output is correct |
25 |
Correct |
6 ms |
7372 KB |
Output is correct |
26 |
Correct |
6 ms |
7372 KB |
Output is correct |
27 |
Correct |
6 ms |
7372 KB |
Output is correct |
28 |
Correct |
6 ms |
7444 KB |
Output is correct |
29 |
Correct |
6 ms |
7372 KB |
Output is correct |
30 |
Correct |
6 ms |
7372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7384 KB |
Output is correct |
2 |
Correct |
6 ms |
7372 KB |
Output is correct |
3 |
Correct |
5 ms |
7372 KB |
Output is correct |
4 |
Correct |
5 ms |
7372 KB |
Output is correct |
5 |
Correct |
6 ms |
7412 KB |
Output is correct |
6 |
Correct |
7 ms |
7372 KB |
Output is correct |
7 |
Correct |
7 ms |
7436 KB |
Output is correct |
8 |
Correct |
6 ms |
7372 KB |
Output is correct |
9 |
Correct |
7 ms |
7372 KB |
Output is correct |
10 |
Correct |
6 ms |
7372 KB |
Output is correct |
11 |
Correct |
6 ms |
7372 KB |
Output is correct |
12 |
Correct |
6 ms |
7372 KB |
Output is correct |
13 |
Correct |
6 ms |
7372 KB |
Output is correct |
14 |
Correct |
7 ms |
7372 KB |
Output is correct |
15 |
Correct |
8 ms |
7372 KB |
Output is correct |
16 |
Correct |
7 ms |
7372 KB |
Output is correct |
17 |
Correct |
6 ms |
7372 KB |
Output is correct |
18 |
Correct |
6 ms |
7372 KB |
Output is correct |
19 |
Correct |
6 ms |
7372 KB |
Output is correct |
20 |
Correct |
6 ms |
7372 KB |
Output is correct |
21 |
Correct |
7 ms |
7372 KB |
Output is correct |
22 |
Correct |
7 ms |
7372 KB |
Output is correct |
23 |
Correct |
8 ms |
7332 KB |
Output is correct |
24 |
Correct |
7 ms |
7372 KB |
Output is correct |
25 |
Correct |
6 ms |
7372 KB |
Output is correct |
26 |
Correct |
6 ms |
7372 KB |
Output is correct |
27 |
Correct |
6 ms |
7372 KB |
Output is correct |
28 |
Correct |
6 ms |
7444 KB |
Output is correct |
29 |
Correct |
6 ms |
7372 KB |
Output is correct |
30 |
Correct |
6 ms |
7372 KB |
Output is correct |
31 |
Correct |
3303 ms |
13684 KB |
Output is correct |
32 |
Correct |
127 ms |
11632 KB |
Output is correct |
33 |
Correct |
261 ms |
11808 KB |
Output is correct |
34 |
Correct |
2540 ms |
11856 KB |
Output is correct |
35 |
Correct |
1489 ms |
13636 KB |
Output is correct |
36 |
Correct |
290 ms |
13660 KB |
Output is correct |
37 |
Correct |
234 ms |
11576 KB |
Output is correct |
38 |
Correct |
127 ms |
11580 KB |
Output is correct |
39 |
Correct |
114 ms |
11620 KB |
Output is correct |
40 |
Correct |
125 ms |
11568 KB |
Output is correct |
41 |
Correct |
346 ms |
11576 KB |
Output is correct |
42 |
Correct |
464 ms |
11504 KB |
Output is correct |
43 |
Correct |
1785 ms |
13792 KB |
Output is correct |
44 |
Correct |
294 ms |
11524 KB |
Output is correct |
45 |
Correct |
188 ms |
11580 KB |
Output is correct |
46 |
Correct |
96 ms |
11580 KB |
Output is correct |
47 |
Correct |
84 ms |
11592 KB |
Output is correct |
48 |
Correct |
82 ms |
11532 KB |
Output is correct |
49 |
Correct |
102 ms |
11556 KB |
Output is correct |
50 |
Correct |
268 ms |
11776 KB |
Output is correct |
51 |
Correct |
95 ms |
11576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1706 ms |
31940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1275 ms |
27420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7384 KB |
Output is correct |
2 |
Correct |
6 ms |
7372 KB |
Output is correct |
3 |
Correct |
5 ms |
7372 KB |
Output is correct |
4 |
Correct |
5 ms |
7372 KB |
Output is correct |
5 |
Correct |
6 ms |
7412 KB |
Output is correct |
6 |
Correct |
7 ms |
7372 KB |
Output is correct |
7 |
Correct |
7 ms |
7436 KB |
Output is correct |
8 |
Correct |
6 ms |
7372 KB |
Output is correct |
9 |
Correct |
7 ms |
7372 KB |
Output is correct |
10 |
Correct |
6 ms |
7372 KB |
Output is correct |
11 |
Correct |
6 ms |
7372 KB |
Output is correct |
12 |
Correct |
6 ms |
7372 KB |
Output is correct |
13 |
Correct |
6 ms |
7372 KB |
Output is correct |
14 |
Correct |
7 ms |
7372 KB |
Output is correct |
15 |
Correct |
8 ms |
7372 KB |
Output is correct |
16 |
Correct |
7 ms |
7372 KB |
Output is correct |
17 |
Correct |
6 ms |
7372 KB |
Output is correct |
18 |
Correct |
6 ms |
7372 KB |
Output is correct |
19 |
Correct |
6 ms |
7372 KB |
Output is correct |
20 |
Correct |
6 ms |
7372 KB |
Output is correct |
21 |
Correct |
7 ms |
7372 KB |
Output is correct |
22 |
Correct |
7 ms |
7372 KB |
Output is correct |
23 |
Correct |
8 ms |
7332 KB |
Output is correct |
24 |
Correct |
7 ms |
7372 KB |
Output is correct |
25 |
Correct |
6 ms |
7372 KB |
Output is correct |
26 |
Correct |
6 ms |
7372 KB |
Output is correct |
27 |
Correct |
6 ms |
7372 KB |
Output is correct |
28 |
Correct |
6 ms |
7444 KB |
Output is correct |
29 |
Correct |
6 ms |
7372 KB |
Output is correct |
30 |
Correct |
6 ms |
7372 KB |
Output is correct |
31 |
Correct |
3303 ms |
13684 KB |
Output is correct |
32 |
Correct |
127 ms |
11632 KB |
Output is correct |
33 |
Correct |
261 ms |
11808 KB |
Output is correct |
34 |
Correct |
2540 ms |
11856 KB |
Output is correct |
35 |
Correct |
1489 ms |
13636 KB |
Output is correct |
36 |
Correct |
290 ms |
13660 KB |
Output is correct |
37 |
Correct |
234 ms |
11576 KB |
Output is correct |
38 |
Correct |
127 ms |
11580 KB |
Output is correct |
39 |
Correct |
114 ms |
11620 KB |
Output is correct |
40 |
Correct |
125 ms |
11568 KB |
Output is correct |
41 |
Correct |
346 ms |
11576 KB |
Output is correct |
42 |
Correct |
464 ms |
11504 KB |
Output is correct |
43 |
Correct |
1785 ms |
13792 KB |
Output is correct |
44 |
Correct |
294 ms |
11524 KB |
Output is correct |
45 |
Correct |
188 ms |
11580 KB |
Output is correct |
46 |
Correct |
96 ms |
11580 KB |
Output is correct |
47 |
Correct |
84 ms |
11592 KB |
Output is correct |
48 |
Correct |
82 ms |
11532 KB |
Output is correct |
49 |
Correct |
102 ms |
11556 KB |
Output is correct |
50 |
Correct |
268 ms |
11776 KB |
Output is correct |
51 |
Correct |
95 ms |
11576 KB |
Output is correct |
52 |
Incorrect |
311 ms |
16660 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7384 KB |
Output is correct |
2 |
Correct |
6 ms |
7372 KB |
Output is correct |
3 |
Correct |
5 ms |
7372 KB |
Output is correct |
4 |
Correct |
5 ms |
7372 KB |
Output is correct |
5 |
Correct |
6 ms |
7412 KB |
Output is correct |
6 |
Correct |
7 ms |
7372 KB |
Output is correct |
7 |
Correct |
7 ms |
7436 KB |
Output is correct |
8 |
Correct |
6 ms |
7372 KB |
Output is correct |
9 |
Correct |
7 ms |
7372 KB |
Output is correct |
10 |
Correct |
6 ms |
7372 KB |
Output is correct |
11 |
Correct |
6 ms |
7372 KB |
Output is correct |
12 |
Correct |
6 ms |
7372 KB |
Output is correct |
13 |
Correct |
6 ms |
7372 KB |
Output is correct |
14 |
Correct |
7 ms |
7372 KB |
Output is correct |
15 |
Correct |
8 ms |
7372 KB |
Output is correct |
16 |
Correct |
7 ms |
7372 KB |
Output is correct |
17 |
Correct |
6 ms |
7372 KB |
Output is correct |
18 |
Correct |
6 ms |
7372 KB |
Output is correct |
19 |
Correct |
6 ms |
7372 KB |
Output is correct |
20 |
Correct |
6 ms |
7372 KB |
Output is correct |
21 |
Correct |
7 ms |
7372 KB |
Output is correct |
22 |
Correct |
7 ms |
7372 KB |
Output is correct |
23 |
Correct |
8 ms |
7332 KB |
Output is correct |
24 |
Correct |
7 ms |
7372 KB |
Output is correct |
25 |
Correct |
6 ms |
7372 KB |
Output is correct |
26 |
Correct |
6 ms |
7372 KB |
Output is correct |
27 |
Correct |
6 ms |
7372 KB |
Output is correct |
28 |
Correct |
6 ms |
7444 KB |
Output is correct |
29 |
Correct |
6 ms |
7372 KB |
Output is correct |
30 |
Correct |
6 ms |
7372 KB |
Output is correct |
31 |
Correct |
3303 ms |
13684 KB |
Output is correct |
32 |
Correct |
127 ms |
11632 KB |
Output is correct |
33 |
Correct |
261 ms |
11808 KB |
Output is correct |
34 |
Correct |
2540 ms |
11856 KB |
Output is correct |
35 |
Correct |
1489 ms |
13636 KB |
Output is correct |
36 |
Correct |
290 ms |
13660 KB |
Output is correct |
37 |
Correct |
234 ms |
11576 KB |
Output is correct |
38 |
Correct |
127 ms |
11580 KB |
Output is correct |
39 |
Correct |
114 ms |
11620 KB |
Output is correct |
40 |
Correct |
125 ms |
11568 KB |
Output is correct |
41 |
Correct |
346 ms |
11576 KB |
Output is correct |
42 |
Correct |
464 ms |
11504 KB |
Output is correct |
43 |
Correct |
1785 ms |
13792 KB |
Output is correct |
44 |
Correct |
294 ms |
11524 KB |
Output is correct |
45 |
Correct |
188 ms |
11580 KB |
Output is correct |
46 |
Correct |
96 ms |
11580 KB |
Output is correct |
47 |
Correct |
84 ms |
11592 KB |
Output is correct |
48 |
Correct |
82 ms |
11532 KB |
Output is correct |
49 |
Correct |
102 ms |
11556 KB |
Output is correct |
50 |
Correct |
268 ms |
11776 KB |
Output is correct |
51 |
Correct |
95 ms |
11576 KB |
Output is correct |
52 |
Incorrect |
1706 ms |
31940 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |