QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#842843#9569. SubwayfryanWA 5ms18116kbC++203.0kb2025-01-04 15:15:392025-01-04 15:15:39

Judging History

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

  • [2025-01-04 15:15:39]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:18116kb
  • [2025-01-04 15:15:39]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
#define int long long

const int inf = 1e18;
namespace LICHAO {
	const int LCB = 7e6;
	int m[LCB],b[LCB],q[LCB];
	int l[LCB],r[LCB],npos = 1;
	void reset() {npos = 1;}
	int create() {
		b[npos] = inf;
		l[npos] = r[npos] = 0;
		return npos++;
	}
	void insert(int i, int cm, int cb, int id, int lo = 0, int hi = 2e9) {
		if (lo+1==hi) {
			if (cm*lo+cb < m[i]*lo+b[i]) {m[i] = cm, b[i] = cb, q[i] = id;}
			return;
		}
		int mid = (lo+hi)/2;
		if (cm*mid+cb < m[i]*mid+b[i]) {swap(cm,m[i]); swap(cb,b[i]); swap(id,q[i]);}
		if (cm==0 && cb==inf) return;
		if (cm*lo+cb < m[i]*lo+b[i]) {
			if (!l[i]) l[i] = create();
			insert(l[i],cm,cb,id,lo,mid);
		} else {
			if (!r[i]) r[i] = create();
			insert(r[i],cm,cb,id,mid,hi);
		}
	}
	array<int,2> query(int i, int x, int lo = 0, int hi = 2e9) {
		if (lo+1 == hi) {return {m[i]*x+b[i],q[i]};}
		int mid = (lo+hi)/2;
		array<int,2> res = {m[i]*x+b[i],q[i]};
		if (x < mid) {if (l[i]) res = min(res, query(l[i],x,lo,mid));}
		else {if (r[i]) res = min(res, query(r[i],x,mid,hi));}
		return res;
	}
}

const int mxn = 4e5+5;

int n,k,a[mxn],b[mxn];
vector<int> x[mxn],w[mxn];
vector<array<int,3>> line[mxn];
vector<int> pos[mxn];
int fp[mxn],lcrt[mxn];
priority_queue<array<int,3>,vector<array<int,3>>,greater<array<int,3>>> dij;
int dist[mxn]; vector<int> dt[mxn];

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	cin>>n>>k;
	for (int i=0; i<k; i++) cin>>a[i];
	for (int i=0; i<k; i++) cin>>b[i];
	for (int i=0; i<k; i++) {
		int p; cin>>p;
		x[i].resize(p);
		w[i].resize(p-1);
		cin>>x[i][0]; --x[i][0];
		for (int j=1; j<p; j++) {
			cin>>w[i][j-1]>>x[i][j];
			--x[i][j];
		}
		pos[i].resize(p);
		dt[i] = vector<int>(p,inf);
	}
	for (int i=0; i<k; i++) {
		for (int j=0; j<sz(x[i]); j++) {
			line[x[i][j]].push_back({a[i],i,j});
		}
	}
	for (int i=0; i<n; i++) {
		sort(all(line[i]));
		for (int j=0; j<sz(line[i]); j++) {
			pos[line[i][j][1]][line[i][j][2]] = j;
		}
	}
	for (int i=0; i<n; i++)
		lcrt[i] = LICHAO::create();
	
	fill(dist,dist+n,inf);	
	for (auto [bv,li,lp] : line[0]) {
		dij.push({0,li,lp});
	}
	while (sz(dij)) {
		auto [d,li,lp] = dij.top(); dij.pop();
		if (dt[li][lp] <= d) continue;
//		cout<<d<<" "<<li<<" "<<lp<<endl;
		dt[li][lp] = d;
		//add line to hull
		int xp = x[li][lp];
		dist[xp] = min(dist[xp],d);
		LICHAO::insert(lcrt[xp],b[li],d,0);
		//go to next line in subway
		if (lp < sz(w[li])) {
			dij.push({d+w[li][lp], li, lp+1});
		}
		//go to next line at station
		while (fp[xp] < sz(line[xp])) {
			auto [av, lj, jp] = line[xp][fp[xp]];
			if (dt[lj][jp] < inf) {
				fp[xp]++;
			} else break;
		}
		if (fp[xp] == sz(line[xp])) continue;
		auto [av,lj,jp] = line[xp][fp[xp]];
		auto [dt,uk] = LICHAO::query(lcrt[xp],av);
		dij.push({dt,lj,jp});
		fp[xp]++;
	}
	for (int i=1; i<n; i++)
		cout<<dist[i]<<" ";
	
	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 17948kb

