QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#120803 | #6660. 택시 여행 | zhouhuanyi# | 0 | 683ms | 372460kb | C++11 | 6.3kb | 2023-07-07 11:24:05 | 2024-07-04 00:25:00 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define N 1000000
#define inf 2e18
#define INF 1e9
using namespace std;
struct node
{
int num,data,snum;
};
struct reads
{
int num;
long long data;
bool operator < (const reads &t)const
{
return data>t.data;
}
};
struct points
{
int x;
long long y;
bool operator < (const points &t)const
{
return x!=t.x?x<t.x:y<t.y;
}
};
int n,cater,length,rt,sx,sy,smz,szt,nums,ds,fa[N+1],b[N+1],sz[N+1],maxp[N+1],ls[N+1],rs[N+1],ps[N+1],ps2[N+1],minn;
long long a[N+1],dis[N+1],depth[N+1];
bool used[N+1],vis[N+1],vst[N+1];
vector<node>E[N+1];
vector<node>ES[N+1];
vector<reads>A[N+1];
vector<reads>B[N+1];
vector<long long>depths[N+1];
set<points>s1[N+1];
set<points>s2[N+1];
priority_queue<reads>q;
void add(int x,int y,int z,int w)
{
E[x].push_back((node){y,z,w}),E[y].push_back((node){x,z,w});
return;
}
void add2(int x,int y,int z)
{
++cater,ES[x].push_back((node){y,z,cater}),ES[y].push_back((node){x,z,cater});
return;
}
void dfs(int x)
{
int nw=0;
vis[x]=1;
for (int i=0;i<E[x].size();++i)
if (!vis[E[x][i].num])
{
dfs(E[x][i].num),++length,add2(length,E[x][i].num,E[x][i].data);
if (nw) add2(length,nw,0);
nw=length;
}
if (nw) add2(x,nw,0);
vis[x]=0;
return;
}
void get_rt(int x)
{
vis[x]=sz[x]=1;
for (int i=0;i<ES[x].size();++i)
if (!used[ES[x][i].snum]&&!vis[ES[x][i].num])
{
get_rt(ES[x][i].num),sz[x]+=sz[ES[x][i].num];
if (max(sz[ES[x][i].num],smz-sz[ES[x][i].num])<minn) minn=max(sz[ES[x][i].num],smz-sz[ES[x][i].num]),sx=x,sy=ES[x][i].num,nums=ES[x][i].snum,ds=ES[x][i].data,szt=sz[ES[x][i].num];
}
vis[x]=0;
return;
}
void dfs2(int x)
{
if (x<=n) depths[x].push_back(depth[x]),A[length].push_back((reads){x,depth[x]});
vis[x]=1;
for (int i=0;i<ES[x].size();++i)
if (!used[ES[x][i].snum]&&!vis[ES[x][i].num])
depth[ES[x][i].num]=depth[x]+ES[x][i].data,dfs2(ES[x][i].num);
vis[x]=0;
return;
}
void dfs3(int x)
{
if (x<=n) depths[x].push_back(depth[x]),B[length].push_back((reads){x,depth[x]});
vis[x]=1;
for (int i=0;i<ES[x].size();++i)
if (!used[ES[x][i].snum]&&!vis[ES[x][i].num])
depth[ES[x][i].num]=depth[x]+ES[x][i].data,dfs3(ES[x][i].num);
vis[x]=0;
return;
}
bool cmp(reads a,reads b)
{
return a.data<b.data;
}
int solve(int x,int y)
{
int d1=smz-szt,d2=szt,nw=++length;
used[nums]=1,depth[x]=ds,depth[y]=0,dfs2(x),dfs3(y),sort(A[nw].begin(),A[nw].end(),cmp),sort(B[nw].begin(),B[nw].end(),cmp);
smz=d1,minn=INF;
if (smz!=1) get_rt(x),ls[nw]=solve(sx,sy);
else ls[nw]=x;
smz=d2,minn=INF;
if (smz!=1) get_rt(y),rs[nw]=solve(sx,sy);
else rs[nw]=y;
fa[ls[nw]]=fa[rs[nw]]=nw;
return nw;
}
bool check(points a,points b,points c)
{
return 1ll*(b.y-a.y)*(c.x-a.x)>=1ll*(c.y-a.y)*(b.x-a.x);
}
void get(int x,int k,long long b)
{
while (s1[x].size()>=2)
{
auto it=s1[x].lower_bound((points){k,b});
if (it!=s1[x].end())
{
auto it2=it;
it2++;
if (it2!=s1[x].end())
{
if (check((points){k,b},*it,*it2)) s1[x].erase(it);
else break;
}
else break;
}
else break;
}
while (s1[x].size()>=2)
{
auto it=s1[x].lower_bound((points){k,b});
if (it!=s1[x].begin())
{
it--;
if (it!=s1[x].begin())
{
auto it2=it;
it2--;
if (check(*it2,*it,(points){k,b})) s1[x].erase(it);
else break;
}
else break;
}
else break;
}
s1[x].insert((points){k,b});
return;
}
void get2(int x,int k,long long b)
{
while (s2[x].size()>=2)
{
auto it=s2[x].lower_bound((points){k,b});
if (it!=s2[x].end())
{
auto it2=it;
it2++;
if (it2!=s2[x].end())
{
if (check((points){k,b},*it,*it2)) s2[x].erase(it);
else break;
}
else break;
}
else break;
}
while (s2[x].size()>=2)
{
auto it=s2[x].lower_bound((points){k,b});
if (it!=s2[x].begin())
{
it--;
if (it!=s2[x].begin())
{
auto it2=it;
it2--;
if (check(*it2,*it,(points){k,b})) s2[x].erase(it);
else break;
}
else break;
}
else break;
}
s2[x].insert((points){k,b});
return;
}
long long query(int x,long long d)
{
if (s1[x].empty()) return inf;
while (s1[x].size()>=2)
{
auto it=s1[x].end();
it--;
auto it2=it;
it2--;
if (check(*it2,*it,(points){1,-d})) s1[x].erase(it);
else break;
}
auto it=s1[x].end();
it--;
return 1ll*(*it).x*d+(*it).y;
}
long long query2(int x,long long d)
{
if (s2[x].empty()) return inf;
while (s2[x].size()>=2)
{
auto it=s2[x].end();
it--;
auto it2=it;
it2--;
if (check(*it2,*it,(points){1,-d})) s2[x].erase(it);
else break;
}
auto it=s2[x].end();
it--;
return 1ll*(*it).x*d+(*it).y;
}
void adder(int x)
{
int y=x,cl;
long long d;
for (int i=(int)(depths[x].size())-1;i>=0;--i)
{
cl=(rs[fa[y]]==y),y=fa[y];
if (!cl) get2(y,b[x],dis[x]+a[x]+1ll*b[x]*depths[x][i]);
else get(y,b[x],dis[x]+a[x]+1ll*b[x]*depths[x][i]);
while (ps[y]<A[y].size()&&vst[A[y][ps[y]].num]) ps[y]++;
if (ps[y]<A[y].size())
{
d=query(y,A[y][ps[y]].data);
if (d<dis[A[y][ps[y]].num]) dis[A[y][ps[y]].num]=d,q.push((reads){A[y][ps[y]].num,d});
}
while (ps2[y]<B[y].size()&&vst[B[y][ps2[y]].num]) ps2[y]++;
if (ps2[y]<B[y].size())
{
d=query2(y,B[y][ps2[y]].data);
if (d<dis[B[y][ps2[y]].num]) dis[B[y][ps2[y]].num]=d,q.push((reads){B[y][ps2[y]].num,d});
}
}
return;
}
void dijkstra()
{
int top;
for (int i=1;i<=n;++i) dis[i]=inf;
dis[1]=0,q.push((reads){1,0});
while (!q.empty())
{
top=q.top().num,q.pop();
if (vst[top]) continue;
vst[top]=1,adder(top);
}
return;
}
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)
{
length=n=A.size();
vector<long long>qry(n-1);
for (int i=1;i<=n;++i) a[i]=A[i-1],b[i]=B[i-1];
for (int i=1;i<=n-1;++i) add(U[i-1]+1,V[i-1]+1,W[i-1],i);
dfs(1);
smz=length,minn=INF,get_rt(1),rt=solve(sx,sy),dijkstra();
for (int i=2;i<=n;++i) qry[i-2]=dis[i];
return qry;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 23ms
memory: 235700kb
input:
2 684124582850 713748627948 74361 256955 0 1 661088
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 733283747618 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 20ms
memory: 232956kb
input:
3 251115773325 363097865287 358609487841 826785 213106 914768 0 1 851938 2 0 231697
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 955485332655 442679377470 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 4 lines
Test #3:
score: 0
Accepted
time: 30ms
memory: 236032kb
input:
3 489998888627 318672977903 70353752652 258347 458793 258657 2 1 156120 0 2 524840
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 665922861747 625589728107 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 4 lines
Test #4:
score: 0
Accepted
time: 24ms
memory: 235720kb
input:
3 737471938521 315388610250 818943569900 726908 666797 564862 0 1 460302 0 2 785280
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 1072069144737 1308298252761 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
ok 4 lines
Test #5:
score: -7
Wrong Answer
time: 32ms
memory: 232392kb
input:
4 201836820267 208957719162 992553400562 566050337171 243994 65303 590123 936951 1 0 259719 0 3 860376 3 2 513584
output:
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I 265206697953 580848556852 411763402011 secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
result:
wrong answer 3rd lines differ - expected: '537074816507', found: '580848556852'
Subtask #2:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 609ms
memory: 372460kb
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 1636760433058 2131282232650 2353514637869 2672707119337 2763307672337 2948215735597 3003888852169 3054019822989 3117708941277 3168979051095 3214001638323 3508164324190 3510527883553 3519264164590 3549383676793 3565437158413 3567169821268 357773249...
result:
wrong answer 14th lines differ - expected: '3269286229765', found: '3508164324190'
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Wrong Answer
Test #69:
score: 0
Wrong Answer
time: 683ms
memory: 370360kb
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 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 20561293 ...
result:
wrong answer 2nd lines differ - expected: '16705757', found: '20561293'
Subtask #5:
score: 0
Wrong Answer
Test #94:
score: 0
Wrong Answer
time: 681ms
memory: 356440kb
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 599096118410 599096118410 599096118410 599096118410 599096118410 599096118410 599096118410 599096118410 599096118410 599096118410 599096118410 599096118410 599096118410 599096118410 599096118410 599096118410 599096118410 599096118410 599096118410 599096118410 5...
result:
wrong answer 2nd lines differ - expected: '598598746654', found: '599096118410'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%