QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#448691 | #190. New Home | JohnAlfnov | 0 | 1171ms | 100660kb | C++14 | 3.0kb | 2024-06-19 22:30:12 | 2024-06-19 22:30:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int x[300005],t[300005],a[300005],b[300005],pp[300005];
int aa[600005],ans[300005],rt[300005];
pair<int,int>pi[300005];
vector<int>r1[600005],r2[600005];
vector<pair<int,int>>wz[600005];
set<int>se[300005];
int rr[300005],an[300005];
int sm[1200005];
int n,k,q;
int cz[300005];
void build(int l,int r,int o){
if(l==r){
if(cz[l])sm[o]=rr[l];
else sm[o]=n+1;
return;
}
int mid=(l+r)>>1;
build(l,mid,o<<1);
build(mid+1,r,o<<1|1);
sm[o]=min(sm[o<<1],sm[o<<1|1]);
}
void add(int l,int r,int o,int x,int y){
if(l==r){
if(cz[x])sm[o]=y;
else sm[o]=n+1;
return;
}
int mid=(l+r)>>1;
if(x<=mid)add(l,mid,o<<1,x,y);
else add(mid+1,r,o<<1|1,x,y);
sm[o]=min(sm[o<<1],sm[o<<1|1]);
}
int query(int l,int r,int o,int ll,int rr){
if(l>=ll&&r<=rr)return sm[o];
int mid=(l+r)>>1,ans=INT_MAX;
if(mid>=ll)ans=min(ans,query(l,mid,o<<1,ll,rr));
if(mid<rr)ans=min(ans,query(mid+1,r,o<<1|1,ll,rr));
return ans;
}
void gai(int x,int y){
if(!cz[x])cz[x]=1;
add(1,n,1,x,y);
}
void unmo(int x){
cz[x]=0;add(1,n,1,x,0);
}
int main(){
scanf("%d%d%d",&n,&k,&q);
int tt=0;
for(int i=1;i<=n;++i){
scanf("%d%d%d%d",&x[i],&t[i],&a[i],&b[i]);
aa[++tt]=a[i],aa[++tt]=b[i]+1;
pi[i]=make_pair(x[i],i);
}
sort(pi+1,pi+n+1);
for(int i=1;i<=n;++i){
rt[i]=t[pi[i].second];
pp[pi[i].second]=i;
}
for(int i=1;i<=n;++i)t[i]=rt[i];
sort(aa+1,aa+tt+1);
tt=unique(aa+1,aa+tt+1)-aa-1;
for(int i=1;i<=n;++i){
int z1=lower_bound(aa+1,aa+tt+1,a[i])-aa;
int z2=lower_bound(aa+1,aa+tt+1,b[i]+1)-aa;
r1[z1].emplace_back(pp[i]);
r2[z2].emplace_back(pp[i]);
}
for(int i=1;i<=q;++i){
int l,y;
scanf("%d%d",&l,&y);
int wy=upper_bound(aa+1,aa+tt+1,y)-aa-1;
if(!wy||wy==tt){
ans[i]=-1;
continue;
}
wz[wy].emplace_back(l,i);
}
set<int>ss;
for(int i=1;i<=n;++i)rr[i]=0,cz[i]=0;
build(1,n,1);
for(int i=1;i<tt;++i){
for(auto cu:r2[i]){
ss.erase(an[t[cu]]);
auto it=se[t[cu]].find(cu);
se[t[cu]].erase(it++);
if(it==se[t[cu]].end())an[t[cu]]=rr[cu];
else gai(*it,rr[cu]),rr[*it]=rr[cu];
unmo(cu);rr[cu]=0;
if(an[t[cu]])ss.emplace(an[t[cu]]);
}
for(auto cu:r1[i]){
if(an[t[cu]])ss.erase(an[t[cu]]);
auto it=se[t[cu]].emplace(cu).first;
auto ti=it;++ti;
rr[cu]=(ti==se[t[cu]].end()?rr[*ti]:an[t[cu]]);
gai(cu,rr[cu]);
if(ti==se[t[cu]].end())an[t[cu]]=cu;
else gai(*ti,cu),rr[*ti]=cu;
ss.emplace(an[t[cu]]);
}
for(auto pii:wz[i]){
if((signed)ss.size()<k){
ans[pii.second]=-1;
continue;
}
int l=pii.first;
int L=0,R=1e8;
auto it=ss.end();--it;
int mn=*it;
while(L<=R){
int mid=(L+R)>>1;
int wz=upper_bound(pi+1,pi+n+1,make_pair(l+mid,n))-pi;
int qz=(wz>n?n+1:query(1,n,1,wz,n));
int fl=1;
if(!qz)fl=0;
else if(qz<=n&&-min(pi[qz].first,mn)<l-mid)fl=0;
if(!fl)L=mid+1;
else R=mid-1;
}
ans[pii.second]=L;
}
}
for(int i=1;i<=q;++i)printf("%d\n",ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 8ms
memory: 60076kb
input:
4 2 4 3 1 1 10 9 2 2 4 7 2 5 7 4 1 8 10 5 3 5 6 5 9 1 10
output:
4 2 -1 -1
result:
ok 4 lines
Test #2:
score: 5
Accepted
time: 7ms
memory: 60372kb
input:
2 1 3 1 1 1 4 1 1 2 6 1 3 1 5 1 7
output:
0 0 -1
result:
ok 3 lines
Test #3:
score: 5
Accepted
time: 12ms
memory: 60108kb
input:
1 1 1 100000000 1 1 1 1 1
output:
99999999
result:
ok single line: '99999999'
Test #4:
score: 5
Accepted
time: 12ms
memory: 60336kb
input:
20 10 20 1 6 1 1 1 9 1 1 1 3 1 1 1 5 1 1 1 2 1 1 1 7 1 1 1 7 1 1 1 8 1 1 1 3 1 1 1 8 1 1 1 5 1 1 1 2 1 1 1 10 1 1 1 7 1 1 1 7 1 1 1 10 1 1 1 1 1 1 1 4 1 1 1 6 1 1 1 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 20 lines
Test #5:
score: 5
Accepted
time: 12ms
memory: 60116kb
input:
20 10 1 45 4 53 54 75 8 56 60 65 3 87 100 56 7 93 97 36 3 64 91 63 4 93 94 71 2 45 97 67 5 57 65 34 6 7 52 96 9 43 95 83 5 63 92 24 3 55 99 7 10 38 52 59 10 59 100 43 5 5 21 38 9 72 82 72 2 1 64 22 7 50 81 74 5 88 89 84 1 25 29 41 48
output:
-1
result:
ok single line: '-1'
Test #6:
score: 5
Accepted
time: 8ms
memory: 60332kb
input:
1 10 20 58 4 59 59 36 88 80 47 56 65 74 45 99 4 17 2 13 46 92 38 82 2 42 47 40 40 30 9 13 41 14 77 61 33 20 73 89 3 89 100 83 100 28 59
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
result:
ok 20 lines
Test #7:
score: 0
Wrong Answer
time: 8ms
memory: 60336kb
input:
20 4 20 61418457 4 33932551 98975124 50805588 3 56616927 66076460 44262243 1 58029464 59272268 34981593 4 10760710 89302332 58741675 3 60670049 77700264 33623668 3 63722438 67824726 62526450 2 43078579 75611393 4274055 2 14095759 73162733 87374777 4 83277088 91743411 94571186 3 89842706 99458411 124...
output:
17589315 30654163 0 -1 -1 7115244 -1 26200391 18873588 -1 -1 18691055 40458180 -1 15028975 0 0 2204062 0 28250686
result:
wrong answer 1st lines differ - expected: '10979904', found: '17589315'
Subtask #2:
score: 0
Wrong Answer
Test #34:
score: 0
Wrong Answer
time: 217ms
memory: 71640kb
input:
60000 400 60000 36444793 284 3080519 96564525 76562130 166 22994125 59743695 76399902 168 29694545 59255380 66355790 132 10949454 89347938 40903435 35 29985718 66394219 83300910 368 17240174 54080010 85941830 363 31462093 87304647 73742613 40 29005856 54988711 27852051 29 6132393 88092297 52011498 2...
output:
6041842 -1 -1 -1 937627 63822987 -1 57910260 -1 -1 -1 -1 27886687 30878403 2464102 51060710 -1 46056985 79272231 -1 45284970 69434596 36453607 24240167 80858840 -1 -1 19986007 -1 -1 -1 -1 16521976 -1 4339177 -1 -1 -1 -1 -1 15851627 66063776 -1 1190237 -1 32156208 -1 95164120 -1 77191908 78730572 780...
result:
wrong answer 1st lines differ - expected: '4187955', found: '6041842'
Subtask #3:
score: 0
Wrong Answer
Test #55:
score: 0
Wrong Answer
time: 1171ms
memory: 100660kb
input:
300000 60000 300000 52373645 39403 1 100000000 43175904 13875 1 100000000 55098270 40348 1 100000000 69248668 7569 1 100000000 69220659 14654 1 100000000 92585410 38487 1 100000000 41202983 28786 1 100000000 47874378 18728 1 100000000 7254419 14009 1 100000000 94592111 3845 1 100000000 19140558 2773...
output:
7425072 63062564 55815190 78586139 50017298 64460299 22725740 79117594 88891337 66036042 53255996 48973924 13757730 91442786 12978590 92224793 30694959 45906939 34773379 68094871 41325160 90201814 14332996 63558995 17050012 55411696 35234704 36622933 94625265 12340424 56988779 34779945 15446515 9074...
result:
wrong answer 1st lines differ - expected: '92572089', found: '7425072'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%