input:

6 3
1 5 1
5 5 1
3 1 2 2 3 3
3 5 1 2 1 4
3 3 4 5 4 6

output:

2 5 21 14 18 

result:

ok 5 number(s): "2 5 21 14 18"

Test #2:

score: 0
Accepted
time: 5ms
memory: 18092kb

input:

6 3
1 5 1
5 5 1
5 1 2 2 100 3 100 6 1 4
5 1 100 2 4 3 100 5 1 4
2 3 1 5

output:

2 31 43 37 136 

result:

ok 5 number(s): "2 31 43 37 136"

Test #3:

score: 0
Accepted
time: 2ms
memory: 18044kb

input:

5 9
278281 70119 511791 834898 25300 63487 609134 236836 394497
835557 287345 579404 879128 636344 306393 569430 152565 47119
2 3 823004250 4
2 1 25427550 3
2 1 15849621 3
2 1 701911826 5
3 5 679672631 3 907176714 2
2 1 817370554 2
2 3 697987914 2
2 4 873900795 2
2 1 814305954 5

output:

817370554 15849621 80811085745 701911826 

result:

ok 4 number(s): "817370554 15849621 80811085745 701911826"

Test #4:

score: 0
Accepted
time: 5ms
memory: 17964kb

input:

5 10
436148 103565 528276 212202 680282 92724 609031 560815 80390 406327
546832 581372 731920 348686 791433 98906 112247 118131 361076 724950
4 1 213029090 4 415633732 5 581145231 3
2 4 306227294 2
2 1 713116112 4
2 3 99672714 5
2 3 975143846 1
5 4 249118026 5 689334413 1 597093740 2 553624319 3
3 4...

output:

597093740 765908995 213029090 628662822 

result:

ok 4 number(s): "597093740 765908995 213029090 628662822"

Test #5:

score: 0
Accepted
time: 0ms
memory: 18028kb

input:

3 5
696710 837216 390019 431068 960618
589388 829806 692481 154511 282620
2 1 711629163 3
2 1 781784306 3
2 1 686636041 3
2 3 794790206 2
2 1 844212542 2

output:

844212542 686636041 

result:

ok 2 number(s): "844212542 686636041"

Test #6:

score: 0
Accepted
time: 0ms
memory: 18028kb

input:

3 8
344877 101098 328614 735002 476606 635558 573861 261083
964379 333960 25186 276560 258996 683650 765559 582374
2 3 838262394 1
2 2 863940316 3
2 2 476918371 3
3 3 320092619 1 400754003 2
3 3 150885055 2 90507792 1
2 3 190275693 2
2 2 600234969 3
2 2 679446528 3

output:

400754003 29224357199 

result:

ok 2 number(s): "400754003 29224357199"

Test #7:

score: -100
Wrong Answer
time: 2ms
memory: 18116kb

input:

50 52
895514 29433 851800 887860 340384 95967 506578 666268 850660 602220 717255 242039 34055 752012 248567 170469 505996 823344 143369 390858 112988 892365 15368 617804 351619 557340 788960 990487 283825 272924 24678 130649 341049 980236 558990 254726 682005 963825 953074 603477 706464 340694 23541...

output:

632126151 479346918 492618840 3695787776 22624579200 174047740 416387993526 21429733469 15831777447 203893499 522142321620 977566721 279122223 30345963113 804573598 73397618725 6389037892 224856032596 416404080694 75356833904 69909552850 4504114918 13173874327 1104455938 278587376156 136977429637 22...

result:

wrong answer 25th numbers differ - expected: '275720760247', found: '278587376156'