#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#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[2*2*MAX];
int mx[2*2*MAX];
segtree(){
memset(mx,-1,sizeof(mx));
}
void add(int v,int tl,int tr,int pos,int x){
pos+=m;
t[pos].insert(x);
mx[pos]=*t[pos].rbegin();
while(pos>1){
pos/=2;
mx[pos]=max(mx[2*pos],mx[2*pos+1]);
}
}
void del(int v,int tl,int tr,int pos,int x){
pos+=m;
t[pos].erase(t[pos].find(x));
mx[pos]=(t[pos].empty()?-1:*t[pos].rbegin());
while(pos>1){
pos/=2;
mx[pos]=max(mx[2*pos],mx[2*pos+1]);
}
}
int get(int v,int tl,int tr,int l,int r){
l+=m,r+=m+1;
int res=0;
while(l<r){
if(l&1){
res=max(res,mx[l++]);
}
if(r&1){
res=max(res,mx[--r]);
}
l/=2,r/=2;
}
return res;
}
}tree;
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;
// cout<<0<<" "<<l<<" "<<tree.get(1,0,m-1,0,l)<<"\n";
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 |
16 ms |
109136 KB |
Output is correct |
2 |
Correct |
20 ms |
109136 KB |
Output is correct |
3 |
Correct |
17 ms |
109136 KB |
Output is correct |
4 |
Correct |
19 ms |
109136 KB |
Output is correct |
5 |
Correct |
20 ms |
109276 KB |
Output is correct |
6 |
Correct |
20 ms |
105060 KB |
Output is correct |
7 |
Correct |
17 ms |
109136 KB |
Output is correct |
8 |
Correct |
19 ms |
105040 KB |
Output is correct |
9 |
Correct |
18 ms |
105296 KB |
Output is correct |
10 |
Correct |
19 ms |
105040 KB |
Output is correct |
11 |
Correct |
22 ms |
105216 KB |
Output is correct |
12 |
Correct |
24 ms |
105088 KB |
Output is correct |
13 |
Correct |
19 ms |
104992 KB |
Output is correct |
14 |
Correct |
24 ms |
105040 KB |
Output is correct |
15 |
Correct |
28 ms |
105196 KB |
Output is correct |
16 |
Correct |
30 ms |
105028 KB |
Output is correct |
17 |
Correct |
29 ms |
105040 KB |
Output is correct |
18 |
Correct |
37 ms |
105032 KB |
Output is correct |
19 |
Correct |
38 ms |
105040 KB |
Output is correct |
20 |
Correct |
36 ms |
105116 KB |
Output is correct |
21 |
Correct |
34 ms |
105040 KB |
Output is correct |
22 |
Correct |
38 ms |
105296 KB |
Output is correct |
23 |
Correct |
38 ms |
105032 KB |
Output is correct |
24 |
Correct |
41 ms |
105032 KB |
Output is correct |
25 |
Correct |
33 ms |
105092 KB |
Output is correct |
26 |
Correct |
38 ms |
104968 KB |
Output is correct |
27 |
Correct |
30 ms |
105040 KB |
Output is correct |
28 |
Correct |
35 ms |
105188 KB |
Output is correct |
29 |
Correct |
37 ms |
105040 KB |
Output is correct |
30 |
Correct |
31 ms |
105076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
109136 KB |
Output is correct |
2 |
Correct |
20 ms |
109136 KB |
Output is correct |
3 |
Correct |
17 ms |
109136 KB |
Output is correct |
4 |
Correct |
19 ms |
109136 KB |
Output is correct |
5 |
Correct |
20 ms |
109276 KB |
Output is correct |
6 |
Correct |
20 ms |
105060 KB |
Output is correct |
7 |
Correct |
17 ms |
109136 KB |
Output is correct |
8 |
Correct |
19 ms |
105040 KB |
Output is correct |
9 |
Correct |
18 ms |
105296 KB |
Output is correct |
10 |
Correct |
19 ms |
105040 KB |
Output is correct |
11 |
Correct |
22 ms |
105216 KB |
Output is correct |
12 |
Correct |
24 ms |
105088 KB |
Output is correct |
13 |
Correct |
19 ms |
104992 KB |
Output is correct |
14 |
Correct |
24 ms |
105040 KB |
Output is correct |
15 |
Correct |
28 ms |
105196 KB |
Output is correct |
16 |
Correct |
30 ms |
105028 KB |
Output is correct |
17 |
Correct |
29 ms |
105040 KB |
Output is correct |
18 |
Correct |
37 ms |
105032 KB |
Output is correct |
19 |
Correct |
38 ms |
105040 KB |
Output is correct |
20 |
Correct |
36 ms |
105116 KB |
Output is correct |
21 |
Correct |
34 ms |
105040 KB |
Output is correct |
22 |
Correct |
38 ms |
105296 KB |
Output is correct |
23 |
Correct |
38 ms |
105032 KB |
Output is correct |
24 |
Correct |
41 ms |
105032 KB |
Output is correct |
25 |
Correct |
33 ms |
105092 KB |
Output is correct |
26 |
Correct |
38 ms |
104968 KB |
Output is correct |
27 |
Correct |
30 ms |
105040 KB |
Output is correct |
28 |
Correct |
35 ms |
105188 KB |
Output is correct |
29 |
Correct |
37 ms |
105040 KB |
Output is correct |
30 |
Correct |
31 ms |
105076 KB |
Output is correct |
31 |
Correct |
435 ms |
119368 KB |
Output is correct |
32 |
Correct |
426 ms |
109752 KB |
Output is correct |
33 |
Correct |
408 ms |
115576 KB |
Output is correct |
34 |
Correct |
364 ms |
115736 KB |
Output is correct |
35 |
Correct |
428 ms |
119248 KB |
Output is correct |
36 |
Correct |
440 ms |
119180 KB |
Output is correct |
37 |
Correct |
357 ms |
114004 KB |
Output is correct |
38 |
Correct |
389 ms |
113924 KB |
Output is correct |
39 |
Correct |
333 ms |
113592 KB |
Output is correct |
40 |
Correct |
365 ms |
113584 KB |
Output is correct |
41 |
Correct |
290 ms |
113848 KB |
Output is correct |
42 |
Correct |
238 ms |
113600 KB |
Output is correct |
43 |
Correct |
126 ms |
111788 KB |
Output is correct |
44 |
Correct |
375 ms |
113848 KB |
Output is correct |
45 |
Correct |
267 ms |
113848 KB |
Output is correct |
46 |
Correct |
295 ms |
113708 KB |
Output is correct |
47 |
Correct |
187 ms |
113336 KB |
Output is correct |
48 |
Correct |
231 ms |
113344 KB |
Output is correct |
49 |
Correct |
288 ms |
113480 KB |
Output is correct |
50 |
Correct |
214 ms |
113604 KB |
Output is correct |
51 |
Correct |
299 ms |
113556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1904 ms |
169956 KB |
Output is correct |
2 |
Correct |
2636 ms |
160080 KB |
Output is correct |
3 |
Correct |
1666 ms |
206388 KB |
Output is correct |
4 |
Correct |
2107 ms |
175848 KB |
Output is correct |
5 |
Correct |
2797 ms |
162132 KB |
Output is correct |
6 |
Correct |
2757 ms |
162416 KB |
Output is correct |
7 |
Correct |
1377 ms |
208028 KB |
Output is correct |
8 |
Correct |
1280 ms |
178204 KB |
Output is correct |
9 |
Correct |
1469 ms |
168040 KB |
Output is correct |
10 |
Correct |
2078 ms |
163096 KB |
Output is correct |
11 |
Correct |
1491 ms |
162048 KB |
Output is correct |
12 |
Correct |
1490 ms |
163084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2138 ms |
171592 KB |
Output is correct |
2 |
Execution timed out |
5068 ms |
132928 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
109136 KB |
Output is correct |
2 |
Correct |
20 ms |
109136 KB |
Output is correct |
3 |
Correct |
17 ms |
109136 KB |
Output is correct |
4 |
Correct |
19 ms |
109136 KB |
Output is correct |
5 |
Correct |
20 ms |
109276 KB |
Output is correct |
6 |
Correct |
20 ms |
105060 KB |
Output is correct |
7 |
Correct |
17 ms |
109136 KB |
Output is correct |
8 |
Correct |
19 ms |
105040 KB |
Output is correct |
9 |
Correct |
18 ms |
105296 KB |
Output is correct |
10 |
Correct |
19 ms |
105040 KB |
Output is correct |
11 |
Correct |
22 ms |
105216 KB |
Output is correct |
12 |
Correct |
24 ms |
105088 KB |
Output is correct |
13 |
Correct |
19 ms |
104992 KB |
Output is correct |
14 |
Correct |
24 ms |
105040 KB |
Output is correct |
15 |
Correct |
28 ms |
105196 KB |
Output is correct |
16 |
Correct |
30 ms |
105028 KB |
Output is correct |
17 |
Correct |
29 ms |
105040 KB |
Output is correct |
18 |
Correct |
37 ms |
105032 KB |
Output is correct |
19 |
Correct |
38 ms |
105040 KB |
Output is correct |
20 |
Correct |
36 ms |
105116 KB |
Output is correct |
21 |
Correct |
34 ms |
105040 KB |
Output is correct |
22 |
Correct |
38 ms |
105296 KB |
Output is correct |
23 |
Correct |
38 ms |
105032 KB |
Output is correct |
24 |
Correct |
41 ms |
105032 KB |
Output is correct |
25 |
Correct |
33 ms |
105092 KB |
Output is correct |
26 |
Correct |
38 ms |
104968 KB |
Output is correct |
27 |
Correct |
30 ms |
105040 KB |
Output is correct |
28 |
Correct |
35 ms |
105188 KB |
Output is correct |
29 |
Correct |
37 ms |
105040 KB |
Output is correct |
30 |
Correct |
31 ms |
105076 KB |
Output is correct |
31 |
Correct |
435 ms |
119368 KB |
Output is correct |
32 |
Correct |
426 ms |
109752 KB |
Output is correct |
33 |
Correct |
408 ms |
115576 KB |
Output is correct |
34 |
Correct |
364 ms |
115736 KB |
Output is correct |
35 |
Correct |
428 ms |
119248 KB |
Output is correct |
36 |
Correct |
440 ms |
119180 KB |
Output is correct |
37 |
Correct |
357 ms |
114004 KB |
Output is correct |
38 |
Correct |
389 ms |
113924 KB |
Output is correct |
39 |
Correct |
333 ms |
113592 KB |
Output is correct |
40 |
Correct |
365 ms |
113584 KB |
Output is correct |
41 |
Correct |
290 ms |
113848 KB |
Output is correct |
42 |
Correct |
238 ms |
113600 KB |
Output is correct |
43 |
Correct |
126 ms |
111788 KB |
Output is correct |
44 |
Correct |
375 ms |
113848 KB |
Output is correct |
45 |
Correct |
267 ms |
113848 KB |
Output is correct |
46 |
Correct |
295 ms |
113708 KB |
Output is correct |
47 |
Correct |
187 ms |
113336 KB |
Output is correct |
48 |
Correct |
231 ms |
113344 KB |
Output is correct |
49 |
Correct |
288 ms |
113480 KB |
Output is correct |
50 |
Correct |
214 ms |
113604 KB |
Output is correct |
51 |
Correct |
299 ms |
113556 KB |
Output is correct |
52 |
Correct |
280 ms |
131000 KB |
Output is correct |
53 |
Correct |
231 ms |
125624 KB |
Output is correct |
54 |
Correct |
232 ms |
125132 KB |
Output is correct |
55 |
Correct |
286 ms |
121784 KB |
Output is correct |
56 |
Correct |
265 ms |
124092 KB |
Output is correct |
57 |
Correct |
262 ms |
118388 KB |
Output is correct |
58 |
Correct |
279 ms |
118580 KB |
Output is correct |
59 |
Correct |
250 ms |
120788 KB |
Output is correct |
60 |
Correct |
246 ms |
115128 KB |
Output is correct |
61 |
Correct |
111 ms |
123200 KB |
Output is correct |
62 |
Correct |
287 ms |
127928 KB |
Output is correct |
63 |
Correct |
325 ms |
122600 KB |
Output is correct |
64 |
Correct |
350 ms |
120248 KB |
Output is correct |
65 |
Correct |
260 ms |
115948 KB |
Output is correct |
66 |
Correct |
264 ms |
113848 KB |
Output is correct |
67 |
Correct |
150 ms |
111056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
109136 KB |
Output is correct |
2 |
Correct |
20 ms |
109136 KB |
Output is correct |
3 |
Correct |
17 ms |
109136 KB |
Output is correct |
4 |
Correct |
19 ms |
109136 KB |
Output is correct |
5 |
Correct |
20 ms |
109276 KB |
Output is correct |
6 |
Correct |
20 ms |
105060 KB |
Output is correct |
7 |
Correct |
17 ms |
109136 KB |
Output is correct |
8 |
Correct |
19 ms |
105040 KB |
Output is correct |
9 |
Correct |
18 ms |
105296 KB |
Output is correct |
10 |
Correct |
19 ms |
105040 KB |
Output is correct |
11 |
Correct |
22 ms |
105216 KB |
Output is correct |
12 |
Correct |
24 ms |
105088 KB |
Output is correct |
13 |
Correct |
19 ms |
104992 KB |
Output is correct |
14 |
Correct |
24 ms |
105040 KB |
Output is correct |
15 |
Correct |
28 ms |
105196 KB |
Output is correct |
16 |
Correct |
30 ms |
105028 KB |
Output is correct |
17 |
Correct |
29 ms |
105040 KB |
Output is correct |
18 |
Correct |
37 ms |
105032 KB |
Output is correct |
19 |
Correct |
38 ms |
105040 KB |
Output is correct |
20 |
Correct |
36 ms |
105116 KB |
Output is correct |
21 |
Correct |
34 ms |
105040 KB |
Output is correct |
22 |
Correct |
38 ms |
105296 KB |
Output is correct |
23 |
Correct |
38 ms |
105032 KB |
Output is correct |
24 |
Correct |
41 ms |
105032 KB |
Output is correct |
25 |
Correct |
33 ms |
105092 KB |
Output is correct |
26 |
Correct |
38 ms |
104968 KB |
Output is correct |
27 |
Correct |
30 ms |
105040 KB |
Output is correct |
28 |
Correct |
35 ms |
105188 KB |
Output is correct |
29 |
Correct |
37 ms |
105040 KB |
Output is correct |
30 |
Correct |
31 ms |
105076 KB |
Output is correct |
31 |
Correct |
435 ms |
119368 KB |
Output is correct |
32 |
Correct |
426 ms |
109752 KB |
Output is correct |
33 |
Correct |
408 ms |
115576 KB |
Output is correct |
34 |
Correct |
364 ms |
115736 KB |
Output is correct |
35 |
Correct |
428 ms |
119248 KB |
Output is correct |
36 |
Correct |
440 ms |
119180 KB |
Output is correct |
37 |
Correct |
357 ms |
114004 KB |
Output is correct |
38 |
Correct |
389 ms |
113924 KB |
Output is correct |
39 |
Correct |
333 ms |
113592 KB |
Output is correct |
40 |
Correct |
365 ms |
113584 KB |
Output is correct |
41 |
Correct |
290 ms |
113848 KB |
Output is correct |
42 |
Correct |
238 ms |
113600 KB |
Output is correct |
43 |
Correct |
126 ms |
111788 KB |
Output is correct |
44 |
Correct |
375 ms |
113848 KB |
Output is correct |
45 |
Correct |
267 ms |
113848 KB |
Output is correct |
46 |
Correct |
295 ms |
113708 KB |
Output is correct |
47 |
Correct |
187 ms |
113336 KB |
Output is correct |
48 |
Correct |
231 ms |
113344 KB |
Output is correct |
49 |
Correct |
288 ms |
113480 KB |
Output is correct |
50 |
Correct |
214 ms |
113604 KB |
Output is correct |
51 |
Correct |
299 ms |
113556 KB |
Output is correct |
52 |
Correct |
1904 ms |
169956 KB |
Output is correct |
53 |
Correct |
2636 ms |
160080 KB |
Output is correct |
54 |
Correct |
1666 ms |
206388 KB |
Output is correct |
55 |
Correct |
2107 ms |
175848 KB |
Output is correct |
56 |
Correct |
2797 ms |
162132 KB |
Output is correct |
57 |
Correct |
2757 ms |
162416 KB |
Output is correct |
58 |
Correct |
1377 ms |
208028 KB |
Output is correct |
59 |
Correct |
1280 ms |
178204 KB |
Output is correct |
60 |
Correct |
1469 ms |
168040 KB |
Output is correct |
61 |
Correct |
2078 ms |
163096 KB |
Output is correct |
62 |
Correct |
1491 ms |
162048 KB |
Output is correct |
63 |
Correct |
1490 ms |
163084 KB |
Output is correct |
64 |
Correct |
2138 ms |
171592 KB |
Output is correct |
65 |
Execution timed out |
5068 ms |
132928 KB |
Time limit exceeded |
66 |
Halted |
0 ms |
0 KB |
- |