#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#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(!t[v].empty())cout<<*t[v].begin()<<" "<<*t[v].rbegin()<<" "<<x<<"\n";
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(id==17)cerr<<sz(st[t[id]])<<"\n";
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);
// cerr<<m-1<<"\n";
for(int i=0;i<sz(tim);i++){
// cerr<<0<<"\n";
for(auto id:events[i]){
// cerr<<id<<"\n";
if(id>0){
add(id);
}
else{
del(id);
}
}
// cerr<<"! "<<i<<" "<<tim[i]<<"\n";
for(int id:zap[i]){
// cout<<col<<"\n";
// cout<<"? "<<id<<" "<<l[id]<<"\n";
if(col!=k)ans[id]=-1;
else ans[id]=tree.get(1,0,m-1,lb(all(pos),l[id])-pos.begin(),l[id]);
}
// cout<<"! "<<tim[i]<<"\n";
// for(int j=1;j<=n;j++){
// if(a[j]<=i&&i<b[j]){
// cout<<j<<" "<<L[j]<<" "<<R[j]<<"\n";
// }
// }
}
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();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
155464 KB |
Output is correct |
2 |
Correct |
110 ms |
155464 KB |
Output is correct |
3 |
Correct |
101 ms |
155464 KB |
Output is correct |
4 |
Correct |
103 ms |
155464 KB |
Output is correct |
5 |
Correct |
104 ms |
155468 KB |
Output is correct |
6 |
Correct |
115 ms |
155392 KB |
Output is correct |
7 |
Correct |
109 ms |
155464 KB |
Output is correct |
8 |
Correct |
104 ms |
155464 KB |
Output is correct |
9 |
Correct |
106 ms |
155464 KB |
Output is correct |
10 |
Correct |
115 ms |
155428 KB |
Output is correct |
11 |
Correct |
111 ms |
155464 KB |
Output is correct |
12 |
Correct |
109 ms |
155468 KB |
Output is correct |
13 |
Correct |
102 ms |
155464 KB |
Output is correct |
14 |
Correct |
102 ms |
155556 KB |
Output is correct |
15 |
Correct |
101 ms |
155520 KB |
Output is correct |
16 |
Correct |
113 ms |
155464 KB |
Output is correct |
17 |
Correct |
110 ms |
155464 KB |
Output is correct |
18 |
Correct |
102 ms |
155464 KB |
Output is correct |
19 |
Correct |
107 ms |
155464 KB |
Output is correct |
20 |
Correct |
98 ms |
155464 KB |
Output is correct |
21 |
Correct |
105 ms |
155464 KB |
Output is correct |
22 |
Correct |
100 ms |
155472 KB |
Output is correct |
23 |
Correct |
101 ms |
155612 KB |
Output is correct |
24 |
Correct |
100 ms |
155464 KB |
Output is correct |
25 |
Correct |
102 ms |
155596 KB |
Output is correct |
26 |
Correct |
102 ms |
155464 KB |
Output is correct |
27 |
Correct |
103 ms |
155464 KB |
Output is correct |
28 |
Correct |
103 ms |
155372 KB |
Output is correct |
29 |
Correct |
106 ms |
155464 KB |
Output is correct |
30 |
Correct |
105 ms |
155464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
155464 KB |
Output is correct |
2 |
Correct |
110 ms |
155464 KB |
Output is correct |
3 |
Correct |
101 ms |
155464 KB |
Output is correct |
4 |
Correct |
103 ms |
155464 KB |
Output is correct |
5 |
Correct |
104 ms |
155468 KB |
Output is correct |
6 |
Correct |
115 ms |
155392 KB |
Output is correct |
7 |
Correct |
109 ms |
155464 KB |
Output is correct |
8 |
Correct |
104 ms |
155464 KB |
Output is correct |
9 |
Correct |
106 ms |
155464 KB |
Output is correct |
10 |
Correct |
115 ms |
155428 KB |
Output is correct |
11 |
Correct |
111 ms |
155464 KB |
Output is correct |
12 |
Correct |
109 ms |
155468 KB |
Output is correct |
13 |
Correct |
102 ms |
155464 KB |
Output is correct |
14 |
Correct |
102 ms |
155556 KB |
Output is correct |
15 |
Correct |
101 ms |
155520 KB |
Output is correct |
16 |
Correct |
113 ms |
155464 KB |
Output is correct |
17 |
Correct |
110 ms |
155464 KB |
Output is correct |
18 |
Correct |
102 ms |
155464 KB |
Output is correct |
19 |
Correct |
107 ms |
155464 KB |
Output is correct |
20 |
Correct |
98 ms |
155464 KB |
Output is correct |
21 |
Correct |
105 ms |
155464 KB |
Output is correct |
22 |
Correct |
100 ms |
155472 KB |
Output is correct |
23 |
Correct |
101 ms |
155612 KB |
Output is correct |
24 |
Correct |
100 ms |
155464 KB |
Output is correct |
25 |
Correct |
102 ms |
155596 KB |
Output is correct |
26 |
Correct |
102 ms |
155464 KB |
Output is correct |
27 |
Correct |
103 ms |
155464 KB |
Output is correct |
28 |
Correct |
103 ms |
155372 KB |
Output is correct |
29 |
Correct |
106 ms |
155464 KB |
Output is correct |
30 |
Correct |
105 ms |
155464 KB |
Output is correct |
31 |
Correct |
1793 ms |
196408 KB |
Output is correct |
32 |
Correct |
170 ms |
161732 KB |
Output is correct |
33 |
Correct |
689 ms |
174332 KB |
Output is correct |
34 |
Correct |
1281 ms |
179536 KB |
Output is correct |
35 |
Correct |
1510 ms |
191984 KB |
Output is correct |
36 |
Correct |
719 ms |
182112 KB |
Output is correct |
37 |
Correct |
616 ms |
169248 KB |
Output is correct |
38 |
Correct |
478 ms |
168536 KB |
Output is correct |
39 |
Correct |
422 ms |
167620 KB |
Output is correct |
40 |
Correct |
409 ms |
167572 KB |
Output is correct |
41 |
Correct |
477 ms |
168084 KB |
Output is correct |
42 |
Correct |
491 ms |
167972 KB |
Output is correct |
43 |
Correct |
152 ms |
165060 KB |
Output is correct |
44 |
Correct |
488 ms |
168132 KB |
Output is correct |
45 |
Correct |
398 ms |
167836 KB |
Output is correct |
46 |
Correct |
349 ms |
167584 KB |
Output is correct |
47 |
Correct |
297 ms |
167108 KB |
Output is correct |
48 |
Correct |
275 ms |
167108 KB |
Output is correct |
49 |
Correct |
364 ms |
167240 KB |
Output is correct |
50 |
Correct |
410 ms |
167620 KB |
Output is correct |
51 |
Correct |
329 ms |
167612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5043 ms |
366296 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5039 ms |
319640 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
155464 KB |
Output is correct |
2 |
Correct |
110 ms |
155464 KB |
Output is correct |
3 |
Correct |
101 ms |
155464 KB |
Output is correct |
4 |
Correct |
103 ms |
155464 KB |
Output is correct |
5 |
Correct |
104 ms |
155468 KB |
Output is correct |
6 |
Correct |
115 ms |
155392 KB |
Output is correct |
7 |
Correct |
109 ms |
155464 KB |
Output is correct |
8 |
Correct |
104 ms |
155464 KB |
Output is correct |
9 |
Correct |
106 ms |
155464 KB |
Output is correct |
10 |
Correct |
115 ms |
155428 KB |
Output is correct |
11 |
Correct |
111 ms |
155464 KB |
Output is correct |
12 |
Correct |
109 ms |
155468 KB |
Output is correct |
13 |
Correct |
102 ms |
155464 KB |
Output is correct |
14 |
Correct |
102 ms |
155556 KB |
Output is correct |
15 |
Correct |
101 ms |
155520 KB |
Output is correct |
16 |
Correct |
113 ms |
155464 KB |
Output is correct |
17 |
Correct |
110 ms |
155464 KB |
Output is correct |
18 |
Correct |
102 ms |
155464 KB |
Output is correct |
19 |
Correct |
107 ms |
155464 KB |
Output is correct |
20 |
Correct |
98 ms |
155464 KB |
Output is correct |
21 |
Correct |
105 ms |
155464 KB |
Output is correct |
22 |
Correct |
100 ms |
155472 KB |
Output is correct |
23 |
Correct |
101 ms |
155612 KB |
Output is correct |
24 |
Correct |
100 ms |
155464 KB |
Output is correct |
25 |
Correct |
102 ms |
155596 KB |
Output is correct |
26 |
Correct |
102 ms |
155464 KB |
Output is correct |
27 |
Correct |
103 ms |
155464 KB |
Output is correct |
28 |
Correct |
103 ms |
155372 KB |
Output is correct |
29 |
Correct |
106 ms |
155464 KB |
Output is correct |
30 |
Correct |
105 ms |
155464 KB |
Output is correct |
31 |
Correct |
1793 ms |
196408 KB |
Output is correct |
32 |
Correct |
170 ms |
161732 KB |
Output is correct |
33 |
Correct |
689 ms |
174332 KB |
Output is correct |
34 |
Correct |
1281 ms |
179536 KB |
Output is correct |
35 |
Correct |
1510 ms |
191984 KB |
Output is correct |
36 |
Correct |
719 ms |
182112 KB |
Output is correct |
37 |
Correct |
616 ms |
169248 KB |
Output is correct |
38 |
Correct |
478 ms |
168536 KB |
Output is correct |
39 |
Correct |
422 ms |
167620 KB |
Output is correct |
40 |
Correct |
409 ms |
167572 KB |
Output is correct |
41 |
Correct |
477 ms |
168084 KB |
Output is correct |
42 |
Correct |
491 ms |
167972 KB |
Output is correct |
43 |
Correct |
152 ms |
165060 KB |
Output is correct |
44 |
Correct |
488 ms |
168132 KB |
Output is correct |
45 |
Correct |
398 ms |
167836 KB |
Output is correct |
46 |
Correct |
349 ms |
167584 KB |
Output is correct |
47 |
Correct |
297 ms |
167108 KB |
Output is correct |
48 |
Correct |
275 ms |
167108 KB |
Output is correct |
49 |
Correct |
364 ms |
167240 KB |
Output is correct |
50 |
Correct |
410 ms |
167620 KB |
Output is correct |
51 |
Correct |
329 ms |
167612 KB |
Output is correct |
52 |
Correct |
270 ms |
173544 KB |
Output is correct |
53 |
Correct |
246 ms |
170000 KB |
Output is correct |
54 |
Correct |
996 ms |
198852 KB |
Output is correct |
55 |
Correct |
414 ms |
170108 KB |
Output is correct |
56 |
Correct |
391 ms |
170948 KB |
Output is correct |
57 |
Correct |
447 ms |
170436 KB |
Output is correct |
58 |
Correct |
407 ms |
169924 KB |
Output is correct |
59 |
Correct |
370 ms |
170948 KB |
Output is correct |
60 |
Correct |
446 ms |
168572 KB |
Output is correct |
61 |
Correct |
147 ms |
168388 KB |
Output is correct |
62 |
Correct |
249 ms |
173564 KB |
Output is correct |
63 |
Correct |
617 ms |
186244 KB |
Output is correct |
64 |
Correct |
767 ms |
185276 KB |
Output is correct |
65 |
Correct |
749 ms |
173772 KB |
Output is correct |
66 |
Correct |
531 ms |
168388 KB |
Output is correct |
67 |
Correct |
410 ms |
163520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
155464 KB |
Output is correct |
2 |
Correct |
110 ms |
155464 KB |
Output is correct |
3 |
Correct |
101 ms |
155464 KB |
Output is correct |
4 |
Correct |
103 ms |
155464 KB |
Output is correct |
5 |
Correct |
104 ms |
155468 KB |
Output is correct |
6 |
Correct |
115 ms |
155392 KB |
Output is correct |
7 |
Correct |
109 ms |
155464 KB |
Output is correct |
8 |
Correct |
104 ms |
155464 KB |
Output is correct |
9 |
Correct |
106 ms |
155464 KB |
Output is correct |
10 |
Correct |
115 ms |
155428 KB |
Output is correct |
11 |
Correct |
111 ms |
155464 KB |
Output is correct |
12 |
Correct |
109 ms |
155468 KB |
Output is correct |
13 |
Correct |
102 ms |
155464 KB |
Output is correct |
14 |
Correct |
102 ms |
155556 KB |
Output is correct |
15 |
Correct |
101 ms |
155520 KB |
Output is correct |
16 |
Correct |
113 ms |
155464 KB |
Output is correct |
17 |
Correct |
110 ms |
155464 KB |
Output is correct |
18 |
Correct |
102 ms |
155464 KB |
Output is correct |
19 |
Correct |
107 ms |
155464 KB |
Output is correct |
20 |
Correct |
98 ms |
155464 KB |
Output is correct |
21 |
Correct |
105 ms |
155464 KB |
Output is correct |
22 |
Correct |
100 ms |
155472 KB |
Output is correct |
23 |
Correct |
101 ms |
155612 KB |
Output is correct |
24 |
Correct |
100 ms |
155464 KB |
Output is correct |
25 |
Correct |
102 ms |
155596 KB |
Output is correct |
26 |
Correct |
102 ms |
155464 KB |
Output is correct |
27 |
Correct |
103 ms |
155464 KB |
Output is correct |
28 |
Correct |
103 ms |
155372 KB |
Output is correct |
29 |
Correct |
106 ms |
155464 KB |
Output is correct |
30 |
Correct |
105 ms |
155464 KB |
Output is correct |
31 |
Correct |
1793 ms |
196408 KB |
Output is correct |
32 |
Correct |
170 ms |
161732 KB |
Output is correct |
33 |
Correct |
689 ms |
174332 KB |
Output is correct |
34 |
Correct |
1281 ms |
179536 KB |
Output is correct |
35 |
Correct |
1510 ms |
191984 KB |
Output is correct |
36 |
Correct |
719 ms |
182112 KB |
Output is correct |
37 |
Correct |
616 ms |
169248 KB |
Output is correct |
38 |
Correct |
478 ms |
168536 KB |
Output is correct |
39 |
Correct |
422 ms |
167620 KB |
Output is correct |
40 |
Correct |
409 ms |
167572 KB |
Output is correct |
41 |
Correct |
477 ms |
168084 KB |
Output is correct |
42 |
Correct |
491 ms |
167972 KB |
Output is correct |
43 |
Correct |
152 ms |
165060 KB |
Output is correct |
44 |
Correct |
488 ms |
168132 KB |
Output is correct |
45 |
Correct |
398 ms |
167836 KB |
Output is correct |
46 |
Correct |
349 ms |
167584 KB |
Output is correct |
47 |
Correct |
297 ms |
167108 KB |
Output is correct |
48 |
Correct |
275 ms |
167108 KB |
Output is correct |
49 |
Correct |
364 ms |
167240 KB |
Output is correct |
50 |
Correct |
410 ms |
167620 KB |
Output is correct |
51 |
Correct |
329 ms |
167612 KB |
Output is correct |
52 |
Execution timed out |
5043 ms |
366296 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |