QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#448694 | #190. New Home | JohnAlfnov | 0 | 922ms | 100636kb | C++14 | 3.0kb | 2024-06-19 22:33:33 | 2024-06-19 22:33:34 |
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);
}
pi[n+1].first=1e9;
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(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;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 7ms
memory: 60360kb
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: 11ms
memory: 60376kb
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: 15ms
memory: 60088kb
input:
1 1 1 100000000 1 1 1 1 1
output:
99999999
result:
ok single line: '99999999'
Test #4:
score: 5
Accepted
time: 7ms
memory: 60112kb
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: 3ms
memory: 60388kb
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: 4ms
memory: 60068kb
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: 11ms
memory: 60132kb
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:
43829125 30654163 67266906 -1 -1 55411188 -1 36326041 18873552 -1 -1 36117977 40458180 -1 47497457 63643466 66382719 60322370 89865895 28250652
result:
wrong answer 1st lines differ - expected: '10979904', found: '43829125'
Subtask #2:
score: 0
Wrong Answer
Test #34:
score: 0
Wrong Answer
time: 190ms
memory: 71564kb
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:
93895945 -1 -1 -1 98997714 63822987 -1 57910260 -1 -1 -1 -1 72048654 69059384 97473685 51060710 -1 53880802 79272231 -1 54652817 69434596 63484180 75695174 80858840 -1 -1 79949334 -1 -1 -1 -1 83415811 -1 95598610 -1 -1 -1 -1 -1 84086160 66063776 -1 98745104 -1 67781579 -1 95164120 -1 77191908 787305...
result:
wrong answer 1st lines differ - expected: '4187955', found: '93895945'
Subtask #3:
score: 0
Wrong Answer
Test #55:
score: 0
Wrong Answer
time: 922ms
memory: 100636kb
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:
92274859 63062564 55815190 78586139 50014632 64460299 76974191 79117594 88891337 66036042 53255996 50726007 85942201 91442786 86721341 92224793 69004972 53792992 64926552 68094871 58374771 90201814 85366935 63558995 82649919 55411696 64465227 63076998 94625265 87359507 56988779 64919986 84253416 907...
result:
wrong answer 1st lines differ - expected: '92572089', found: '92274859'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%