QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#50410#147. FloppyieeCompile Error//C++172.5kb2022-09-25 22:22:242023-01-15 18:06:50

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-15 18:06:50]
  • 评测
  • [2022-09-25 22:22:24]
  • 提交

floppy

#include <bits/stdc++.h>
using namespace std;
void read_array(int subtask_id, const vector<int> &v) {
	const int n = (int) v.size(), Log = (int) ceil(log2(n)) + 1;
	string bits(2 * n, '0');
	vector<int> ng(n + 1);
	vector<vector<int>> ST(n, vector<int>(Log));
	ng[1] = 0;
	for (int i = 2; i <= n; ++i) ng[i] = ng[i / 2] + 1;
	for (int i = 0; i < n; ++i) ST[i][0] = i;
	auto argmax = [&] (int x, int y) {
		return v[x] > v[y] ? x : y;
	};
	for (int i = 1; i < Log; ++i)
		for (int j = 0; j + (1 << i) - 1 < n; ++j)
			ST[j][i] = argmax(ST[j][i - 1], ST[j + (1 << i - 1)][i - 1]);
	auto query = [&] (int x, int y) {
		const int k = ng[y - x + 1];
		return argmax(ST[x][k], ST[y - (1 << k) + 1][k]);
	};
	int cnt = 0;
	function<void(int, int)> build = [&] (int l, int r) {
		const int p = query(l, r), u = cnt++;
		if (l <= p - 1) bits[u * 2] = '1', build(l, p - 1);
		if (p + 1 <= r) bits[u * 2 + 1] = '1', build(p + 1, r);
	};
	build(0, n - 1);
    save_to_floppy(bits);
}

std::vector<int> solve_queries(int subtask_id, int N,
		const std::string &bits,
		const std::vector<int> &a, const std::vector<int> &b) {
	const int M = (int) a.size();
	vector<int> answers(M), id(N + 1), uid(N + 1), vid(N + 1), siz(N + 1);
	vector<vector<int>> e(N + 1);
	int pos = 1;
	function<void()> init = [&] () {
		const int u = pos;
		if (bits[u * 2 - 2] == '1') e[u].push_back(++pos), init();
		else e[u].push_back(0);
		if (bits[u * 2 - 1] == '1') e[u].push_back(++pos), init();
		else e[u].push_back(0);
	};
	init();
	pos = 0;
	function<void(int)> init2 = [&] (int u) {
		if (e[u][0])
			init2(e[u][0]);
		id[u] = ++pos;
		if (e[u][1])
			init2(e[u][1]);
	};
	init2(1);
	for (int i = 1; i <= N; ++i) assert(vid[id[i]] == 0), vid[id[i]] = i;
	const int Log = (int) ceil(log2(N)) + 1;
	vector<int> dep(N + 1);
	vector<vector<int>> anc(N + 1, vector<int>(Log));
	function<void(int, int)> dfs = [&] (int u, int faz) {
		dep[u] = dep[faz] + 1;
		anc[u][0] = faz;
		for (int i = 1; i < Log; ++i)
			anc[u][i] = anc[anc[u][i - 1]][i - 1];
		for (int v: e[u])
			if (v != 0)
				dfs(v, u);
	};
	dfs(1, 0);
	auto lca = [&] (int u, int v) {
		if (dep[u] < dep[v]) swap(u, v);
		for (int i = Log - 1; i >= 0; --i)
			if (dep[anc[u][i]] >= dep[v])
				u = anc[u][i];
		if (u == v) return u;
		for (int i = Log - 1; i >= 0; --i)
			if (anc[u][i] != anc[v][i])
				u = anc[u][i], v = anc[v][i];
		return anc[u][0];
	};
	for (int i = 0; i < M; ++i)
		answers[i] = id[lca(vid[a[i] + 1], vid[b[i] + 1])] - 1;
	return answers;
}

詳細信息

floppy.code: In function ‘void read_array(int, const std::vector<int>&)’:
floppy.code:28:5: error: ‘save_to_floppy’ was not declared in this scope
   28 |     save_to_floppy(bits);
      |     ^~~~~~~~~~~~~~