QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#739089#9569. SubwayDeltaxWA 12ms235720kbC++144.5kb2024-11-12 20:48:582024-11-12 20:50:02

Judging History

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

  • [2024-11-12 20:50:02]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:235720kb
  • [2024-11-12 20:48:58]
  • 提交

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() {
		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];

vector <pair<int, LL>> G[MAXN + 10];
void dij() {
	while (!q.empty()) {
		int x = q.top().se; q.pop();
		if (vis[x]) continue;
		vis[x] = 1;
		int p = pos[x].fi;
		LL 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()) {
	//		DS tmp = ds[p];
//			while (ds[p].size()) {
				pii p1 = ds[p].min();
				pii p2 = ds[p].max();
				LL v1 = query(p1.fi, p);
				LL v2 = query(p2.fi, p);
				chkmin(p1.se, v1);
				chkmin(p2.se, v2);
			//	ds[p].del(p1);
	//		}
	//		ds[p] = tmp;
		}*/
		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; LL w = i.se;
			chkmin(v, dp[x] + w);
		}
	}
}


vector <int> vec[MAXN + 10];
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));
			vec[x].pb(tot + j);
			if (j < p) {
				w[tot + j] = read();
				//G[tot + j].pb(mkp(tot + j + 1, w));
			}
		}
		tot += p;
	}
	//cerr << tot << endl;
	for (int i = 1; i <= n; ++i)
		for (auto u : vec[i])
			for (auto k : vec[i])
				G[u].pb(mkp(k, 1ll * b[pos[u].se] * a[pos[k].se]));
	for (int i = 1; i <= tot; ++i) {
		if (pos[i].fi == 1) q.push(mkp(0ll, i));
		else dp[i] = inf;
	}
exit(0);
	dij();

	static LL ans[MAXN + 10];
	for (int i = 1; i <= n; ++i) ans[i] = inf;
	for (int i = 1; i <= tot; ++i) {
	//	cout << dp[i] << " ";
		ans[pos[i].fi] = min(ans[pos[i].fi], dp[i]);
	}
	//cout << endl;
	for (int i = 2; i <= n; ++i)
		printf("%lld ", ans[i]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 12ms
memory: 235720kb

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:


result:

wrong answer Answer contains longer sequence [length = 5], but output contains 0 elements