#include <bits/stdc++.h>
using namespace std;
#define int long long
priority_queue<int> bruh[300005],del[300005];
int cnum;
struct node{
int s,e,m;
int val,pnum;
node *l, *r;
node(int S, int E){
s=S; e=E; m=(s+e)/2;
val=0;
l=r=NULL;
if(s==e){
pnum=cnum;
cnum++;
}
}
void update(int S, int V, int R){
if(s==e){
if(R!=-1) del[pnum].push(R);
if(V!=-1) bruh[pnum].push(V);
while(!del[pnum].empty()&&!bruh[pnum].empty()&&bruh[pnum].top()==del[pnum].top()){
bruh[pnum].pop();
del[pnum].pop();
}
if(!bruh[pnum].empty()) val=bruh[pnum].top();
else val=0;
return;
}
if(S<=m){
if(!l) l=new node(s,m);
l->update(S,V,R);
}
else{
if(!r) r=new node(m+1,e);
r->update(S,V,R);
}
val=max((l?l->val:0),(r?r->val:0));
}
int query(int S){
if(s==e) return val;
if(S<=m) return (l?l->query(S):0);
else return max((l?l->val:0),(r?r->query(S):0));
}
} *root;
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,q,k;
cin >> n >> k >> q;
vector<pair<pair<int,int>,pair<int,int> > > up; //time,loc,type,+-1
for(int i=0; i<n; i++){
int a,b,c,d;
cin >> a >> b >> c >> d;
up.push_back({{c,a},{b,1}});
up.push_back({{d+1,a},{b,-1}});
}
sort(up.begin(),up.end());
root=new node(0,1e8+5);
pair<pair<int,int>,int> qu[q]; //time,loc,index
for(int i=0; i<q; i++){
int a,b;
cin >> a >> b;
qu[i]={{b,a},i};
}
sort(qu,qu+q);
multiset<int> occ[k+1];
multiset<int>::iterator it;
for(int i=1; i<=k; i++){
occ[i].insert(0);
occ[i].insert(1e16);
root->update(0,1e16,-1);
}
int ans[q],cnt=0;
for(int i=0; i<q; i++){
while(cnt<(int)up.size()&&up[cnt].first.first<=qu[i].first.first){
if(up[cnt].second.second==1){
int t=up[cnt].second.first,p=up[cnt].first.second;
it=occ[t].upper_bound(p);
int nxt=*it;
it--;
int prv=*it;
root->update(prv,p,nxt);
root->update(p,nxt,-1);
occ[t].insert(p);
}
else{
int t=up[cnt].second.first,p=up[cnt].first.second;
occ[t].erase(occ[t].find(p));
it=occ[t].upper_bound(p);
int nxt=*it;
it--;
int prv=*it;
root->update(prv,nxt,p);
root->update(p,-1,nxt);
}
cnt++;
}
int loc=qu[i].first.second;
if(root->query(0)==1e16){
ans[qu[i].second]=-1;
continue;
}
int lo=0,hi=1e8,mid;
while(lo<hi){
mid=(lo+hi)/2;
int big=root->query(max(loc-mid-1,0ll));
if(big<=loc+mid) assert(big>=loc-mid),hi=mid;
else lo=mid+1;
}
ans[qu[i].second]=lo;
}
for(int i=0; i<q; i++) cout << ans[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
19032 KB |
Output is correct |
2 |
Correct |
6 ms |
19036 KB |
Output is correct |
3 |
Correct |
4 ms |
19032 KB |
Output is correct |
4 |
Correct |
4 ms |
19036 KB |
Output is correct |
5 |
Correct |
5 ms |
19292 KB |
Output is correct |
6 |
Correct |
7 ms |
19804 KB |
Output is correct |
7 |
Correct |
6 ms |
19804 KB |
Output is correct |
8 |
Correct |
7 ms |
19804 KB |
Output is correct |
9 |
Correct |
5 ms |
19904 KB |
Output is correct |
10 |
Correct |
6 ms |
19804 KB |
Output is correct |
11 |
Correct |
5 ms |
19616 KB |
Output is correct |
12 |
Correct |
6 ms |
19804 KB |
Output is correct |
13 |
Correct |
6 ms |
19804 KB |
Output is correct |
14 |
Correct |
6 ms |
19804 KB |
Output is correct |
15 |
Correct |
7 ms |
19804 KB |
Output is correct |
16 |
Correct |
6 ms |
20056 KB |
Output is correct |
17 |
Correct |
7 ms |
19648 KB |
Output is correct |
18 |
Correct |
6 ms |
19804 KB |
Output is correct |
19 |
Correct |
7 ms |
19804 KB |
Output is correct |
20 |
Correct |
7 ms |
19804 KB |
Output is correct |
21 |
Correct |
5 ms |
19288 KB |
Output is correct |
22 |
Correct |
6 ms |
19800 KB |
Output is correct |
23 |
Correct |
7 ms |
19888 KB |
Output is correct |
24 |
Correct |
6 ms |
19804 KB |
Output is correct |
25 |
Correct |
6 ms |
19804 KB |
Output is correct |
26 |
Correct |
6 ms |
19724 KB |
Output is correct |
27 |
Correct |
7 ms |
19252 KB |
Output is correct |
28 |
Correct |
6 ms |
19804 KB |
Output is correct |
29 |
Correct |
6 ms |
19804 KB |
Output is correct |
30 |
Correct |
6 ms |
19544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
19032 KB |
Output is correct |
2 |
Correct |
6 ms |
19036 KB |
Output is correct |
3 |
Correct |
4 ms |
19032 KB |
Output is correct |
4 |
Correct |
4 ms |
19036 KB |
Output is correct |
5 |
Correct |
5 ms |
19292 KB |
Output is correct |
6 |
Correct |
7 ms |
19804 KB |
Output is correct |
7 |
Correct |
6 ms |
19804 KB |
Output is correct |
8 |
Correct |
7 ms |
19804 KB |
Output is correct |
9 |
Correct |
5 ms |
19904 KB |
Output is correct |
10 |
Correct |
6 ms |
19804 KB |
Output is correct |
11 |
Correct |
5 ms |
19616 KB |
Output is correct |
12 |
Correct |
6 ms |
19804 KB |
Output is correct |
13 |
Correct |
6 ms |
19804 KB |
Output is correct |
14 |
Correct |
6 ms |
19804 KB |
Output is correct |
15 |
Correct |
7 ms |
19804 KB |
Output is correct |
16 |
Correct |
6 ms |
20056 KB |
Output is correct |
17 |
Correct |
7 ms |
19648 KB |
Output is correct |
18 |
Correct |
6 ms |
19804 KB |
Output is correct |
19 |
Correct |
7 ms |
19804 KB |
Output is correct |
20 |
Correct |
7 ms |
19804 KB |
Output is correct |
21 |
Correct |
5 ms |
19288 KB |
Output is correct |
22 |
Correct |
6 ms |
19800 KB |
Output is correct |
23 |
Correct |
7 ms |
19888 KB |
Output is correct |
24 |
Correct |
6 ms |
19804 KB |
Output is correct |
25 |
Correct |
6 ms |
19804 KB |
Output is correct |
26 |
Correct |
6 ms |
19724 KB |
Output is correct |
27 |
Correct |
7 ms |
19252 KB |
Output is correct |
28 |
Correct |
6 ms |
19804 KB |
Output is correct |
29 |
Correct |
6 ms |
19804 KB |
Output is correct |
30 |
Correct |
6 ms |
19544 KB |
Output is correct |
31 |
Correct |
635 ms |
79300 KB |
Output is correct |
32 |
Correct |
152 ms |
28076 KB |
Output is correct |
33 |
Correct |
595 ms |
77552 KB |
Output is correct |
34 |
Correct |
513 ms |
77756 KB |
Output is correct |
35 |
Correct |
655 ms |
79036 KB |
Output is correct |
36 |
Correct |
661 ms |
79040 KB |
Output is correct |
37 |
Correct |
419 ms |
77544 KB |
Output is correct |
38 |
Correct |
426 ms |
77248 KB |
Output is correct |
39 |
Correct |
358 ms |
77188 KB |
Output is correct |
40 |
Correct |
355 ms |
77240 KB |
Output is correct |
41 |
Correct |
315 ms |
77632 KB |
Output is correct |
42 |
Correct |
276 ms |
77796 KB |
Output is correct |
43 |
Correct |
122 ms |
31020 KB |
Output is correct |
44 |
Correct |
315 ms |
78076 KB |
Output is correct |
45 |
Correct |
328 ms |
77692 KB |
Output is correct |
46 |
Correct |
345 ms |
77248 KB |
Output is correct |
47 |
Correct |
246 ms |
75248 KB |
Output is correct |
48 |
Correct |
263 ms |
74432 KB |
Output is correct |
49 |
Correct |
280 ms |
75864 KB |
Output is correct |
50 |
Correct |
265 ms |
77220 KB |
Output is correct |
51 |
Correct |
308 ms |
75496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1919 ms |
285204 KB |
Output is correct |
2 |
Correct |
3422 ms |
274720 KB |
Output is correct |
3 |
Correct |
1422 ms |
312292 KB |
Output is correct |
4 |
Correct |
1714 ms |
289380 KB |
Output is correct |
5 |
Correct |
3424 ms |
275276 KB |
Output is correct |
6 |
Correct |
3391 ms |
275052 KB |
Output is correct |
7 |
Correct |
1454 ms |
313612 KB |
Output is correct |
8 |
Correct |
1787 ms |
289648 KB |
Output is correct |
9 |
Correct |
2220 ms |
280860 KB |
Output is correct |
10 |
Correct |
3523 ms |
275620 KB |
Output is correct |
11 |
Correct |
1731 ms |
271536 KB |
Output is correct |
12 |
Correct |
2013 ms |
275096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4100 ms |
277632 KB |
Output is correct |
2 |
Correct |
749 ms |
71868 KB |
Output is correct |
3 |
Execution timed out |
5055 ms |
273356 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
19032 KB |
Output is correct |
2 |
Correct |
6 ms |
19036 KB |
Output is correct |
3 |
Correct |
4 ms |
19032 KB |
Output is correct |
4 |
Correct |
4 ms |
19036 KB |
Output is correct |
5 |
Correct |
5 ms |
19292 KB |
Output is correct |
6 |
Correct |
7 ms |
19804 KB |
Output is correct |
7 |
Correct |
6 ms |
19804 KB |
Output is correct |
8 |
Correct |
7 ms |
19804 KB |
Output is correct |
9 |
Correct |
5 ms |
19904 KB |
Output is correct |
10 |
Correct |
6 ms |
19804 KB |
Output is correct |
11 |
Correct |
5 ms |
19616 KB |
Output is correct |
12 |
Correct |
6 ms |
19804 KB |
Output is correct |
13 |
Correct |
6 ms |
19804 KB |
Output is correct |
14 |
Correct |
6 ms |
19804 KB |
Output is correct |
15 |
Correct |
7 ms |
19804 KB |
Output is correct |
16 |
Correct |
6 ms |
20056 KB |
Output is correct |
17 |
Correct |
7 ms |
19648 KB |
Output is correct |
18 |
Correct |
6 ms |
19804 KB |
Output is correct |
19 |
Correct |
7 ms |
19804 KB |
Output is correct |
20 |
Correct |
7 ms |
19804 KB |
Output is correct |
21 |
Correct |
5 ms |
19288 KB |
Output is correct |
22 |
Correct |
6 ms |
19800 KB |
Output is correct |
23 |
Correct |
7 ms |
19888 KB |
Output is correct |
24 |
Correct |
6 ms |
19804 KB |
Output is correct |
25 |
Correct |
6 ms |
19804 KB |
Output is correct |
26 |
Correct |
6 ms |
19724 KB |
Output is correct |
27 |
Correct |
7 ms |
19252 KB |
Output is correct |
28 |
Correct |
6 ms |
19804 KB |
Output is correct |
29 |
Correct |
6 ms |
19804 KB |
Output is correct |
30 |
Correct |
6 ms |
19544 KB |
Output is correct |
31 |
Correct |
635 ms |
79300 KB |
Output is correct |
32 |
Correct |
152 ms |
28076 KB |
Output is correct |
33 |
Correct |
595 ms |
77552 KB |
Output is correct |
34 |
Correct |
513 ms |
77756 KB |
Output is correct |
35 |
Correct |
655 ms |
79036 KB |
Output is correct |
36 |
Correct |
661 ms |
79040 KB |
Output is correct |
37 |
Correct |
419 ms |
77544 KB |
Output is correct |
38 |
Correct |
426 ms |
77248 KB |
Output is correct |
39 |
Correct |
358 ms |
77188 KB |
Output is correct |
40 |
Correct |
355 ms |
77240 KB |
Output is correct |
41 |
Correct |
315 ms |
77632 KB |
Output is correct |
42 |
Correct |
276 ms |
77796 KB |
Output is correct |
43 |
Correct |
122 ms |
31020 KB |
Output is correct |
44 |
Correct |
315 ms |
78076 KB |
Output is correct |
45 |
Correct |
328 ms |
77692 KB |
Output is correct |
46 |
Correct |
345 ms |
77248 KB |
Output is correct |
47 |
Correct |
246 ms |
75248 KB |
Output is correct |
48 |
Correct |
263 ms |
74432 KB |
Output is correct |
49 |
Correct |
280 ms |
75864 KB |
Output is correct |
50 |
Correct |
265 ms |
77220 KB |
Output is correct |
51 |
Correct |
308 ms |
75496 KB |
Output is correct |
52 |
Correct |
309 ms |
88176 KB |
Output is correct |
53 |
Correct |
276 ms |
86688 KB |
Output is correct |
54 |
Correct |
353 ms |
82876 KB |
Output is correct |
55 |
Correct |
340 ms |
81468 KB |
Output is correct |
56 |
Correct |
338 ms |
82416 KB |
Output is correct |
57 |
Correct |
322 ms |
78780 KB |
Output is correct |
58 |
Correct |
292 ms |
80576 KB |
Output is correct |
59 |
Correct |
316 ms |
81372 KB |
Output is correct |
60 |
Correct |
292 ms |
78816 KB |
Output is correct |
61 |
Correct |
135 ms |
39964 KB |
Output is correct |
62 |
Correct |
323 ms |
88372 KB |
Output is correct |
63 |
Correct |
337 ms |
84160 KB |
Output is correct |
64 |
Correct |
375 ms |
82288 KB |
Output is correct |
65 |
Correct |
384 ms |
79184 KB |
Output is correct |
66 |
Correct |
316 ms |
77896 KB |
Output is correct |
67 |
Correct |
142 ms |
30660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
19032 KB |
Output is correct |
2 |
Correct |
6 ms |
19036 KB |
Output is correct |
3 |
Correct |
4 ms |
19032 KB |
Output is correct |
4 |
Correct |
4 ms |
19036 KB |
Output is correct |
5 |
Correct |
5 ms |
19292 KB |
Output is correct |
6 |
Correct |
7 ms |
19804 KB |
Output is correct |
7 |
Correct |
6 ms |
19804 KB |
Output is correct |
8 |
Correct |
7 ms |
19804 KB |
Output is correct |
9 |
Correct |
5 ms |
19904 KB |
Output is correct |
10 |
Correct |
6 ms |
19804 KB |
Output is correct |
11 |
Correct |
5 ms |
19616 KB |
Output is correct |
12 |
Correct |
6 ms |
19804 KB |
Output is correct |
13 |
Correct |
6 ms |
19804 KB |
Output is correct |
14 |
Correct |
6 ms |
19804 KB |
Output is correct |
15 |
Correct |
7 ms |
19804 KB |
Output is correct |
16 |
Correct |
6 ms |
20056 KB |
Output is correct |
17 |
Correct |
7 ms |
19648 KB |
Output is correct |
18 |
Correct |
6 ms |
19804 KB |
Output is correct |
19 |
Correct |
7 ms |
19804 KB |
Output is correct |
20 |
Correct |
7 ms |
19804 KB |
Output is correct |
21 |
Correct |
5 ms |
19288 KB |
Output is correct |
22 |
Correct |
6 ms |
19800 KB |
Output is correct |
23 |
Correct |
7 ms |
19888 KB |
Output is correct |
24 |
Correct |
6 ms |
19804 KB |
Output is correct |
25 |
Correct |
6 ms |
19804 KB |
Output is correct |
26 |
Correct |
6 ms |
19724 KB |
Output is correct |
27 |
Correct |
7 ms |
19252 KB |
Output is correct |
28 |
Correct |
6 ms |
19804 KB |
Output is correct |
29 |
Correct |
6 ms |
19804 KB |
Output is correct |
30 |
Correct |
6 ms |
19544 KB |
Output is correct |
31 |
Correct |
635 ms |
79300 KB |
Output is correct |
32 |
Correct |
152 ms |
28076 KB |
Output is correct |
33 |
Correct |
595 ms |
77552 KB |
Output is correct |
34 |
Correct |
513 ms |
77756 KB |
Output is correct |
35 |
Correct |
655 ms |
79036 KB |
Output is correct |
36 |
Correct |
661 ms |
79040 KB |
Output is correct |
37 |
Correct |
419 ms |
77544 KB |
Output is correct |
38 |
Correct |
426 ms |
77248 KB |
Output is correct |
39 |
Correct |
358 ms |
77188 KB |
Output is correct |
40 |
Correct |
355 ms |
77240 KB |
Output is correct |
41 |
Correct |
315 ms |
77632 KB |
Output is correct |
42 |
Correct |
276 ms |
77796 KB |
Output is correct |
43 |
Correct |
122 ms |
31020 KB |
Output is correct |
44 |
Correct |
315 ms |
78076 KB |
Output is correct |
45 |
Correct |
328 ms |
77692 KB |
Output is correct |
46 |
Correct |
345 ms |
77248 KB |
Output is correct |
47 |
Correct |
246 ms |
75248 KB |
Output is correct |
48 |
Correct |
263 ms |
74432 KB |
Output is correct |
49 |
Correct |
280 ms |
75864 KB |
Output is correct |
50 |
Correct |
265 ms |
77220 KB |
Output is correct |
51 |
Correct |
308 ms |
75496 KB |
Output is correct |
52 |
Correct |
1919 ms |
285204 KB |
Output is correct |
53 |
Correct |
3422 ms |
274720 KB |
Output is correct |
54 |
Correct |
1422 ms |
312292 KB |
Output is correct |
55 |
Correct |
1714 ms |
289380 KB |
Output is correct |
56 |
Correct |
3424 ms |
275276 KB |
Output is correct |
57 |
Correct |
3391 ms |
275052 KB |
Output is correct |
58 |
Correct |
1454 ms |
313612 KB |
Output is correct |
59 |
Correct |
1787 ms |
289648 KB |
Output is correct |
60 |
Correct |
2220 ms |
280860 KB |
Output is correct |
61 |
Correct |
3523 ms |
275620 KB |
Output is correct |
62 |
Correct |
1731 ms |
271536 KB |
Output is correct |
63 |
Correct |
2013 ms |
275096 KB |
Output is correct |
64 |
Correct |
4100 ms |
277632 KB |
Output is correct |
65 |
Correct |
749 ms |
71868 KB |
Output is correct |
66 |
Execution timed out |
5055 ms |
273356 KB |
Time limit exceeded |
67 |
Halted |
0 ms |
0 KB |
- |