QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#120814#6660. 택시 여행zhouhuanyi#0 776ms374048kbC++116.4kb2023-07-07 11:31:162024-07-04 00:25:17

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 00:25:17]
  • 评测
  • 测评结果:0
  • 用时:776ms
  • 内存:374048kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-07 11:31:16]
  • 提交

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);
}
bool checks(points a,points b,long long d)
{
    return b.y-a.y>=1ll*(b.x-a.x)*d;
}
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 (checks(*it2,*it,-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 (checks(*it2,*it,-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: 30ms
memory: 235904kb

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: 235860kb

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: 24ms
memory: 232900kb

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: 30ms
memory: 232568kb

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: 0
Accepted
time: 19ms
memory: 232488kb

input:

4
201836820267 208957719162 992553400562 566050337171
243994 65303 590123 936951
1 0 259719
0 3 860376
3 2 513584

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
265206697953
537074816507
411763402011
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 5 lines

Test #6:

score: 0
Accepted
time: 24ms
memory: 236072kb

input:

4
440719935569 160237864481 704297665373 767778991240
451998 371509 46564 828427
1 0 861960
1 3 830699
2 3 185693

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
830324131649
1289731282865
1205798418251
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 5 lines

Test #7:

score: 0
Accepted
time: 30ms
memory: 235548kb

input:

5
148262899914 9382086008 622202345986 443806901161 213829280326
178155 503016 333953 572340 461148
0 3 453941
3 2 84057
4 0 171136
3 1 598794

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
335812903839
244109933604
229134758769
178751633994
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 6 lines

Test #8:

score: 0
Accepted
time: 23ms
memory: 235860kb

input:

5
391440982512 969252165920 333946610796 649830522527 902812044171
522045 996458 225429 545971 667483
0 1 701500
0 4 514779
2 1 435377
3 0 919439

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
757655550012
984941935977
871429515267
660178785567
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 6 lines

Test #9:

score: 0
Accepted
time: 20ms
memory: 235660kb

input:

17
315015458526 65513576283 829720084774 654640079244 561177336848 463903843105 496216524512 837433489064 92734412345 807145138979 250511786518 915329126804 373916658654 78276842047 121976569238 432447179015 519384539551
696133 642473 231377 987220 589587 337763 790202 785083 249580 108311 73808 892...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
430639669161
417840567823
403532946274
499079112962
498466070651
495984520010
499402357184
501387707132
498265325456
501233852966
474661031682
494612046266
411867746683
497598865088
499819422548
496976423075
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 18 lines

Test #10:

score: -7
Wrong Answer
time: 23ms
memory: 232452kb

input:

20
764145449871 794297102632 450082553736 427358261877 587251097098 98567356955 15910789509 321286084089 25839798358 969219436118 975479420690 937908953492 410498404545 180209954689 302999489632 849828117651 171771046425 800442975277 295169929534 146003957886
828538 724406 733109 79844 665172 652593...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
1384833390877
871900130923
1468189815605
1245326093057
924349900475
1046486123707
1063981383357
864751505059
1159443240947
824076089025
1470641459547
1486181926466
1488465960086
1436267903541
1478403270966
1303312410681
1485431478966
1135576549657
1412080059777...

result:

wrong answer 4th lines differ - expected: '1446847771547', found: '1468189815605'

Subtask #2:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 608ms
memory: 374048kb

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
3098778933881
3003888852169
3054019822989
3117708941277
3168979051095
3214001638323
3269286229765
3273106480907
3287227043365
3335909595067
3361857042147
3364657567217
338173015...

result:

wrong answer 8th lines differ - expected: '2948215735597', found: '3098778933881'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Wrong Answer

Test #69:

score: 0
Wrong Answer
time: 776ms
memory: 357248kb

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
19723787
18391058
17718875
21812902
17905682
17787443
17939674
18319455
17905682
16817058
17465829
19471956
16817058
17330879
20013067
19417371
19935151
20695746
20302631
19166491
19187357
18452136
21494530
20534369
20417607
17841308
16817058
17012459
18356382
...

result:

wrong answer 2nd lines differ - expected: '16705757', found: '19723787'

Subtask #5:

score: 0
Wrong Answer

Test #94:

score: 29
Accepted
time: 697ms
memory: 356684kb

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:

ok 99282 lines

Test #95:

score: -29
Wrong Answer
time: 735ms
memory: 364928kb

input:

100000
762048253398 544847923340 274220772253 709492519024 93107863549 990677171512 878434244170 777350365410 575870270443 928311965336 349432073756 948390047110 470116186153 495432094032 154258868766 719518553291 580490378718 661863092617 453262793865 191963964294 783054160061 953488248260 99347544...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764692690700
764705621299
7...

result:

wrong answer 21st lines differ - expected: '764692690700', found: '764705621299'

Subtask #6:

score: 0
Skipped

Dependency #1:

0%