//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#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 solve(){
int n,q,k;
cin>>n>>k>>q;
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;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
356 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
460 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
3 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
3 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
408 KB |
Output is correct |
22 |
Correct |
3 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
356 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
460 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
3 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
3 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
408 KB |
Output is correct |
22 |
Correct |
3 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
3684 ms |
8396 KB |
Output is correct |
32 |
Correct |
146 ms |
5632 KB |
Output is correct |
33 |
Correct |
275 ms |
7664 KB |
Output is correct |
34 |
Correct |
2471 ms |
7760 KB |
Output is correct |
35 |
Correct |
1483 ms |
9548 KB |
Output is correct |
36 |
Correct |
279 ms |
9328 KB |
Output is correct |
37 |
Correct |
263 ms |
6848 KB |
Output is correct |
38 |
Correct |
148 ms |
6744 KB |
Output is correct |
39 |
Correct |
113 ms |
6684 KB |
Output is correct |
40 |
Correct |
137 ms |
6728 KB |
Output is correct |
41 |
Correct |
357 ms |
6976 KB |
Output is correct |
42 |
Correct |
516 ms |
6844 KB |
Output is correct |
43 |
Correct |
1860 ms |
8988 KB |
Output is correct |
44 |
Correct |
309 ms |
6960 KB |
Output is correct |
45 |
Correct |
140 ms |
6948 KB |
Output is correct |
46 |
Correct |
92 ms |
6896 KB |
Output is correct |
47 |
Correct |
244 ms |
6672 KB |
Output is correct |
48 |
Correct |
98 ms |
6716 KB |
Output is correct |
49 |
Correct |
111 ms |
6620 KB |
Output is correct |
50 |
Correct |
281 ms |
6696 KB |
Output is correct |
51 |
Correct |
104 ms |
6660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
363 ms |
35804 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
386 ms |
35884 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
356 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
460 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
3 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
3 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
408 KB |
Output is correct |
22 |
Correct |
3 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
3684 ms |
8396 KB |
Output is correct |
32 |
Correct |
146 ms |
5632 KB |
Output is correct |
33 |
Correct |
275 ms |
7664 KB |
Output is correct |
34 |
Correct |
2471 ms |
7760 KB |
Output is correct |
35 |
Correct |
1483 ms |
9548 KB |
Output is correct |
36 |
Correct |
279 ms |
9328 KB |
Output is correct |
37 |
Correct |
263 ms |
6848 KB |
Output is correct |
38 |
Correct |
148 ms |
6744 KB |
Output is correct |
39 |
Correct |
113 ms |
6684 KB |
Output is correct |
40 |
Correct |
137 ms |
6728 KB |
Output is correct |
41 |
Correct |
357 ms |
6976 KB |
Output is correct |
42 |
Correct |
516 ms |
6844 KB |
Output is correct |
43 |
Correct |
1860 ms |
8988 KB |
Output is correct |
44 |
Correct |
309 ms |
6960 KB |
Output is correct |
45 |
Correct |
140 ms |
6948 KB |
Output is correct |
46 |
Correct |
92 ms |
6896 KB |
Output is correct |
47 |
Correct |
244 ms |
6672 KB |
Output is correct |
48 |
Correct |
98 ms |
6716 KB |
Output is correct |
49 |
Correct |
111 ms |
6620 KB |
Output is correct |
50 |
Correct |
281 ms |
6696 KB |
Output is correct |
51 |
Correct |
104 ms |
6660 KB |
Output is correct |
52 |
Runtime error |
95 ms |
9516 KB |
Execution killed with signal 11 |
53 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
356 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
460 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
3 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
3 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
408 KB |
Output is correct |
22 |
Correct |
3 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
3684 ms |
8396 KB |
Output is correct |
32 |
Correct |
146 ms |
5632 KB |
Output is correct |
33 |
Correct |
275 ms |
7664 KB |
Output is correct |
34 |
Correct |
2471 ms |
7760 KB |
Output is correct |
35 |
Correct |
1483 ms |
9548 KB |
Output is correct |
36 |
Correct |
279 ms |
9328 KB |
Output is correct |
37 |
Correct |
263 ms |
6848 KB |
Output is correct |
38 |
Correct |
148 ms |
6744 KB |
Output is correct |
39 |
Correct |
113 ms |
6684 KB |
Output is correct |
40 |
Correct |
137 ms |
6728 KB |
Output is correct |
41 |
Correct |
357 ms |
6976 KB |
Output is correct |
42 |
Correct |
516 ms |
6844 KB |
Output is correct |
43 |
Correct |
1860 ms |
8988 KB |
Output is correct |
44 |
Correct |
309 ms |
6960 KB |
Output is correct |
45 |
Correct |
140 ms |
6948 KB |
Output is correct |
46 |
Correct |
92 ms |
6896 KB |
Output is correct |
47 |
Correct |
244 ms |
6672 KB |
Output is correct |
48 |
Correct |
98 ms |
6716 KB |
Output is correct |
49 |
Correct |
111 ms |
6620 KB |
Output is correct |
50 |
Correct |
281 ms |
6696 KB |
Output is correct |
51 |
Correct |
104 ms |
6660 KB |
Output is correct |
52 |
Runtime error |
363 ms |
35804 KB |
Execution killed with signal 11 |
53 |
Halted |
0 ms |
0 KB |
- |