QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#789434#6660. 택시 여행Chendaqian0 277ms112844kbC++143.9kb2024-11-27 20:20:492024-11-27 20:20:51

Judging History

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

  • [2024-11-27 20:20:51]
  • 评测
  • 测评结果:0
  • 用时:277ms
  • 内存:112844kb
  • [2024-11-27 20:20:49]
  • 提交

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)].first==x) {
		y=min(y,sta[id][tp(id)].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 
*/

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 3ms
memory: 18144kb

input:

2
684124582850 713748627948
74361 256955
0 1 661088

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
733283747618
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

ok 3 lines

Test #2:

score: 7
Accepted
time: 3ms
memory: 20196kb

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: 7
Accepted
time: 2ms
memory: 18156kb

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

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
Accepted
time: 3ms
memory: 20200kb

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

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: 7
Accepted
time: 2ms
memory: 20476kb

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

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: 7
Accepted
time: 3ms
memory: 16380kb

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

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
1446847771547
1245326093057
924349900475
1046486123707
1063981383357
864751505059
1159443240947
824076089025
1448542597977
1486181926466
1488465960086
1424780088987
1478403270966
1303312410681
1485431478966
1135576549657
1412080059777...

result:

ok 21 lines

Test #11:

score: 7
Accepted
time: 3ms
memory: 20196kb

input:

20
286866076510 666296858783 319893290745 436172872006 579306725182 388780143357 429085643976 163864091991 334402956892 573150791451 971047548996 924353133556 82495144441 364862686518 76783079529 74022380610 978776791995 17833817791 637808249822 150520055702
705613 111460 694926 702547 748042 671482...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
1345583882860
995125125260
815198043938
1295987956432
1034264067144
888082221934
1247814963646
1225117709350
631676569994
1289347270738
404306893004
1347095564962
373415155864
1441975557454
1167058795516
1091947224281
1373264198836
795244013911
1127743556434
se...

result:

ok 21 lines

Test #12:

score: 7
Accepted
time: 0ms
memory: 18436kb

input:

20
161996998737 15089127085 28063038428 574601167323 736141386895 762192247356 788118187801 956063872362 580983462657 839554694910 471536078792 781164874294 363054673222 809510755913 153755418459 78171544930 969593469579 864779185396 408120998971 610129629325
933618 563940 506188 824442 64614 396381...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
1870873819056
1340292002469
2180029603234
1667979150565
2084831816447
1131232525437
1898452835615
1742994070672
2139665843266
1042857179175
2148449164384
1856727805178
2077059488718
1931794896836
1753987714167
1864830429393
1705470391803
1529058594761
197326523...

result:

ok 21 lines

Test #13:

score: 0
Wrong Answer
time: 0ms
memory: 18224kb

input:

20
443174843835 295023765677 175861678382 805210665445 724299682774 889923334441 967560897715 857729286838 7238459275 901083586058 887820756720 681912091803 886476957360 821901344613 222491154905 602669810322 953890359316 822857333786 674877086360 498973934687
505612 0 0 0 913180 49780 0 0 0 0 0 0 0...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
1032546415198
561660971139
1032546415198
945673790751
1032546415198
1032546415198
637744453675
1032546415198
901966161411
1032546415198
1032546415198
1032546415198
1032546415198
1032546415198
1032546415198
1032546415198
608216207263
1032546415198
737522649521
s...

result:

wrong answer 2nd lines differ - expected: '737522649521', found: '1032546415198'

Subtask #2:

score: 0
Wrong Answer

Test #31:

score: 8
Accepted
time: 260ms
memory: 88928kb

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
3269286229765
3273106480907
3287227043365
3335909595067
3361857042147
3364657567217
338173015...

result:

ok 100001 lines

Test #32:

score: 8
Accepted
time: 277ms
memory: 89444kb

input:

99999
199936403206 387848228799 134551775973 379377394692 83082074622 879859342494 648173966597 944650644236 499996263229 902471096917 590863268927 40584929392 906714919013 233728229536 286705399400 944576541664 998941389868 610718110168 422760120374 346110411150 812871715907 273865436932 3195132627...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
697799158816
929607027922
1018095086086
1584613641145
1877765365665
2239699168305
2438089294735
2832345576485
2927526977455
2931605531105
3195571528127
3387289232535
3446336905209
3460262616504
3466765570662
3469379135670
3491001700992
3497511229992
35078529774...

result:

ok 100000 lines

Test #33:

score: 8
Accepted
time: 233ms
memory: 101592kb

input:

100000
56998 11671 13811 25717 14858 88240 42443 83814 1000000000000 76043 96812 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 96423 8620 1000000000000 1000000000000 21485 33558 27910 1000000000000 1000000000000 1000000000000 1000000000000 88572 61826 1000000000000 22580 8911...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
350836056998
1268196151308
1761927177655
1764058173393
1823989948523
2593985186768
3180555709767
3397318276233
3865405999596
4662149904880
5500125621852
5885446768602
6399152631492
6942124201722
7571623906662
7578166841232
7924285399671
8079299773002
8229842213...

result:

ok 100001 lines

Test #34:

score: 8
Accepted
time: 269ms
memory: 107616kb

input:

100000
14710 1000000000000 25745 978 1000000000000 62317 22444 1000000000000 8347 1000000000000 33719 65677 98665 62278 1000000000000 1000000000000 37800 67542 58652 1000000000000 1000000000000 25465 12743 31814 1000000000000 92966 22056 1000000000000 1067 24490 9396 1000000000000 17174 19345 31055 ...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
881904014710
1542423014710
2233996657305
3033138260851
3818801903853
3910348508435
4546837711921
5257126450163
6187656014214
6382291457118
6984889464797
7158062625549
7640143939170
8471766190219
9461415324613
9768735329401
10038031058401
10588178773274
10854900...

result:

ok 100001 lines

Test #35:

score: 8
Accepted
time: 242ms
memory: 106756kb

input:

94827
22402 62109 33267 89192 1000000000000 34994 26802 11762 1000000000000 58525 1000000000000 1000000000000 1000000000000 86073 31536 30063 1370 54650 53651 9657 1000000000000 1000000000000 1000000000000 23604 38641 56775 26468 43548 33809 74580 1000000000000 1000000000000 92571 1000000000000 1922...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
506781022402
551887022402
1470591218257
1570575007497
2060293538337
2717768285941
3403176200271
3411252151815
3928574534219
4656961037207
5072868294008
6057420432959
6341875872837
7155710378925
7542794991201
7788796331189
8003459897887
8625555376735
93472504396...

result:

ok 94828 lines

Test #36:

score: 8
Accepted
time: 251ms
memory: 110536kb

input:

100000
13783 1000000000000 1000000000000 28609 82477 1000000000000 66631 31765 79413 54284 21977 98114 1000000000000 1000000000000 12294 21853 99221 67993 13506 87091 96991 1000000000000 1000000000000 1000000000000 78773 52607 1000000000000 12382 51767 1000000000000 1000000000000 1000000000000 58422...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
853169013783
1385838013783
1798533013783
1999567439287
2984456582192
3412540869848
3596703831495
3830162229040
4210874262733
4322399313283
5000201557170
5773654147213
6267343716568
6939334324590
7300134285614
7563570355867
7825168269456
8299451274502
9199219091...

result:

ok 100001 lines

Test #37:

score: 8
Accepted
time: 263ms
memory: 112272kb

input:

99013
25311 10149 92055 18621 30464 42738 57404 26228 89765 49821 86564 88474 58867 28911 70528 47489 77906 45409 2235 839 71138 53163 32524 47258 7663 27526 89795 51926 53217 10161 1675 23003 31180 35502 48694 60585 66045 69603 90269 35308 6985 1668 92978 16505 3949 52801 27047 1634 23493 24546 942...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
952085025311
1608027379517
2267132153360
2377639840457
2476220476597
2852709636880
2887654462155
3242135007002
3781302783391
4649627018224
5172774873258
5666844526907
5954087138822
6202983932033
6393508335183
7292230901632
7607428936290
8402727461395
9320371945...

result:

ok 99014 lines

Test #38:

score: 8
Accepted
time: 263ms
memory: 112844kb

input:

100000
41470 86167 38125 18891 51474 6401 24258 23148 98577 49813 31436 14447 76256 34760 17176 16188 52035 91332 30657 51668 70484 42793 98864 97559 75171 84727 82885 37141 61138 36539 63298 95576 91623 15468 94434 99763 32482 67115 88955 32740 2367 72772 41787 92407 85389 64331 7555 69817 2842 351...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
982964041470
1196103914497
1403658537512
2193759186094
2281861885156
2793868331512
2892810762112
3335226688327
3882143411536
4868076587871
4883500449055
5663599882314
6498826935726
7345643961722
7455916435062
7783321540100
8245342199687
8692981681020
8866105595...

result:

ok 100001 lines

Test #39:

score: 0
Wrong Answer
time: 190ms
memory: 84784kb

input:

100000
8692 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 1000000000000 10000000...

output:

secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I
544720008692
1482018008692
1544720008692
1544720008692
1544720008692
1544720008692
1544720008692
1544720008692
1544720008692
1544720008692
1544720008692
1544720008692
1544720008692
1544720008692
1544720008692
1544720008692
1544720008692
1544720008692
1544720008...

result:

wrong answer 24th lines differ - expected: '1544720008692', found: '5544720008692'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Wrong Answer

Test #69:

score: 0
Wrong Answer
time: 105ms
memory: 75144kb

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
107733170
135946343
130487117
138532303
137530068
140308018
155214788
100963534
141225190
146322061
155214788
140079959
155214788
88595323
155214788
100943269
155214788
126560816
139991302
134031282
131618939
155214788
139177284
118529802
128179296
155214788
12...

result:

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

Subtask #5:

score: 0
Wrong Answer

Test #94:

score: 0
Wrong Answer
time: 89ms
memory: 74340kb

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
1562976347774
921368365837
1794585618758
1364101380575
1283579512446
1143631405862
955013898615
1385663895278
1671936250046
1623186689820
1077624511454
969553391708
1365639595070
1516747710774
1871383416926
1567199347334
1623186689820
901601060214
1340392788446...

result:

wrong answer 2nd lines differ - expected: '598598746654', found: '1562976347774'

Subtask #6:

score: 0
Skipped

Dependency #1:

0%