QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#766023 | #9569. Subway | ucup-team5217 | WA | 7ms | 134468kb | C++23 | 4.6kb | 2024-11-20 15:57:54 | 2024-11-20 15:57:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
// const double inf=1e18;
// const double eps=1e-9;
// struct line{
// double k,b;int num;
// line(double x=0,double y=0,int z=0):k(x),b(y),num(z){}
// double get(ll x){if(fabs(k)==inf) return b;return k*x+b;}
// };
// bool cmp(line a,line b,ll x){
// double y1=a.get(x),y2=b.get(x);
// return (fabs(y1-y2)>eps)?(y1>y2):(a.num<b.num);
// }
struct line{
ll k,b;
line(ll x=0,ll y=0):k(x),b(y){}
ll get(ll x){return k*x+b;}
};
bool cmp(line a,line b,ll x){
double y1=a.get(x),y2=b.get(x);
return y1<y2;
}
struct lc{
#define ls(x) tr[x].l
#define rs(x) tr[x].r
int xl,xr;
struct node{
int l,r;line ln;
bool isempty=true;
}tr[4000010];int tot=1;
void intt(int l,int r){
xl=l,xr=r;
}
void modify(int p,int l,int r,int L,int R,line res){
int mid=(l+r)>>1;
if(L<=l&&r<=R){
if(tr[p].isempty){
tr[p].isempty=false;
tr[p].ln=res;
return ;
}
if(l==r){
if(cmp(res,tr[p].ln,l)) tr[p].ln=res;
return ;
}
else if(cmp(res,tr[p].ln,mid)) swap(tr[p].ln,res);
if(cmp(res,tr[p].ln,l)) {if(!ls(p)) ls(p)=++tot;modify(ls(p),l,mid,L,R,res);}
else if(cmp(res,tr[p].ln,r)) {if(!rs(p)) rs(p)=++tot;modify(rs(p),mid+1,r,L,R,res);}
return ;
}
if(mid>=L) {if(!ls(p)) ls(p)=++tot;modify(ls(p),l,mid,L,R,res);}
if(mid<R) {if(!rs(p)) rs(p)=++tot;modify(rs(p),mid+1,r,L,R,res);}
}
void modify(int p,int l,int r,line res){
modify(p,xl,xr,l,r,res);
}
pair<line,bool> query(int p,int l,int r,int pz){
pair<line,bool> res=(p==0||tr[p].isempty)?make_pair(line(),false):make_pair(tr[p].ln,true);
pair<line,bool> sres=make_pair(line(),false);
if(l==r) return res;
int mid=(l+r)>>1;
if(pz<=mid) sres=query(ls(p),l,mid,pz);
else sres=query(rs(p),mid+1,r,pz);
if(!res.second) return sres;
if(!sres.second) return res;
return cmp(res.first,sres.first,pz)?res:sres;
}
pair<line,bool> query(int p,int pz){
return query(p,xl,xr,pz);
}
int getrt(){
return ++tot;
}
};
lc lct;
void solve(){
int n,k;cin>>n>>k;
vector<int> rt(n+1);
lct.intt(1,1000000);
for(int i=1;i<=n;i++) rt[i]=lct.getrt();
vector<ll> a(k+1);
vector<ll> b(k+1);
for(int i=1;i<=k;i++) cin>>a[i];
for(int i=1;i<=k;i++) cin>>b[i];
int tot=0;
vector<vector<pair<int,int>>> pot(n+1);
vector<int> zt(200010);
vector<int> xian(200010);
vector<vector<pair<int,int>>> ve(200010);
for(int i=1;i<=k;i++){
int num;
cin>>num;
int pre=0;cin>>pre;pot[pre].push_back({++tot,i});
zt[tot]=pre;xian[tot]=i;
for(int j=2;j<=num;j++){
int len,v;cin>>len>>v;
pot[v].push_back({++tot,i});
zt[tot]=v;xian[tot]=i;
ve[tot-1].push_back({tot,len});
// ve[tot].push_back({tot-1,len});
}
}
for(int i=1;i<=n;i++) {
sort(pot[i].begin(),pot[i].end(),[&](pair<int,int> x,pair<int,int> y){return a[x.second]<a[y.second];});
int sz=pot[i].size();
}
struct node{
int p;ll len;
bool operator<(const node a)const {
return len>a.len;
}
};
priority_queue<node> qe;
vector<bool> flag(tot+1);
vector<int> ans(n+1,-1);
vector<int> ip(n+1);
for(int i=1;i<=tot;i++){
if(zt[i]==1) qe.push({i,0});
}
int xl=1,xr=1000000;
while(!qe.empty()){
node t=qe.top();qe.pop();
if(flag[t.p]) continue;flag[t.p]=1;
if(ans[zt[t.p]]==-1) ans[zt[t.p]]=t.len;
int wt=zt[t.p];
lct.modify(rt[wt],xl,xr,line(b[xian[t.p]],t.len));
auto [pz,tz]=pot[wt][ip[wt]];
qe.push({pz,a[tz]*b[xian[t.p]]+t.len});
while(ip[wt]<pot[wt].size()&&flag[pot[wt][ip[wt]].first]){
ip[wt]++;
}
if(ip[wt]<pot[wt].size()){
auto [p,t]=pot[wt][ip[wt]];
pair<line,bool> res=lct.query(rt[wt],b[t]);
if(res.second) qe.push({p,res.first.get(a[t])});
}
for(auto [v,w]:ve[t.p]){
if(flag[v]) continue;
qe.push({v,w+t.len});
}
}
for(int i=2;i<=n;i++) cout<<ans[i]<<' ';
cout<<'\n';
}
int main(){
ios::sync_with_stdio(0),cin.tie(0);
int _ = 1;
while(_--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 134200kb
input:
6 3 1 5 1 5 5 1 3 1 2 2 3 3 3 5 1 2 1 4 3 3 4 5 4 6
output:
2 5 21 14 18
result:
ok 5 number(s): "2 5 21 14 18"
Test #2:
score: 0
Accepted
time: 7ms
memory: 134468kb
input:
6 3 1 5 1 5 5 1 5 1 2 2 100 3 100 6 1 4 5 1 100 2 4 3 100 5 1 4 2 3 1 5
output:
2 31 43 37 136
result:
ok 5 number(s): "2 31 43 37 136"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 134356kb
input:
5 9 278281 70119 511791 834898 25300 63487 609134 236836 394497 835557 287345 579404 879128 636344 306393 569430 152565 47119 2 3 823004250 4 2 1 25427550 3 2 1 15849621 3 2 1 701911826 5 3 5 679672631 3 907176714 2 2 1 817370554 2 2 3 697987914 2 2 4 873900795 2 2 1 814305954 5
output:
817370554 15849621 -793292879 701911826
result:
wrong answer 3rd numbers differ - expected: '80811085745', found: '-793292879'