#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 int inf=1e8;
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];
multiset<int> st[MAX];
vector<int> tim,pos;
struct segtree{
multiset<int> t[4*8*MAX];
int mx[4*8*MAX],L[4*8*MAX],R[4*8*MAX];
int cnt=1;
segtree(){
memset(L,0,sizeof(L));
memset(R,0,sizeof(R));
memset(mx,-1,sizeof(mx));
}
void add(int v,int tl,int tr,int pos,int x){
if(tl==tr){
t[v].insert(x);
mx[v]=*t[v].rbegin();
return;
}
int tm=(tl+tr)/2;
if(pos<=tm){
if(!L[v])L[v]=++cnt;
add(L[v],tl,tm,pos,x);
}
else{
if(!R[v])R[v]=++cnt;
add(R[v],tm+1,tr,pos,x);
}
mx[v]=max(mx[L[v]],mx[R[v]]);
}
void del(int v,int tl,int tr,int pos,int x){
if(tl==tr){
t[v].erase(t[v].find(x));
if(t[v].empty())mx[v]=-1;
else mx[v]=*t[v].rbegin();
return;
}
int tm=(tl+tr)/2;
if(pos<=tm){
del(L[v],tl,tm,pos,x);
}
else{
del(R[v],tm+1,tr,pos,x);
}
mx[v]=max(mx[L[v]],mx[R[v]]);
}
int get(int v,int tl,int tr,int l,int r){
if(l>r||tl>r||l>tr)return 0;
if(l<=tl&&tr<=r)return mx[v];
int tm=(tl+tr)/2;
int res=0;
if(L[v])res=max(res,get(L[v],tl,tm,l,r));
if(R[v])res=max(res,get(R[v],tm+1,tr,l,r));
return res;
}
}tree;
int L[MAX],R[MAX];
int cnt[MAX],col;
int getx(int x){
return lb(all(pos),x)-pos.begin();
}
void add(int id){
if(cnt[t[id]]==0)col++;
cnt[t[id]]++;
if(st[t[id]].count(x[id]))st[t[id]].insert(x[id]);
else{
auto l=--st[t[id]].lb(x[id]);
auto r=st[t[id]].lb(x[id]);
int LL=getx(*l+1);
if(!(*l==-1&&*r==inf+1))tree.del(1,0,m-1,LL,*r-1);
tree.add(1,0,m-1,LL,x[id]-1);
tree.add(1,0,m-1,getx(x[id]+1),*r-1);
st[t[id]].insert(x[id]);
}
}
void del(int id){
id=-id;
cnt[t[id]]--;
if(cnt[t[id]]==0)col--;
st[t[id]].erase(st[t[id]].find(x[id]));
if(!st[t[id]].count(x[id])){
auto l=--st[t[id]].lb(x[id]);
auto r=st[t[id]].lb(x[id]);
int LL=getx(*l+1);
tree.del(1,0,m-1,LL,x[id]-1);
tree.del(1,0,m-1,getx(x[id]+1),*r-1);
if(!(*l==-1&&*r==inf+1))tree.add(1,0,m-1,LL,*r-1);
}
}
bool check(int l,int r){
l=max(l,0);
r=min(r,inf);
l=ub(all(pos),l)-pos.begin()-1;
if(tree.get(1,0,m-1,0,l)>=r)return 0;
return 1;
}
int ans[MAX];
void solve(){
cin>>n>>k>>q;
pos.pb(0),pos.pb(inf);
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]+1);
pos.pb(x[i]-1);
}
for(int i=1;i<=q;i++){
cin>>l[i]>>y[i];
tim.pb(y[i]);
}
sort(all(tim));
tim.erase(unique(all(tim)),tim.end());
sort(all(pos));
pos.erase(unique(all(pos)),pos.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);
}
for(int i=1;i<=k;i++){
st[i].insert(-1);
st[i].insert(inf+1);
}
m=sz(pos);
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{
int L=0,R=inf,res=inf;
while(L<=R){
int mid=(L+R)/2;
if(check(l[id]-mid,l[id]+mid)){
R=mid-1,res=mid;
}
else L=mid+1;
}
ans[id]=res;
}
}
}
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 |
333 ms |
607816 KB |
Output is correct |
2 |
Correct |
331 ms |
607732 KB |
Output is correct |
3 |
Correct |
387 ms |
607720 KB |
Output is correct |
4 |
Correct |
341 ms |
607740 KB |
Output is correct |
5 |
Correct |
352 ms |
607816 KB |
Output is correct |
6 |
Correct |
349 ms |
607884 KB |
Output is correct |
7 |
Correct |
346 ms |
607816 KB |
Output is correct |
8 |
Correct |
368 ms |
607824 KB |
Output is correct |
9 |
Correct |
364 ms |
607816 KB |
Output is correct |
10 |
Correct |
365 ms |
608072 KB |
Output is correct |
11 |
Correct |
362 ms |
607860 KB |
Output is correct |
12 |
Correct |
351 ms |
607820 KB |
Output is correct |
13 |
Correct |
318 ms |
607724 KB |
Output is correct |
14 |
Correct |
335 ms |
607816 KB |
Output is correct |
15 |
Correct |
329 ms |
607736 KB |
Output is correct |
16 |
Correct |
311 ms |
607896 KB |
Output is correct |
17 |
Correct |
314 ms |
607816 KB |
Output is correct |
18 |
Correct |
315 ms |
607816 KB |
Output is correct |
19 |
Correct |
320 ms |
607852 KB |
Output is correct |
20 |
Correct |
353 ms |
607824 KB |
Output is correct |
21 |
Correct |
353 ms |
607816 KB |
Output is correct |
22 |
Correct |
369 ms |
607816 KB |
Output is correct |
23 |
Correct |
391 ms |
608072 KB |
Output is correct |
24 |
Correct |
364 ms |
607756 KB |
Output is correct |
25 |
Correct |
361 ms |
607868 KB |
Output is correct |
26 |
Correct |
368 ms |
607816 KB |
Output is correct |
27 |
Correct |
359 ms |
607716 KB |
Output is correct |
28 |
Correct |
343 ms |
607888 KB |
Output is correct |
29 |
Correct |
348 ms |
607748 KB |
Output is correct |
30 |
Correct |
386 ms |
607944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
333 ms |
607816 KB |
Output is correct |
2 |
Correct |
331 ms |
607732 KB |
Output is correct |
3 |
Correct |
387 ms |
607720 KB |
Output is correct |
4 |
Correct |
341 ms |
607740 KB |
Output is correct |
5 |
Correct |
352 ms |
607816 KB |
Output is correct |
6 |
Correct |
349 ms |
607884 KB |
Output is correct |
7 |
Correct |
346 ms |
607816 KB |
Output is correct |
8 |
Correct |
368 ms |
607824 KB |
Output is correct |
9 |
Correct |
364 ms |
607816 KB |
Output is correct |
10 |
Correct |
365 ms |
608072 KB |
Output is correct |
11 |
Correct |
362 ms |
607860 KB |
Output is correct |
12 |
Correct |
351 ms |
607820 KB |
Output is correct |
13 |
Correct |
318 ms |
607724 KB |
Output is correct |
14 |
Correct |
335 ms |
607816 KB |
Output is correct |
15 |
Correct |
329 ms |
607736 KB |
Output is correct |
16 |
Correct |
311 ms |
607896 KB |
Output is correct |
17 |
Correct |
314 ms |
607816 KB |
Output is correct |
18 |
Correct |
315 ms |
607816 KB |
Output is correct |
19 |
Correct |
320 ms |
607852 KB |
Output is correct |
20 |
Correct |
353 ms |
607824 KB |
Output is correct |
21 |
Correct |
353 ms |
607816 KB |
Output is correct |
22 |
Correct |
369 ms |
607816 KB |
Output is correct |
23 |
Correct |
391 ms |
608072 KB |
Output is correct |
24 |
Correct |
364 ms |
607756 KB |
Output is correct |
25 |
Correct |
361 ms |
607868 KB |
Output is correct |
26 |
Correct |
368 ms |
607816 KB |
Output is correct |
27 |
Correct |
359 ms |
607716 KB |
Output is correct |
28 |
Correct |
343 ms |
607888 KB |
Output is correct |
29 |
Correct |
348 ms |
607748 KB |
Output is correct |
30 |
Correct |
386 ms |
607944 KB |
Output is correct |
31 |
Correct |
985 ms |
622260 KB |
Output is correct |
32 |
Correct |
715 ms |
612492 KB |
Output is correct |
33 |
Correct |
922 ms |
620268 KB |
Output is correct |
34 |
Correct |
833 ms |
618476 KB |
Output is correct |
35 |
Correct |
958 ms |
623736 KB |
Output is correct |
36 |
Correct |
1034 ms |
621880 KB |
Output is correct |
37 |
Correct |
893 ms |
616948 KB |
Output is correct |
38 |
Correct |
908 ms |
618476 KB |
Output is correct |
39 |
Correct |
774 ms |
616376 KB |
Output is correct |
40 |
Correct |
774 ms |
616376 KB |
Output is correct |
41 |
Correct |
798 ms |
618680 KB |
Output is correct |
42 |
Correct |
679 ms |
616404 KB |
Output is correct |
43 |
Correct |
447 ms |
615352 KB |
Output is correct |
44 |
Correct |
802 ms |
618236 KB |
Output is correct |
45 |
Correct |
703 ms |
617728 KB |
Output is correct |
46 |
Correct |
747 ms |
616632 KB |
Output is correct |
47 |
Correct |
585 ms |
616588 KB |
Output is correct |
48 |
Correct |
639 ms |
615960 KB |
Output is correct |
49 |
Correct |
651 ms |
616120 KB |
Output is correct |
50 |
Correct |
611 ms |
617332 KB |
Output is correct |
51 |
Correct |
726 ms |
616192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3342 ms |
681320 KB |
Output is correct |
2 |
Correct |
4768 ms |
668324 KB |
Output is correct |
3 |
Correct |
3306 ms |
712392 KB |
Output is correct |
4 |
Correct |
3316 ms |
678656 KB |
Output is correct |
5 |
Correct |
4637 ms |
662664 KB |
Output is correct |
6 |
Correct |
4582 ms |
669352 KB |
Output is correct |
7 |
Correct |
3012 ms |
714848 KB |
Output is correct |
8 |
Correct |
3095 ms |
678740 KB |
Output is correct |
9 |
Correct |
2829 ms |
668704 KB |
Output is correct |
10 |
Correct |
4112 ms |
663752 KB |
Output is correct |
11 |
Correct |
2723 ms |
668820 KB |
Output is correct |
12 |
Correct |
2795 ms |
663584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4396 ms |
678576 KB |
Output is correct |
2 |
Execution timed out |
5082 ms |
635660 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
333 ms |
607816 KB |
Output is correct |
2 |
Correct |
331 ms |
607732 KB |
Output is correct |
3 |
Correct |
387 ms |
607720 KB |
Output is correct |
4 |
Correct |
341 ms |
607740 KB |
Output is correct |
5 |
Correct |
352 ms |
607816 KB |
Output is correct |
6 |
Correct |
349 ms |
607884 KB |
Output is correct |
7 |
Correct |
346 ms |
607816 KB |
Output is correct |
8 |
Correct |
368 ms |
607824 KB |
Output is correct |
9 |
Correct |
364 ms |
607816 KB |
Output is correct |
10 |
Correct |
365 ms |
608072 KB |
Output is correct |
11 |
Correct |
362 ms |
607860 KB |
Output is correct |
12 |
Correct |
351 ms |
607820 KB |
Output is correct |
13 |
Correct |
318 ms |
607724 KB |
Output is correct |
14 |
Correct |
335 ms |
607816 KB |
Output is correct |
15 |
Correct |
329 ms |
607736 KB |
Output is correct |
16 |
Correct |
311 ms |
607896 KB |
Output is correct |
17 |
Correct |
314 ms |
607816 KB |
Output is correct |
18 |
Correct |
315 ms |
607816 KB |
Output is correct |
19 |
Correct |
320 ms |
607852 KB |
Output is correct |
20 |
Correct |
353 ms |
607824 KB |
Output is correct |
21 |
Correct |
353 ms |
607816 KB |
Output is correct |
22 |
Correct |
369 ms |
607816 KB |
Output is correct |
23 |
Correct |
391 ms |
608072 KB |
Output is correct |
24 |
Correct |
364 ms |
607756 KB |
Output is correct |
25 |
Correct |
361 ms |
607868 KB |
Output is correct |
26 |
Correct |
368 ms |
607816 KB |
Output is correct |
27 |
Correct |
359 ms |
607716 KB |
Output is correct |
28 |
Correct |
343 ms |
607888 KB |
Output is correct |
29 |
Correct |
348 ms |
607748 KB |
Output is correct |
30 |
Correct |
386 ms |
607944 KB |
Output is correct |
31 |
Correct |
985 ms |
622260 KB |
Output is correct |
32 |
Correct |
715 ms |
612492 KB |
Output is correct |
33 |
Correct |
922 ms |
620268 KB |
Output is correct |
34 |
Correct |
833 ms |
618476 KB |
Output is correct |
35 |
Correct |
958 ms |
623736 KB |
Output is correct |
36 |
Correct |
1034 ms |
621880 KB |
Output is correct |
37 |
Correct |
893 ms |
616948 KB |
Output is correct |
38 |
Correct |
908 ms |
618476 KB |
Output is correct |
39 |
Correct |
774 ms |
616376 KB |
Output is correct |
40 |
Correct |
774 ms |
616376 KB |
Output is correct |
41 |
Correct |
798 ms |
618680 KB |
Output is correct |
42 |
Correct |
679 ms |
616404 KB |
Output is correct |
43 |
Correct |
447 ms |
615352 KB |
Output is correct |
44 |
Correct |
802 ms |
618236 KB |
Output is correct |
45 |
Correct |
703 ms |
617728 KB |
Output is correct |
46 |
Correct |
747 ms |
616632 KB |
Output is correct |
47 |
Correct |
585 ms |
616588 KB |
Output is correct |
48 |
Correct |
639 ms |
615960 KB |
Output is correct |
49 |
Correct |
651 ms |
616120 KB |
Output is correct |
50 |
Correct |
611 ms |
617332 KB |
Output is correct |
51 |
Correct |
726 ms |
616192 KB |
Output is correct |
52 |
Correct |
627 ms |
630960 KB |
Output is correct |
53 |
Correct |
620 ms |
627548 KB |
Output is correct |
54 |
Correct |
629 ms |
626516 KB |
Output is correct |
55 |
Correct |
774 ms |
621684 KB |
Output is correct |
56 |
Correct |
766 ms |
623636 KB |
Output is correct |
57 |
Correct |
782 ms |
617912 KB |
Output is correct |
58 |
Correct |
749 ms |
621128 KB |
Output is correct |
59 |
Correct |
678 ms |
623472 KB |
Output is correct |
60 |
Correct |
671 ms |
617912 KB |
Output is correct |
61 |
Correct |
401 ms |
625916 KB |
Output is correct |
62 |
Correct |
662 ms |
630712 KB |
Output is correct |
63 |
Correct |
677 ms |
625336 KB |
Output is correct |
64 |
Correct |
730 ms |
623000 KB |
Output is correct |
65 |
Correct |
731 ms |
618584 KB |
Output is correct |
66 |
Correct |
786 ms |
616756 KB |
Output is correct |
67 |
Correct |
475 ms |
613728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
333 ms |
607816 KB |
Output is correct |
2 |
Correct |
331 ms |
607732 KB |
Output is correct |
3 |
Correct |
387 ms |
607720 KB |
Output is correct |
4 |
Correct |
341 ms |
607740 KB |
Output is correct |
5 |
Correct |
352 ms |
607816 KB |
Output is correct |
6 |
Correct |
349 ms |
607884 KB |
Output is correct |
7 |
Correct |
346 ms |
607816 KB |
Output is correct |
8 |
Correct |
368 ms |
607824 KB |
Output is correct |
9 |
Correct |
364 ms |
607816 KB |
Output is correct |
10 |
Correct |
365 ms |
608072 KB |
Output is correct |
11 |
Correct |
362 ms |
607860 KB |
Output is correct |
12 |
Correct |
351 ms |
607820 KB |
Output is correct |
13 |
Correct |
318 ms |
607724 KB |
Output is correct |
14 |
Correct |
335 ms |
607816 KB |
Output is correct |
15 |
Correct |
329 ms |
607736 KB |
Output is correct |
16 |
Correct |
311 ms |
607896 KB |
Output is correct |
17 |
Correct |
314 ms |
607816 KB |
Output is correct |
18 |
Correct |
315 ms |
607816 KB |
Output is correct |
19 |
Correct |
320 ms |
607852 KB |
Output is correct |
20 |
Correct |
353 ms |
607824 KB |
Output is correct |
21 |
Correct |
353 ms |
607816 KB |
Output is correct |
22 |
Correct |
369 ms |
607816 KB |
Output is correct |
23 |
Correct |
391 ms |
608072 KB |
Output is correct |
24 |
Correct |
364 ms |
607756 KB |
Output is correct |
25 |
Correct |
361 ms |
607868 KB |
Output is correct |
26 |
Correct |
368 ms |
607816 KB |
Output is correct |
27 |
Correct |
359 ms |
607716 KB |
Output is correct |
28 |
Correct |
343 ms |
607888 KB |
Output is correct |
29 |
Correct |
348 ms |
607748 KB |
Output is correct |
30 |
Correct |
386 ms |
607944 KB |
Output is correct |
31 |
Correct |
985 ms |
622260 KB |
Output is correct |
32 |
Correct |
715 ms |
612492 KB |
Output is correct |
33 |
Correct |
922 ms |
620268 KB |
Output is correct |
34 |
Correct |
833 ms |
618476 KB |
Output is correct |
35 |
Correct |
958 ms |
623736 KB |
Output is correct |
36 |
Correct |
1034 ms |
621880 KB |
Output is correct |
37 |
Correct |
893 ms |
616948 KB |
Output is correct |
38 |
Correct |
908 ms |
618476 KB |
Output is correct |
39 |
Correct |
774 ms |
616376 KB |
Output is correct |
40 |
Correct |
774 ms |
616376 KB |
Output is correct |
41 |
Correct |
798 ms |
618680 KB |
Output is correct |
42 |
Correct |
679 ms |
616404 KB |
Output is correct |
43 |
Correct |
447 ms |
615352 KB |
Output is correct |
44 |
Correct |
802 ms |
618236 KB |
Output is correct |
45 |
Correct |
703 ms |
617728 KB |
Output is correct |
46 |
Correct |
747 ms |
616632 KB |
Output is correct |
47 |
Correct |
585 ms |
616588 KB |
Output is correct |
48 |
Correct |
639 ms |
615960 KB |
Output is correct |
49 |
Correct |
651 ms |
616120 KB |
Output is correct |
50 |
Correct |
611 ms |
617332 KB |
Output is correct |
51 |
Correct |
726 ms |
616192 KB |
Output is correct |
52 |
Correct |
3342 ms |
681320 KB |
Output is correct |
53 |
Correct |
4768 ms |
668324 KB |
Output is correct |
54 |
Correct |
3306 ms |
712392 KB |
Output is correct |
55 |
Correct |
3316 ms |
678656 KB |
Output is correct |
56 |
Correct |
4637 ms |
662664 KB |
Output is correct |
57 |
Correct |
4582 ms |
669352 KB |
Output is correct |
58 |
Correct |
3012 ms |
714848 KB |
Output is correct |
59 |
Correct |
3095 ms |
678740 KB |
Output is correct |
60 |
Correct |
2829 ms |
668704 KB |
Output is correct |
61 |
Correct |
4112 ms |
663752 KB |
Output is correct |
62 |
Correct |
2723 ms |
668820 KB |
Output is correct |
63 |
Correct |
2795 ms |
663584 KB |
Output is correct |
64 |
Correct |
4396 ms |
678576 KB |
Output is correct |
65 |
Execution timed out |
5082 ms |
635660 KB |
Time limit exceeded |
66 |
Halted |
0 ms |
0 KB |
- |