#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#define ll long long
// #define int ll
#define all(v) v.begin(),v.end()
#define sz(s) ((int)s.size())
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
using namespace std;
const ll inf=1e18;
const int MAX=3e5+10;
const int mod=1e9+7;
int binpow(int a,int n){
if(!n)return 1;
if(n%2==1)return a*binpow(a,n-1)%mod;
int k=binpow(a,n/2);
return k*k%mod;
}
int n,k,q,m;
int a[MAX],b[MAX],x[MAX],t[MAX];
int l[MAX],y[MAX];
vector<int> events[MAX+MAX],zap[MAX+MAX];
set<pii> st[MAX];
vector<int> tim,pos;
struct segtree{
multiset<int> t[8*MAX];
void add(int v,int tl,int tr,int l,int r,int x){
if(l>r||tl>r||l>tr)return;
if(l<=tl&&tr<=r){
t[v].insert(x);
return;
}
int tm=(tl+tr)/2;
add(2*v,tl,tm,l,r,x);
add(2*v+1,tm+1,tr,l,r,x);
}
void del(int v,int tl,int tr,int l,int r,int x){
if(l>r||tl>r||l>tr)return;
if(l<=tl&&tr<=r){
t[v].erase(t[v].find(x));
return;
}
int tm=(tl+tr)/2;
del(2*v,tl,tm,l,r,x);
del(2*v+1,tm+1,tr,l,r,x);
}
int get(int v,int tl,int tr,int p,int x){
int res=0;
if(!t[v].empty())res=max(abs(*t[v].begin()-x),abs(*t[v].rbegin()-x));
if(tl==tr)return res;
int tm=(tl+tr)/2;
if(p<=tm)return max(res,get(2*v,tl,tm,p,x));
else return max(res,get(2*v+1,tm+1,tr,p,x));
}
}tree;
int L[MAX],R[MAX];
int cnt[MAX],col;
void add(int id){
if(cnt[t[id]]==0)col++;
cnt[t[id]]++;
if(st[t[id]].empty()){
L[id]=0,R[id]=m-1;
tree.add(1,0,m-1,0,m-1,x[id]);
}
else{
auto r=st[t[id]].lb({x[id],id});
if(r==st[t[id]].end()){
r--;
tree.del(1,0,m-1,L[r->S],R[r->S],x[r->S]);
int mid=ub(all(pos),(r->F+x[id])/2)-pos.begin()-1;
R[r->S]=mid;
L[id]=mid+1,R[id]=m-1;
tree.add(1,0,m-1,L[r->S],R[r->S],x[r->S]);
tree.add(1,0,m-1,L[id],R[id],x[id]);
}
else if(r==st[t[id]].begin()){
tree.del(1,0,m-1,L[r->S],R[r->S],x[r->S]);
int mid=ub(all(pos),(x[id]+r->F)/2)-pos.begin()-1;
R[id]=mid,L[id]=0;
L[r->S]=mid+1;
tree.add(1,0,m-1,L[r->S],R[r->S],x[r->S]);
tree.add(1,0,m-1,L[id],R[id],x[id]);
}
else{
auto l=--st[t[id]].lb({x[id],id});
tree.del(1,0,m-1,L[r->S],R[r->S],x[r->S]);
tree.del(1,0,m-1,L[l->S],R[l->S],x[l->S]);
int mid1=ub(all(pos),(x[id]+l->F)/2)-pos.begin()-1;
int mid2=ub(all(pos),(x[id]+r->F)/2)-pos.begin()-1;
R[l->S]=mid1;
L[id]=mid1+1;
R[id]=mid2;
L[r->S]=mid2+1;
tree.add(1,0,m-1,L[r->S],R[r->S],x[r->S]);
tree.add(1,0,m-1,L[l->S],R[l->S],x[l->S]);
tree.add(1,0,m-1,L[id],R[id],x[id]);
}
}
st[t[id]].insert({x[id],id});
}
void del(int id){
id=-id;
cnt[t[id]]--;
if(cnt[t[id]]==0)col--;
if(sz(st[t[id]])==1){
tree.del(1,0,m-1,0,m-1,x[id]);
}
else{
tree.del(1,0,m-1,L[id],R[id],x[id]);
auto r=st[t[id]].lb({x[id],id});
if(r==--st[t[id]].end()){
r--;
tree.del(1,0,m-1,L[r->S],R[r->S],x[r->S]);
R[r->S]=m-1;
tree.add(1,0,m-1,L[r->S],R[r->S],x[r->S]);
}
else if(r==st[t[id]].begin()){
r++;
tree.del(1,0,m-1,L[r->S],R[r->S],x[r->S]);
L[r->S]=0;
tree.add(1,0,m-1,L[r->S],R[r->S],x[r->S]);
}
else{
auto l=--st[t[id]].lb({x[id],id});
r++;
tree.del(1,0,m-1,L[r->S],R[r->S],x[r->S]);
tree.del(1,0,m-1,L[l->S],R[l->S],x[l->S]);
int mid=ub(all(pos),(r->F+l->F)/2)-pos.begin()-1;
R[l->S]=mid;
L[r->S]=mid+1;
tree.add(1,0,m-1,L[r->S],R[r->S],x[r->S]);
tree.add(1,0,m-1,L[l->S],R[l->S],x[l->S]);
}
}
st[t[id]].erase({x[id],id});
}
void solve(){
cin>>n>>k>>q;
for(int i=1;i<=n;i++){
cin>>x[i]>>t[i]>>a[i]>>b[i];
tim.pb(a[i]);
tim.pb(b[i]+1);
pos.pb(x[i]);
}
for(int i=1;i<=q;i++){
cin>>l[i]>>y[i];
pos.pb(l[i]);
tim.pb(y[i]);
}
sort(all(pos));
pos.erase(unique(all(pos)),pos.end());
sort(all(tim));
tim.erase(unique(all(tim)),tim.end());
for(int i=1;i<=n;i++){
a[i]=lb(all(tim),a[i])-tim.begin();
b[i]=lb(all(tim),b[i]+1)-tim.begin();
events[a[i]].pb(i);
events[b[i]].pb(-i);
}
for(int i=1;i<=q;i++){
y[i]=lb(all(tim),y[i])-tim.begin();
zap[y[i]].pb(i);
}
m=sz(pos);
vector<int> ans(q+1,0);
for(int i=0;i<sz(tim);i++){
for(auto id:events[i]){
if(id>0){
add(id);
}
else{
del(id);
}
}
for(int id:zap[i]){
if(col!=k)ans[id]=-1;
else ans[id]=tree.get(1,0,m-1,lb(all(pos),l[id])-pos.begin(),l[id]);
}
}
for(int i=1;i<=q;i++)cout<<ans[i]<<"\n";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
while(t--)solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
155244 KB |
Output is correct |
2 |
Correct |
99 ms |
155464 KB |
Output is correct |
3 |
Correct |
105 ms |
155316 KB |
Output is correct |
4 |
Correct |
99 ms |
155464 KB |
Output is correct |
5 |
Correct |
101 ms |
155464 KB |
Output is correct |
6 |
Correct |
104 ms |
155464 KB |
Output is correct |
7 |
Correct |
95 ms |
155464 KB |
Output is correct |
8 |
Correct |
95 ms |
155464 KB |
Output is correct |
9 |
Correct |
98 ms |
155464 KB |
Output is correct |
10 |
Correct |
95 ms |
155464 KB |
Output is correct |
11 |
Correct |
94 ms |
155464 KB |
Output is correct |
12 |
Correct |
95 ms |
155464 KB |
Output is correct |
13 |
Correct |
93 ms |
155552 KB |
Output is correct |
14 |
Correct |
96 ms |
155472 KB |
Output is correct |
15 |
Correct |
96 ms |
155464 KB |
Output is correct |
16 |
Correct |
99 ms |
155464 KB |
Output is correct |
17 |
Correct |
98 ms |
155480 KB |
Output is correct |
18 |
Correct |
105 ms |
155464 KB |
Output is correct |
19 |
Correct |
102 ms |
155468 KB |
Output is correct |
20 |
Correct |
114 ms |
155512 KB |
Output is correct |
21 |
Correct |
107 ms |
155464 KB |
Output is correct |
22 |
Correct |
113 ms |
155464 KB |
Output is correct |
23 |
Correct |
110 ms |
155536 KB |
Output is correct |
24 |
Correct |
108 ms |
155464 KB |
Output is correct |
25 |
Correct |
111 ms |
155364 KB |
Output is correct |
26 |
Correct |
106 ms |
155472 KB |
Output is correct |
27 |
Correct |
104 ms |
155480 KB |
Output is correct |
28 |
Correct |
105 ms |
155464 KB |
Output is correct |
29 |
Correct |
107 ms |
155372 KB |
Output is correct |
30 |
Correct |
111 ms |
155468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
155244 KB |
Output is correct |
2 |
Correct |
99 ms |
155464 KB |
Output is correct |
3 |
Correct |
105 ms |
155316 KB |
Output is correct |
4 |
Correct |
99 ms |
155464 KB |
Output is correct |
5 |
Correct |
101 ms |
155464 KB |
Output is correct |
6 |
Correct |
104 ms |
155464 KB |
Output is correct |
7 |
Correct |
95 ms |
155464 KB |
Output is correct |
8 |
Correct |
95 ms |
155464 KB |
Output is correct |
9 |
Correct |
98 ms |
155464 KB |
Output is correct |
10 |
Correct |
95 ms |
155464 KB |
Output is correct |
11 |
Correct |
94 ms |
155464 KB |
Output is correct |
12 |
Correct |
95 ms |
155464 KB |
Output is correct |
13 |
Correct |
93 ms |
155552 KB |
Output is correct |
14 |
Correct |
96 ms |
155472 KB |
Output is correct |
15 |
Correct |
96 ms |
155464 KB |
Output is correct |
16 |
Correct |
99 ms |
155464 KB |
Output is correct |
17 |
Correct |
98 ms |
155480 KB |
Output is correct |
18 |
Correct |
105 ms |
155464 KB |
Output is correct |
19 |
Correct |
102 ms |
155468 KB |
Output is correct |
20 |
Correct |
114 ms |
155512 KB |
Output is correct |
21 |
Correct |
107 ms |
155464 KB |
Output is correct |
22 |
Correct |
113 ms |
155464 KB |
Output is correct |
23 |
Correct |
110 ms |
155536 KB |
Output is correct |
24 |
Correct |
108 ms |
155464 KB |
Output is correct |
25 |
Correct |
111 ms |
155364 KB |
Output is correct |
26 |
Correct |
106 ms |
155472 KB |
Output is correct |
27 |
Correct |
104 ms |
155480 KB |
Output is correct |
28 |
Correct |
105 ms |
155464 KB |
Output is correct |
29 |
Correct |
107 ms |
155372 KB |
Output is correct |
30 |
Correct |
111 ms |
155468 KB |
Output is correct |
31 |
Correct |
1755 ms |
193564 KB |
Output is correct |
32 |
Correct |
178 ms |
160704 KB |
Output is correct |
33 |
Correct |
712 ms |
171356 KB |
Output is correct |
34 |
Correct |
1295 ms |
176592 KB |
Output is correct |
35 |
Correct |
1263 ms |
189152 KB |
Output is correct |
36 |
Correct |
727 ms |
180932 KB |
Output is correct |
37 |
Correct |
600 ms |
168008 KB |
Output is correct |
38 |
Correct |
478 ms |
167360 KB |
Output is correct |
39 |
Correct |
425 ms |
164784 KB |
Output is correct |
40 |
Correct |
421 ms |
165216 KB |
Output is correct |
41 |
Correct |
497 ms |
165060 KB |
Output is correct |
42 |
Correct |
483 ms |
166744 KB |
Output is correct |
43 |
Correct |
159 ms |
164292 KB |
Output is correct |
44 |
Correct |
486 ms |
166852 KB |
Output is correct |
45 |
Correct |
426 ms |
166596 KB |
Output is correct |
46 |
Correct |
380 ms |
164800 KB |
Output is correct |
47 |
Correct |
297 ms |
165812 KB |
Output is correct |
48 |
Correct |
271 ms |
164292 KB |
Output is correct |
49 |
Correct |
341 ms |
164508 KB |
Output is correct |
50 |
Correct |
422 ms |
166620 KB |
Output is correct |
51 |
Correct |
353 ms |
164548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5045 ms |
362972 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5053 ms |
319952 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
155244 KB |
Output is correct |
2 |
Correct |
99 ms |
155464 KB |
Output is correct |
3 |
Correct |
105 ms |
155316 KB |
Output is correct |
4 |
Correct |
99 ms |
155464 KB |
Output is correct |
5 |
Correct |
101 ms |
155464 KB |
Output is correct |
6 |
Correct |
104 ms |
155464 KB |
Output is correct |
7 |
Correct |
95 ms |
155464 KB |
Output is correct |
8 |
Correct |
95 ms |
155464 KB |
Output is correct |
9 |
Correct |
98 ms |
155464 KB |
Output is correct |
10 |
Correct |
95 ms |
155464 KB |
Output is correct |
11 |
Correct |
94 ms |
155464 KB |
Output is correct |
12 |
Correct |
95 ms |
155464 KB |
Output is correct |
13 |
Correct |
93 ms |
155552 KB |
Output is correct |
14 |
Correct |
96 ms |
155472 KB |
Output is correct |
15 |
Correct |
96 ms |
155464 KB |
Output is correct |
16 |
Correct |
99 ms |
155464 KB |
Output is correct |
17 |
Correct |
98 ms |
155480 KB |
Output is correct |
18 |
Correct |
105 ms |
155464 KB |
Output is correct |
19 |
Correct |
102 ms |
155468 KB |
Output is correct |
20 |
Correct |
114 ms |
155512 KB |
Output is correct |
21 |
Correct |
107 ms |
155464 KB |
Output is correct |
22 |
Correct |
113 ms |
155464 KB |
Output is correct |
23 |
Correct |
110 ms |
155536 KB |
Output is correct |
24 |
Correct |
108 ms |
155464 KB |
Output is correct |
25 |
Correct |
111 ms |
155364 KB |
Output is correct |
26 |
Correct |
106 ms |
155472 KB |
Output is correct |
27 |
Correct |
104 ms |
155480 KB |
Output is correct |
28 |
Correct |
105 ms |
155464 KB |
Output is correct |
29 |
Correct |
107 ms |
155372 KB |
Output is correct |
30 |
Correct |
111 ms |
155468 KB |
Output is correct |
31 |
Correct |
1755 ms |
193564 KB |
Output is correct |
32 |
Correct |
178 ms |
160704 KB |
Output is correct |
33 |
Correct |
712 ms |
171356 KB |
Output is correct |
34 |
Correct |
1295 ms |
176592 KB |
Output is correct |
35 |
Correct |
1263 ms |
189152 KB |
Output is correct |
36 |
Correct |
727 ms |
180932 KB |
Output is correct |
37 |
Correct |
600 ms |
168008 KB |
Output is correct |
38 |
Correct |
478 ms |
167360 KB |
Output is correct |
39 |
Correct |
425 ms |
164784 KB |
Output is correct |
40 |
Correct |
421 ms |
165216 KB |
Output is correct |
41 |
Correct |
497 ms |
165060 KB |
Output is correct |
42 |
Correct |
483 ms |
166744 KB |
Output is correct |
43 |
Correct |
159 ms |
164292 KB |
Output is correct |
44 |
Correct |
486 ms |
166852 KB |
Output is correct |
45 |
Correct |
426 ms |
166596 KB |
Output is correct |
46 |
Correct |
380 ms |
164800 KB |
Output is correct |
47 |
Correct |
297 ms |
165812 KB |
Output is correct |
48 |
Correct |
271 ms |
164292 KB |
Output is correct |
49 |
Correct |
341 ms |
164508 KB |
Output is correct |
50 |
Correct |
422 ms |
166620 KB |
Output is correct |
51 |
Correct |
353 ms |
164548 KB |
Output is correct |
52 |
Correct |
279 ms |
171972 KB |
Output is correct |
53 |
Correct |
258 ms |
166848 KB |
Output is correct |
54 |
Correct |
981 ms |
195780 KB |
Output is correct |
55 |
Correct |
409 ms |
166852 KB |
Output is correct |
56 |
Correct |
373 ms |
167796 KB |
Output is correct |
57 |
Correct |
452 ms |
165740 KB |
Output is correct |
58 |
Correct |
408 ms |
167068 KB |
Output is correct |
59 |
Correct |
398 ms |
167912 KB |
Output is correct |
60 |
Correct |
512 ms |
165576 KB |
Output is correct |
61 |
Correct |
156 ms |
165876 KB |
Output is correct |
62 |
Correct |
305 ms |
170436 KB |
Output is correct |
63 |
Correct |
603 ms |
183128 KB |
Output is correct |
64 |
Correct |
677 ms |
182212 KB |
Output is correct |
65 |
Correct |
764 ms |
172484 KB |
Output is correct |
66 |
Correct |
541 ms |
167108 KB |
Output is correct |
67 |
Correct |
384 ms |
163112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
155244 KB |
Output is correct |
2 |
Correct |
99 ms |
155464 KB |
Output is correct |
3 |
Correct |
105 ms |
155316 KB |
Output is correct |
4 |
Correct |
99 ms |
155464 KB |
Output is correct |
5 |
Correct |
101 ms |
155464 KB |
Output is correct |
6 |
Correct |
104 ms |
155464 KB |
Output is correct |
7 |
Correct |
95 ms |
155464 KB |
Output is correct |
8 |
Correct |
95 ms |
155464 KB |
Output is correct |
9 |
Correct |
98 ms |
155464 KB |
Output is correct |
10 |
Correct |
95 ms |
155464 KB |
Output is correct |
11 |
Correct |
94 ms |
155464 KB |
Output is correct |
12 |
Correct |
95 ms |
155464 KB |
Output is correct |
13 |
Correct |
93 ms |
155552 KB |
Output is correct |
14 |
Correct |
96 ms |
155472 KB |
Output is correct |
15 |
Correct |
96 ms |
155464 KB |
Output is correct |
16 |
Correct |
99 ms |
155464 KB |
Output is correct |
17 |
Correct |
98 ms |
155480 KB |
Output is correct |
18 |
Correct |
105 ms |
155464 KB |
Output is correct |
19 |
Correct |
102 ms |
155468 KB |
Output is correct |
20 |
Correct |
114 ms |
155512 KB |
Output is correct |
21 |
Correct |
107 ms |
155464 KB |
Output is correct |
22 |
Correct |
113 ms |
155464 KB |
Output is correct |
23 |
Correct |
110 ms |
155536 KB |
Output is correct |
24 |
Correct |
108 ms |
155464 KB |
Output is correct |
25 |
Correct |
111 ms |
155364 KB |
Output is correct |
26 |
Correct |
106 ms |
155472 KB |
Output is correct |
27 |
Correct |
104 ms |
155480 KB |
Output is correct |
28 |
Correct |
105 ms |
155464 KB |
Output is correct |
29 |
Correct |
107 ms |
155372 KB |
Output is correct |
30 |
Correct |
111 ms |
155468 KB |
Output is correct |
31 |
Correct |
1755 ms |
193564 KB |
Output is correct |
32 |
Correct |
178 ms |
160704 KB |
Output is correct |
33 |
Correct |
712 ms |
171356 KB |
Output is correct |
34 |
Correct |
1295 ms |
176592 KB |
Output is correct |
35 |
Correct |
1263 ms |
189152 KB |
Output is correct |
36 |
Correct |
727 ms |
180932 KB |
Output is correct |
37 |
Correct |
600 ms |
168008 KB |
Output is correct |
38 |
Correct |
478 ms |
167360 KB |
Output is correct |
39 |
Correct |
425 ms |
164784 KB |
Output is correct |
40 |
Correct |
421 ms |
165216 KB |
Output is correct |
41 |
Correct |
497 ms |
165060 KB |
Output is correct |
42 |
Correct |
483 ms |
166744 KB |
Output is correct |
43 |
Correct |
159 ms |
164292 KB |
Output is correct |
44 |
Correct |
486 ms |
166852 KB |
Output is correct |
45 |
Correct |
426 ms |
166596 KB |
Output is correct |
46 |
Correct |
380 ms |
164800 KB |
Output is correct |
47 |
Correct |
297 ms |
165812 KB |
Output is correct |
48 |
Correct |
271 ms |
164292 KB |
Output is correct |
49 |
Correct |
341 ms |
164508 KB |
Output is correct |
50 |
Correct |
422 ms |
166620 KB |
Output is correct |
51 |
Correct |
353 ms |
164548 KB |
Output is correct |
52 |
Execution timed out |
5045 ms |
362972 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |