QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#532762#6660. 택시 여행orz_zCompile Error//C++146.0kb2024-08-25 11:25:272024-08-25 11:25:27

Judging History

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

  • [2024-08-25 11:25:27]
  • 评测
  • [2024-08-25 11:25:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
//#define int long long
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;
#define F(i, a, b) for(int i = a; i <= (b); ++i)
#define F2(i, a, b) for(int i = a; i < (b); ++i)
#define dF(i, a, b) for(int i = a; i >= (b); --i)
template<typename T> void debug(string s, T x) {cerr << "[" << s << "] = [" << x << "]\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i = 0, b = 0; i < (int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++;else if (s[i] == ')' || s[i] == '}') b--;else if (s[i] == ',' && b == 0) {cerr << "[" << s.substr(0, i) << "] = [" << x << "] | ";debug(s.substr(s.find_first_not_of(' ', i + 1)), args...);break;}}
#ifdef ONLINE_JUDGE
#define Debug(...)
#else
#define Debug(...) debug(#__VA_ARGS__, __VA_ARGS__)
#endif
#define pb push_back
#define fi first
#define se second
#define Mry fprintf(stderr, "%.3lf MB\n", (&Med - &Mbe) / 1048576.0)
#define Try cerr << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
typedef long long ll;
// namespace Fread {const int SIZE = 1 << 17; char buf[SIZE], *S, *T; inline char getchar() {if (S == T) {T = (S = buf) + fread(buf, 1, SIZE, stdin); if (S == T) return '\n';} return *S++;}}
// namespace Fwrite {const int SIZE = 1 << 17; char buf[SIZE], *S = buf, *T = buf + SIZE; inline void flush() {fwrite(buf, 1, S - buf, stdout), S = buf;} inline void putchar(char c) {*S++ = c;if (S == T) flush();} struct NTR {~NTR() {flush();}} ztr;}
// #ifdef ONLINE_JUDGE
// #define getchar Fread::getchar
// #define putchar Fwrite::putchar
// #endif
inline int ri() {
	int x = 0;
	bool t = 0;
	char c = getchar();
	while (c < '0' || c > '9') t |= c == '-', c = getchar();
	while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
	return t ? -x : x;
}
inline void wi(int x) {
	if (x < 0) {
		putchar('-'), x = -x;
	}
	if (x > 9) wi(x / 10);
	putchar(x % 10 + 48);
}
inline void wi(int x, char s) {
	wi(x), putchar(s);
}
bool Mbe;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 998244353;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int _ = 2e5 + 5;


bool Med;

int n, tot, head[_], to[_ << 1], nxt[_ << 1], w[_ << 1];

void add(int u, int v, int c) {
	to[++tot] = v, nxt[tot] = head[u], head[u] = tot, w[tot] = c;
}

namespace Dis {
	int dfn[_], cnt, Fa[_], st[_][20];
	ll dep[_];
	void dfs(int u, int fa) {
		dfn[u] = ++cnt;
		Fa[u] = fa;
		st[dfn[u]][0] = u;
		for(int i = head[u], v = to[i]; i; i = nxt[i], v = to[i]) if(v != fa) {
			dep[v] = dep[u] + w[i];
			dfs(v, u);
		}
	}
	int get(int x, int y) {
		return dfn[Fa[x]] < dfn[Fa[y]] ? x : y;
	}
	int lg[_];
	int LCA(int u, int v) {
		if(u == v) return u;
		u = dfn[u], v = dfn[v];
		if(u > v) swap(u, v);
		u++;
		int t = lg[v - u + 1];
		return Fa[get(st[u][t], st[v - (1 << t) + 1][t])];
	}
	ll Dis(int u, int v) {
//		Debug(u, v, LCA(u, v));
		return dep[u] + dep[v] - (dep[LCA(u, v)] << 1);
	}
	void init() {
		F(i, 2, n) lg[i] = lg[i >> 1] + 1;
		dfs(1, 0);
		F(j, 1, lg[n]) {
			F(i, 1, n - (1 << j) + 1) st[i][j] = get(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
		}
	}
}

ll f[_];

int Sum, rt, sz[_]; bool vis[_];
void get_rt(int u, int fa) {
	int mx = 0;
	for(int i = head[u], v = to[i]; i; i = nxt[i], v = to[i]) if(v != fa &&!vis[v]) {
		get_rt(v, u);
		mx = max(mx, sz[v]);
	}
	mx = max(mx, Sum - sz[u]);
	if(mx <= Sum / 2) {
		rt = u;
	}
}
void get_sz(int u, int fa) {
	sz[u] = 1;
	for(int i = head[u], v = to[i]; i; i = nxt[i], v = to[i]) if(v != fa && !vis[v]) {
		get_sz(v, u);
		sz[u] += sz[v];
	}
}
int Fa[_];
void work(int u) {
//	Debug(u);
	vis[u] = 1;
	for(int i = head[u], v = to[i]; i; i = nxt[i], v = to[i]) if(!vis[v]) {
		get_sz(v, u);
		Sum = sz[v];
		get_rt(v, u);
		Fa[rt] = u;
		work(rt);
	}
}
pair<ll, ll> operator - (pair<ll, ll> a, pair<ll, ll> b) {
	return make_pair(a.fi - b.fi, a.se - b.se);
}
struct Tubao {
	vector<pair<ll, ll>> a;
	void ins(ll x, ll y) {
		if(a.empty()) {
			a.pb({x, y});
			return;
		}
		while(a.size() > 1 && 1ll * (a.back().se - a[(int)a.size() - 2].se) * (x - a.back().fi) < 1ll * (a.back().fi - a[(int)a.size() - 2].fi) * (y - a.back().se)) a.pop_back();
		a.pb({x, y});
	}
	ll qry(ll x) {
		if(a.empty()) {
			return inf;
		}
//		ll res = inf;
//		for(pair<ll, ll> v : a) res = min(res, v.fi * x + v.se);
//		return res;
		if((int)a.size() == 1) {
			return a.front().fi * x + a.front().se;
		}
		int l = 1, r = (int)a.size() - 1, mid, res = 0;
		while(l <= r) {
			mid = (l + r) >> 1;
			if((a[mid].se - a[mid - 1].se) <= (a[mid].fi - a[mid - 1].fi) * (-x)) {
				l = mid + 1;
				res = mid;
			} else {
				r = mid - 1;
			}
		}
		return a[res].fi * x + a[res].se;
	}
} d[_];
ll a[_], b[_];
void ins(int u) {
	for(int nw = u; nw; nw = Fa[nw]) {
		d[nw].ins(a[u], f[u] + a[u] * Dis::Dis(u, nw) + b[u]);
	}
}
ll qry(int u) {
	ll res = inf;
	for(int nw = u; nw; nw = Fa[nw]) {
		res = min(res, d[nw].qry(Dis::Dis(u, nw)));
	}
	return res;
}

int p[_];

vector<long long> travel(vector<long long> A, vector<int> B, vector<int> U, vector<int> V, vector<int> W) {
	n = A.size();
	F(i, 1, n) a[i] = B[i - 1], b[i] = A[i - 1];
	F(i, 0, n - 2) {
		U[i]++, V[i]++;
		add(U[i], V[i], W[i]);
		add(V[i], U[i], W[i]);
	}
	Dis::init();
//	Debug("Yes");
	f[1] = 0;
	F(i, 2, n) f[i] = a[1] * Dis::Dis(1, i) + b[1];
//	Debug("2");
	Sum = n;
	get_sz(1, 0);
	get_rt(1, 0);
	work(rt);
//	Debug("done");
	F(i, 1, n) p[i] = i;
	sort(p + 1, p + n + 1, [&](int a1, int b1) { return a[a1] > a[b1]; });
	ins(1);
//	F(i, 2, n) Debug(i, f[i], Dis::Dis(1, i));
	F(i, 1, n) {
		if(p[i] == 1) continue;
//		Debug(p[i], f[p[i]], qry(p[i]));
		f[p[i]] = qry(p[i]);
		ins(p[i]);
//		Debug(qry(p[i]));
	}
	F(i, 1, n) {
		Debug(i, qry(i));
	}
	vector<ll> f2;
	F(i, 2, n) f2.pb(qry(i));
	return f2;
}

signed main() {
	// Mry;
	travel({10, 5, 13, 4, 3}, {10, 7, 5, 9, 1}, {1, 0, 3, 2}, {0, 2, 2, 4}, {1, 5, 10, 3});
	// Try;
	return 0;
}

详细

/usr/bin/ld: /tmp/ccy3uEs3.o: in function `main':
answer.code:(.text.startup+0x0): multiple definition of `main'; /tmp/ccjcZ3FZ.o:implementer.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status