QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#738368#9569. SubwayDeltaxWA 11ms225096kbC++144.2kb2024-11-12 18:52:132024-11-12 18:52:15

Judging History

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

  • [2024-11-12 18:52:15]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:225096kb
  • [2024-11-12 18:52:13]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
#define fi first
#define se second
#define mkp make_pair
#define pb push_back
typedef pair <int, int> pii;

inline int read() {
	int x = 0, f = 0;
	char c = getchar();
	while (!isdigit(c)) {if (c == '-') f = 1; c = getchar();}
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c & 15), c = getchar();
	return f? -x : x;
}

const int MAXN = 2e5;
struct ds {
	priority_queue <pii> q2, d2;
	priority_queue <pii, vector<pii>, greater<pii>> q1, d1;
	inline int size() {return q1.size() - d1.size();}
	pii max() {
	//	assert(*this.size() > 0);
		while (d2.size() && q2.top() == d2.top()) q2.pop(), d2.pop();
		if (q2.size())
			return q2.top();
		return mkp(-1, -1);
	}
	pii min() {
		while (d1.size() && q1.top() == d1.top()) q1.pop(), d1.pop();
		if (q1.size())
			return q1.top();
		return mkp(-1, -1);
	}
	void ins(pii x) {q1.push(x); q2.push(x);}
	void del(pii x) {d1.push(x); d2.push(x);}
}ds[MAXN + 10];


typedef long long LL;
typedef pair<LL, LL> pll;
const int MAXS = MAXN*60;
const LL inf = 2e18;
struct SEG {
	pll tag[MAXS]; //fi k, se b
	int lc[MAXS], rc[MAXS], tot;
	inline LL calc(pll v, LL x) {
		if (v == mkp(0ll, 0ll)) return inf;
	//	cerr << v.fi << " " << v.se << " " << x << endl;
		return v.fi * x + v.se;
	}
	void upd2(int l, int r, pll v, int &s) {
		if (!s) s = ++tot;
		if (tag[s] == mkp(0ll, 0ll)) {
			tag[s] = v;
			return;
		}
		int mid = l + r >> 1;
		LL v1 = calc(v, mid);
		LL v2 = calc(tag[s], mid);
		if (v1 > v2) swap(v1, v2), swap(tag[s], v);
		if (l == r) return;
		if (calc(v, l) < calc(tag[s], l)) upd2(l, mid, v, lc[s]);
		else upd2(mid + 1, r, v, rc[s]);
	}

	void upd1(int l, int r, int L, int R, pll v, int &s) {
		if (!s) s = ++tot;
		if (L > r || R < l) return;
		if (L <= l && r <= R) {
			upd2(l, r, v, s);
			return;
		}
		int mid = l + r >> 1;
		upd1(l, mid, L, R, v, lc[s]);
		upd1(mid + 1, r, L, R, v, rc[s]);
		return;
	}
	LL query(int l, int r, int x, int s) {
		if (!s) return inf;
		if (l == r) return calc(tag[s], x);
		int mid = l + r >> 1; LL v = calc(tag[s], x);
		if (x <= mid) return min(query(l, mid, x, lc[s]), v);
		return min(query(mid + 1, r, x, rc[s]), v);
	}
}seg;

pii pos[MAXN + 10];
//vector <pii> G[MAXN + 10];
int a[MAXN + 10], b[MAXN + 10];
LL dp[MAXN + 10];

typedef pair <LL, int> pli;
priority_queue <pli, vector<pli>, greater<pli>> q;
int rt[MAXN + 10];

const int MAXW = 1e6;
LL query(int x, int p) {
	return seg.query(1, MAXW, x, rt[p]);
}

inline void chkmin(int x, LL v) {
	if (dp[x] > v)
		dp[x] = v, q.push(mkp(v, x));
}

bool vis[MAXN + 10];
int w[MAXN + 10];
void dij() {
	while (!q.empty()) {
		int x = q.top().se; q.pop();
		if (vis[x]) return;
		vis[x] = 1;
		int p = pos[x].fi, k = ::b[pos[x].se], m = dp[x];
		ds[p].del(mkp(a[pos[x].se], x));
		seg.upd1(1, MAXW, 1, MAXW, mkp(k, m), rt[p]);
		if (ds[p].size()) {
			pii p1 = ds[p].min();
			pii p2 = ds[p].max();
			if (p1.se == 6 || p2.se == 6) {
			//	cerr << "1" << endl;
			}
			LL v1 = query(p1.fi, p);
			LL v2 = query(p2.fi, p);
	//		assert(v1 >= 0 && v2 >= 0);
			chkmin(p1.se, v1);
			chkmin(p2.se, v2);
		}
		if (w[x]) {
			if (x + 1 == 6) {
			//	cerr << "s" << endl;
			}
			chkmin(x + 1, dp[x] + w[x]);
		}
		/*
		for (auto i : G[x]) {
			int v = i.fi, w = i.se;
			chkmin(v, dp[x] + w);
		}*/
	}
}

signed main() {
//	freopen ("std.in", "r", stdin);
//	freopen ("std.out", "w", stdout);
	int n, k;
	n = read(), k = read();
	for (int i = 1; i <= k; ++i) a[i] = read();
	for (int i = 1; i <= k; ++i) b[i] = read();
	int tot = 0;
	for (int i = 1; i <= k; ++i) {
		int p = read();
		for (int j = 1; j <= p; ++j) {
			int x = read();
			pos[tot + j].fi = x;
			pos[tot + j].se = i;
			ds[x].ins(mkp(a[i], tot + j));
			if (j < p) {
				w[tot + j] = read();
				//G[tot + j].pb(mkp(tot + j + 1, w));
			}
		}
		tot += p;
	}
	for (int i = 1; i <= tot; ++i) {
		if (pos[i].fi == 1) q.push(mkp(0ll, i));
		else dp[i] = inf;
	}
	dij();
	static LL ans[MAXN + 10];
	for (int i = 1; i <= n; ++i) ans[i] = inf;
	for (int i = 1; i <= tot; ++i)
		ans[pos[i].fi] = min(ans[pos[i].fi], dp[i]);
	for (int i = 2; i <= n; ++i)
		printf("%lld ", ans[i]);
	return 0;
}


詳細信息

Test #1:

score: 100
Accepted
time: 11ms
memory: 225096kb

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

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: -100
Wrong Answer
time: 7ms
memory: 225060kb

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 162075978395 701911826 

result:

wrong answer 3rd numbers differ - expected: '80811085745', found: '162075978395'