QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#783771#6660. 택시 여행beiwen0 171ms38892kbC++202.5kb2024-11-26 11:44:022024-11-26 11:44:02

Judging History

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

  • [2024-11-26 11:44:02]
  • 评测
  • 测评结果:0
  • 用时:171ms
  • 内存:38892kb
  • [2024-11-26 11:44:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
#define int long long
using ll=long long;
const ll inf=1e18;
ll n, a[N], b[N];
ll sz[N], vis[N], rt, S, mn, ft[N], fw[N];
vector<pair<ll, ll> > e[N];
void findrt(ll u, ll f) {
	sz[u]=1;
	ll res=0;
	for(auto t:e[u]) {
		int v=t.first; 
		if(v==f||vis[v]) continue ;
		findrt(v, u);
		sz[u]+=sz[v];
		res=max(res, sz[v]);
	}
	res=max(res, S-sz[u]);
	if(res<mn) mn=res, rt=u;
}
ll dis[N];
void pdfs(int u, int fa) {
	for(auto t:e[u]) {
		ll v=t.first, w=t.second;
		if(v==fa||vis[v]) continue ;
		dis[v]=dis[u]+w;
		pdfs(v, u);
	}
}
void dfs(int u) {
	vis[u]=1;
	sz[u]=S+1;
	dis[u]=0; pdfs(u, 0);
	for(auto t:e[u]) {
		ll v=t.first, w=t.second;
		if(!vis[v]) {
			S=sz[v]; rt=0; mn=inf;
			findrt(v, 0);
			ft[rt]=u; fw[rt]=dis[rt];
			dfs(rt);
		} 
	}
}
struct Node{
	ll x, y;
};
long double K(Node A, Node B) {
	return 1.0L*(A.y-B.y)/(A.x-B.x);
}
struct TB{
	vector<Node> A;
	void Ins(Node p) {
		if(!A.empty()&&A.back().x==p.x) {
			p.y=min(p.y, A.back().y);
			A.pop_back();
		}
		while(A.size()>1&&K(A[A.size()-1], A[A.size()-2])<=K(A[A.size()-1], p)) A.pop_back();
		A.push_back(p);
	}
	ll qry(ll k) {
		if(A.empty()) return inf;
		k=-k;
		ll L=1, R=A.size()-1, now=0;
		while(L<=R) {
			ll mid=L+R>>1;
			if(K(A[mid], A[mid-1])>k) now=mid, L=mid+1;
			else R=mid-1;
		}
		return A[now].y-k*A[now].x;
	}
} tb[N];
ll f[N];
ll get(int u) {
	if(u==1) return 0; ll res=inf;
	for(ll i=u, d=0; i; d+=fw[i], i=ft[i]) {
		res=min(res, tb[i].qry(d));
	}
	return res;
}
void change(int u) {
	f[u]=get(u);
//	cout<<f[u]<<"\n";
	for(ll i=u, d=0; i; d+=fw[i], i=ft[i]) {
		tb[i].Ins(Node{b[u], f[u]+a[u]+b[u]*d});
	}
}

int p[N];
#undef int
vector<long long> travel(vector<long long> A, vector<int> B, vector<int> U,
 vector<int> V, vector<int> W) {
	n=A.size();
	for(int i=1; i<=n; i++)
		a[i]=A[i-1], b[i]=B[i-1];
	for(int i=1; i<n; i++) {
		ll u=U[i-1]+1, v=V[i-1]+1, w=W[i-1];
		e[u].push_back({v, w});
		e[v].push_back({u, w});
	}
	S=n; mn=inf; rt=0;
	findrt(1, 0);
	dfs(rt);
	for(int i=1; i<=n; i++) p[i]=i;
	sort(p+1, p+1+n, [&](ll x, ll y){
		return b[x]>b[y];
	});
	for(int i=1; i<=n; i++) {
		change(p[i]);
	}
	vector<ll> res(n-1);
	for(int i=2; i<=n; i++) res[i-2]=get(i);
	return res;
}
/*
int main() {
	vector<ll> res=travel({10, 5, 13, 4, 3}, {10, 7, 5, 9, 1}, {1, 0, 3, 2}, {0, 2, 2, 4}, {1, 5, 10, 3});
	for(ll v:res) cout<<v<<" "; 
}
*/
/*
5
10 5 13 4 3
10 7 5 9 1
1 0 1
0 2 5
3 2 10
2 4 3
*/

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

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: 0ms
memory: 9960kb

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: 1ms
memory: 9944kb

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

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: 1ms
memory: 8184kb

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: 1ms
memory: 9940kb

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: 0ms
memory: 7904kb

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
Wrong Answer
time: 1ms
memory: 9936kb

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
1212228321942
984941935977
871429515267
660178785567
secret: XBNN6R0Jnospxlfz11GWxd4ldkzb0I

result:

wrong answer 2nd lines differ - expected: '757655550012', found: '1212228321942'

Subtask #2:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 171ms
memory: 38892kb

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
2408842387198
2893332914530
3258156482902
3195016753906
3350951812118
3300820841298
3364509959586
3415780069404
3704618570120
3649333978678
3653154229820
3631393165078
3582710613376
3701286814736
3698486289666
371555887...

result:

wrong answer 5th lines differ - expected: '2353514637869', found: '2408842387198'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Wrong Answer

Test #69:

score: 0
Wrong Answer
time: 64ms
memory: 29168kb

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:

wrong answer 1841st lines differ - expected: '16477221', found: '16487141'

Subtask #5:

score: 0
Wrong Answer

Test #94:

score: 0
Wrong Answer
time: 64ms
memory: 28908kb

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:

wrong answer 48315th lines differ - expected: '570853708214', found: '598598746654'

Subtask #6:

score: 0
Skipped

Dependency #1:

0%