QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#784205 | #6660. 택시 여행 | zero-range | 0 | 112ms | 31292kb | C++23 | 2.9kb | 2024-11-26 14:05:46 | 2024-11-26 14:05:46 |
Judging History
answer
#include<stdio.h>
#include<vector>
#include<algorithm>
#define M 100005
using namespace std;
int n;
long long a[M],W[M],F[M];
int b[M],st[M],tp;
struct Edge{
int x,w;
operator int() const{return x;}
};
vector<Edge> G[M];
struct Line{
long long k,b;
inline long long operator()(long long x) const{return k*x+b;}
};
struct SGT{
struct Node{
int ls,rs;Line s;
} tr[M<<5];
int tot;
void upd(int &x,long long l,long long r,Line u){
if(!x) return tr[x=++tot]={0,0,u},void();
Line &v=tr[x].s;long long mid=l+r>>1;
if(u(mid)<=v(mid)) swap(u,v);
long long ul=u(l),ur=u(r),vl=v(l),vr=v(r);
if(ul>=vl&&ur>=vr) return;
if(ul<=vl&&ur<=vr) return tr[x].s=u,void();
if(ul<=vl) upd(tr[x].ls,l,mid,u);
if(ur<=vr) upd(tr[x].rs,mid+1,r,u);
}
long long que(int x,long long l,long long r,long long k){
if(!x) return 0x7fffffffffffffff;
long long res=tr[x].s(k);
if(l==r) return res;
long long mid=l+r>>1;
if(k<=mid) res=min(res,que(tr[x].ls,l,mid,k));
if(k>mid) res=min(res,que(tr[x].rs,mid+1,r,k));
return res;
}
} sgt;
int sz[M],dep[M],top[M],big[M],f[M],rt[M],fa[M];
void dfs(int x,int fa){
sz[x]=1,dep[x]=dep[fa]+1,f[x]=fa;
for(auto [p,w]:G[x]) if(p!=fa)
W[p]=W[x]+w,dfs(p,x),
sz[x]+=sz[p],(sz[p]>sz[big[x]])&&(big[x]=p);
}
void ctp(int x,int tp){
top[x]=tp;
if(big[x]) ctp(big[x],tp);
for(int p:G[x]) if(p!=big[x]&&p!=f[x])
ctp(p,p);
}
int LCA(int x,int y){
while(top[x]!=top[y]){
if(dep[top[x]]>dep[top[y]]) x=f[top[x]];
else y=f[top[y]];
}
return dep[x]<dep[y]?x:y;
}
long long dis(int x,int y){return W[x]+W[y]-2*W[LCA(x,y)];}
namespace ASD{
int sz[M],all,mn,rt;
bool vis[M];
void frt(int x){
sz[x]=1,vis[x]=1;
int mx=0;
for(int p:G[x]) if(!vis[p])
frt(p),mx=max(mx,sz[p]),sz[x]+=sz[p];
mx=max(mx,all-sz[x]);
if(mx<mn) mn=mx,rt=x;
vis[x]=0;
}
void dfs(int x){
vis[x]=1,sz[x]=1;
for(int p:G[x]) if(!vis[p])
dfs(p),sz[x]+=sz[p];
vis[x]=0;
}
int div(int x){
mn=0x7fffffff,frt(x),x=rt,vis[x]=1;
for(int p:G[x]) if(!vis[p])
dfs(p),all=sz[p],fa[div(p)]=x;
return x;
}
void work(){all=n,div(1);}
}
inline void cal(int x){
for(int t=x;t;t=fa[t]) F[x]=min(F[x],sgt.que(rt[t],1,1e11,dis(x,t)));
}
inline void ins(int x){
for(int t=x;t;t=fa[t]) sgt.upd(rt[t],1,1e11,Line{b[x],b[x]*dis(x,t)+a[x]+F[x]});
}
vector<long long> travel(vector<long long> A,vector<int> B,vector<int> U,vector<int> V,vector<int> W){
n=A.size();
for(int i=1;i<=n;++i) a[i]=A[i-1],b[i]=B[i-1];
for(int i=0;i<n-1;++i){
++U[i],++V[i],
G[U[i]].push_back({V[i],W[i]}),
G[V[i]].push_back({U[i],W[i]});
}
dfs(1,0),ctp(1,1);
ASD::work();
for(int i=1;i<=n;++i) st[i]=i;
sort(st+1,st+n+1,[](int x,int y){return b[x]<b[y];}),tp=n;
while(st[tp]!=1) --tp;
while(tp){
int x=st[tp--];
if(x!=1) F[x]=0x7fffffffffffffff,cal(x);
ins(x);
}
for(int i=2;i<=n;++i) cal(i);
return vector<long long>(F+2,F+n+1);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5904kb
input:
2 684124582850 713748627948 74361 256955 0 1 661088
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 0 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
wrong answer 2nd lines differ - expected: '733283747618', found: '0'
Subtask #2:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 112ms
memory: 31292kb
input:
100000 746699125678 374834842799 250803643493 620187038832 454433387570 406226564003 897157438699 99473514061 734784419618 503968957100 363935477037 277126009840 52078020050 990757079812 847235285349 950784717285 271017141367 861087225700 996035427219 520682200664 282013988419 415183977876 882007771...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 1148030742334 0 0 2353514637869 2672707119337 0 0 0 0 3117708941277 3168979051095 0 3269286229765 3273106480907 3287227043365 3335909595067 3361857042147 3364657567217 3381730150671 3408171419287 3450579049517 0 0 3612738081397 3644630444211 3689458544293 37204...
result:
wrong answer 3rd lines differ - expected: '1636760433058', found: '0'
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Wrong Answer
Test #69:
score: 0
Wrong Answer
time: 57ms
memory: 24184kb
input:
100000 15175010 23519365 21177669 27079342 9089 16784452 29693960 23124925 17048604 10179491 12828214 24992902 8483134 2928073 23807522 7332137 17421520 28460746 1607282 13224363 11900728 11794692 11495061 4687109 23460275 7657982 27417256 16978162 7326803 23083826 24942987 16610314 12147303 2828271...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 0 16705757 0 16705757 0 0 0 0 0 0 16705757 0 0 16705757 16705757 0 0 0 16705757 0 0 16705757 0 0 0 0 16705757 0 0 16705757 0 0 0 16705757 0 0 16705757 0 0 0 0 16705757 0 0 16705757 16705757 16705757 0 0 0 0 0 0 0 0 0 0 0 0 0 16705757 0 0 0 0 16705757 0 16705757...
result:
wrong answer 2nd lines differ - expected: '16705757', found: '0'
Subtask #5:
score: 0
Wrong Answer
Test #94:
score: 0
Wrong Answer
time: 71ms
memory: 24892kb
input:
99281 551670361798 568902251563 418071776626 697635341894 641578820039 117221079324 812766431051 425410617978 663769685693 282144284527 799662290178 749088952784 586626406385 122473825417 459510657357 871705247919 443707710712 735612808044 237919555727 829939639783 122127143240 616906466299 24431898...
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 598598746654 5...
result:
wrong answer 256th lines differ - expected: '598598746654', found: '0'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%