QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#789471 | #6660. 택시 여행 | Chendaqian | 0 | 243ms | 88016kb | C++14 | 3.9kb | 2024-11-27 20:28:10 | 2024-11-27 20:28:17 |
Judging History
answer
#include <vector>
#include<bits/stdc++.h>
#define ll long long
#define i128 __int128
using namespace std;
const int N=1e5+10,lgN=20;
const i128 lnf=1e18+10;
int n;
i128 a[N],b[N];
vector<pair<int,i128> > e[N];
i128 dp[N];
int sd[N],bt[N][lgN];
i128 dis[N][lgN];
bool vis[N];
int tot,sum[N],mxsum[N];
void getrt(int x,int fa,int &rt) {
sum[x]=1,mxsum[x]=0;
for(auto v:e[x]) if(v.first!=fa&&!vis[v.first]) {
getrt(v.first,x,rt);
sum[x]+=sum[v.first];
mxsum[x]=max(mxsum[x],sum[v.first]);
}
mxsum[x]=max(mxsum[x],tot-sum[x]);
if(mxsum[x]<mxsum[rt]) rt=x;
}
void fixsum(int x,int fa) {
sum[x]=1;
for(auto v:e[x]) if(v.first!=fa&&!vis[v.first]) {
fixsum(v.first,x);
sum[x]+=sum[v.first];
}
}
int st[N],stt;
void getdis(int dep,int x,int fa,i128 d) {
st[++stt]=x;
dis[x][dep]=d;
for(auto v:e[x]) if(v.first!=fa&&!vis[v.first]) {
getdis(dep,v.first,x,d+v.second);
}
}
void calc(int dep,int rt) {
sd[rt]=dep;
st[stt=1]=rt;
dis[rt][dep]=0;
bt[rt][dep]=rt;
for(auto x:e[rt]) if(!vis[x.first]) {
int hd=stt;
getdis(dep,x.first,rt,x.second);
for(int i=hd+1;i<=stt;i++) bt[st[i]][dep]=rt;
}
}
void solve(int dep,int x) {
assert(dep<20);
int rt=0;
getrt(x,0,rt);
// cerr<<x<<' '<<rt<<"\n";
fixsum(rt,0);
vis[rt]=1;
for(auto v:e[rt]) if(!vis[v.first]) {
tot=sum[v.first];
solve(dep+1,v.first);
}
vis[rt]=0;
calc(dep,rt);
}
#define vec pair<i128,i128>
vec operator + (vec x,vec y) {
return make_pair(x.first+y.first,x.second+y.second);
}
vec operator - (vec x,vec y) {
return make_pair(x.first-y.first,x.second-y.second);
}
i128 operator ^ (vec x,vec y) {
return x.first*y.second-x.second*y.first;
}
vector<vec> sta[N];
#define tp(id) (sta[id].size())
#define X(i,j) (sta[i][j].first)
#define Y(i,j) (sta[i][j].second)
bool check(vec x,vec y) {
return (x^y)>0;
}
void update(int id,i128 x,i128 y) {
auto cur=make_pair(x,y);
if(tp(id)>0&&sta[id][tp(id)-1].first==x) {
y=min(y,sta[id][tp(id)-1].second);
sta[id].pop_back();
}
while(tp(id)>1&&
check(sta[id][tp(id)-1]-sta[id][tp(id)-2],
cur-sta[id][tp(id)-1])) {
sta[id].pop_back();
}
sta[id].emplace_back(cur);
}
// bool deb;
i128 query(int id,i128 k) {
if(sta[id].empty()) return lnf;
int res=0,l=1,r=tp(id)-1;
vec tmp=make_pair(1,k);
while(l<=r) {
int mid=(l+r)/2;
if(check(sta[id][mid]-sta[id][mid-1],tmp)) res=mid,l=mid+1;
else r=mid-1;
}
i128 ans=sta[id][res].second-k*sta[id][res].first;
return ans;
}
void Upd(int x) {
for(int i=sd[x];i>=1;i--) {
update(bt[x][i],-b[x],dp[x]+a[x]+b[x]*dis[x][i]);
}
}
i128 Qry(int x) {
i128 Ans=lnf;
for(int i=sd[x];i>=1;i--) {
Ans=min(Ans,query(bt[x][i],dis[x][i]));
}
return Ans;
}
int p[N];
i128 Ans[N];
std::vector<long long> travel(std::vector<long long> A,
std::vector<int> B, std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
n=A.size();
for(int i=1;i<=n;i++) a[i]=A[i-1];
for(int i=1;i<=n;i++) b[i]=B[i-1];
for(int i=0;i<n-1;i++) {
e[U[i]+1].emplace_back(V[i]+1,W[i]);
e[V[i]+1].emplace_back(U[i]+1,W[i]);
}
for(int i=1;i<=n;i++) dp[i]=lnf,p[i]=i;
dp[1]=0;
sort(p+1,p+1+n,[&](int x,int y) {
return b[x]>b[y];
});
tot=n;
mxsum[0]=0x3f3f3f3f;
// cerr<<"OK\n";
solve(1,1);
// cerr<<"OK\n";
// for(int i=1;i<=n;i++,cerr<<'\n')
// for(int j=sd[i];j>=1;j--) cerr<<bt[i][j]<<' ';
for(int i=1;i<=n;i++) {
// cerr<<p[i]<<":\n";
dp[p[i]]=min(dp[p[i]],Qry(p[i]));
// cerr<<"OK\n";
Upd(p[i]);
// cerr<<dp[p[i]]<<"\n";
}
// for(int i=1;i<=n;i++) {
// for(auto j:sta[i]) cerr<<"("<<j.first<<','<<j.second<<")";
// cerr<<"\n";
// }
// deb=1;
for(int i=1;i<=n;i++) Ans[i]=Qry(i);
vector<ll> RES(n-1);
for(int i=2;i<=n;i++) RES[i-2]=Ans[i];
return RES;
}
/*
cd "D:\OI\4 NOI\Counting_And_DP\QOJ6660\cpp"
g++ taxi.cpp grader.cpp -o taxi -std=c++14 -Wall -O2
./taxi
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 0ms
memory: 18436kb
input:
2 684124582850 713748627948 74361 256955 0 1 661088
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 733283747618 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 3 lines
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 20244kb
input:
3 251115773325 363097865287 358609487841 826785 213106 914768 0 1 851938 2 0 231697
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 1318583197942 1549512318252 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
wrong answer 2nd lines differ - expected: '955485332655', found: '1318583197942'
Subtask #2:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 243ms
memory: 88016kb
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 4661076069806 3644913768745 3610496858827 4516258784270 4500409985770 4441725835942 4389981402346 4343388022086 4284193251702 5782060682093 5464940867911 5415831270498 5419224819961 5431768190898 5475013161201 5498062416821 5500550138176 551571580...
result:
wrong answer 3rd lines differ - expected: '1636760433058', found: '4661076069806'
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Wrong Answer
Test #69:
score: 0
Wrong Answer
time: 120ms
memory: 74804kb
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 386327769 414254350 395368043 379139603 397124202 414254350 414254350 414254350 398731321 364542233 414254350 365229613 310298827 414254350 372793122 388086720 414254350 402589466 317653399 414254350 414254350 414254350 396612592 395208451 389808284 414254350 3...
result:
wrong answer 2nd lines differ - expected: '16705757', found: '386327769'
Subtask #5:
score: 0
Wrong Answer
Test #94:
score: 0
Wrong Answer
time: 110ms
memory: 74392kb
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 9405065494538 8993487489096 8980134253902 8371206991087 10146737472639 10146737472639 9399226497678 8973815879700 9067281340620 8458965463477 9876455428512 9133136953743 9239174597067 10146737472639 10146737472639 8458965463477 8458965463477 8625344067033 83874...
result:
wrong answer 2nd lines differ - expected: '598598746654', found: '9405065494538'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%