QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#783889 | #6660. 택시 여행 | ushg8877 | 0 | 0ms | 0kb | C++14 | 2.4kb | 2024-11-26 12:10:33 | 2024-11-26 12:10:33 |
answer
#include<bits/stdc++.h>
// #include"grader.cpp"
using namespace std;
#define ll long long
const int MAXN=2e5+5;
const ll V=1e12,inf=1e18;
struct line{
ll k,b;
line(ll _k=-1,ll _b=0){k=_k,b=_b;}
ll f(ll x){return k==-1?inf:k*x+b;}
};
struct lichaos{
int ls[MAXN*400],rs[MAXN*400],tot=0;line val[MAXN*400];
void insert(line L,int &id,ll l=0,ll r=V){
if(L.k==-1||l>r) return;
if(!id) id=++tot;
ll mid=(l+r)>>1;
if(L.f(mid)<val[id].f(mid)) swap(L,val[id]);
if(L.k==-1) return;
if(L.k>=val[id].k) insert(L,ls[id],l,mid);
else insert(L,rs[id],mid+1,r);
}
ll ask(ll x,int id,ll l=0,ll r=V){
if(id==0||val[id].k==-1) return inf;
ll mid=(l+r)>>1;
return min(val[id].f(x),x<=mid?ask(x,ls[id],l,mid)
:ask(x,rs[id],mid+1,r));
}
}T;
vector<array<int,2> > edg[MAXN];
int siz[MAXN],msiz[MAXN],n,m,rt,mson;bool vis[MAXN];
ll a[MAXN],b[MAXN];
struct DAFEN{
vector<array<ll,2> > vec[MAXN];int rt[MAXN];
void get_size(int u,int fa){
siz[u]=msiz[u]=1;
for(auto e:edg[u]) if(e[0]!=fa&&!vis[e[0]]){
get_size(e[0],u);
siz[u]+=siz[e[0]];
msiz[u]=max(msiz[u],siz[e[0]]);
}
msiz[u]=max(msiz[u],m-siz[u]);
if(msiz[mson]>msiz[u]) mson=u;
}
void get_val(int u,int fa,int rt,ll w){
vec[u].push_back({rt,w});
siz[u]=msiz[u]=1;
for(auto e:edg[u]) if(e[0]!=fa&&!vis[e[0]]){
get_val(e[0],u,rt,w+e[1]);
siz[u]+=siz[e[0]];
msiz[u]=max(msiz[u],siz[e[0]]);
}
msiz[u]=max(msiz[u],m-siz[u]);
if(msiz[mson]>msiz[u]) mson=u;
}
void build(int rt){
vis[rt]=true;
get_val(rt,-1,rt,0);
for(auto e:edg[rt]) if(!vis[e[0]]){
m=siz[e[0]];mson=n;
get_size(e[0],rt);build(mson);
}
}
void build(){
msiz[n]=1e9;mson=n;m=n;
get_size(0,-1);
build(mson);
}
void insert(int x,ll v){
for(auto r:vec[x]) T.insert(line(b[x],a[x]+v+b[x]*r[1]),rt[r[0]]);
}
ll query(int x){
ll ans=1e18;
for(auto r:vec[x]) ans=min(ans,T.ask(r[1],rt[r[0]]));
return ans;
}
}dfz;
vector<ll> travel(vector<ll> A,vector<int> B,vector<int> U,
vector<int> V,vector<int> W){
n=A.size();
for(int i=0;i<n;i++) a[i]=A[i],b[i]=B[i];
for(int i=0;i<n-1;i++){
edg[U[i]].push_back({V[i],W[i]});
edg[V[i]].push_back({U[i],W[i]});
}
dfz.build();
vector<int> id(n);
for(int i=0;i<n;i++) id[i]=i;
sort(id.begin(),id.end(),[&](int x,int y){
return B[x]>B[y];
});
dfz.insert(0,0);
for(int i=0;i<n;i++) dfz.insert(id[i],dfz.query(id[i]));
vector<ll> ans(n-1);
for(int i=0;i<n-1;i++) ans[i]=dfz.query(i+1);
return ans;
}
详细
Subtask #1:
score: 0
Memory Limit Exceeded
Test #1:
score: 0
Memory Limit Exceeded
input:
2 684124582850 713748627948 74361 256955 0 1 661088
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 733283747618 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
Subtask #2:
score: 0
Memory Limit Exceeded
Test #31:
score: 0
Memory Limit Exceeded
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:
Unauthorized output
result:
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Memory Limit Exceeded
Test #69:
score: 0
Memory Limit Exceeded
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 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 16705757 ...
result:
Subtask #5:
score: 0
Time Limit Exceeded
Test #94:
score: 0
Time Limit Exceeded
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:
Unauthorized output
result:
Subtask #6:
score: 0
Skipped
Dependency #1:
0%