QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#859588#9676. AncestorslfxxxCompile Error//C++173.6kb2025-01-17 20:59:412025-01-17 20:59:51

Judging History

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

  • [2025-01-17 20:59:51]
  • 评测
  • [2025-01-17 20:59:41]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) (x).begin(), (x).end()
bool be;
constexpr int N = 1e5 + 5, Q = 1e6 + 5;
int n, m, b, rt, fa[N], dfn[N], dep[N], cnt, st[N][17], p[N], in[N], pre[N], nxt[N], ans[Q], lca[N];
vector<int>e[N];
struct Query {
	int l, r, x, id;
}q[Q];
struct ds {
	int a[N], sum[350], in[N], b;
	void clear()
	{
		memset(a + 1, 0, n * sizeof(int));
		memset(sum, 0, sizeof sum);
	}
	void init()
	{
		b = sqrt(n);
		for (int i = 1; i <= n; ++i) in[i] = (i + b - 1) / b;
	}
	void add(int x, int v)
	{
		a[x] += v;
		sum[in[x]] += v;
	}
	int query(int x)
	{
		int ans = 0;
		for (int i = 1; i < in[x]; ++i) ans += sum[i];
		for (int i = (in[x] - 1) * b + 1; i <= x; ++i) ans += a[i];
		return ans;
	}
}d;
void dfs(int u)
{
	dfn[u] = ++cnt;
	st[cnt][0] = fa[u];
	dep[u] = dep[fa[u]] + 1;
	for (int v : e[u]) {
		dfs(v);
	}
}
int get(int u, int v)
{
	return dfn[u] < dfn[v] ? u : v;
}
int LCA(int u, int v)
{
	if (u == v) return u;
	if (dfn[u] > dfn[v]) swap(u, v);
	int k = __lg(dfn[v] - dfn[u]);
	return get(st[dfn[u] + 1][k], st[dfn[v] - (1 << k) + 1][k]);
}
void work(int x, int y, int z)
{
	if (y == 0) return;
	if (x == 0 || dep[x] != dep[y]) d.add(dep[y], z);
	else d.add(dep[x] - dep[lca[y]], z);
}
void del(int x)
{
	work(pre[x], x, -1);
	work(x, nxt[x], -1);
	lca[nxt[x]] = pre[x] && nxt[x] ? LCA(pre[x], nxt[x]) : 0;
	work(pre[x], nxt[x], 1);
	pre[nxt[x]] = pre[x];
	nxt[pre[x]] = nxt[x];
}
void add(int x)
{
	work(pre[x], x, 1);
	work(pre[x], nxt[x], -1);
	lca[nxt[x]] = nxt[x] ? LCA(x, nxt[x]) : 0;
	work(x, nxt[x], 1);
	pre[nxt[x]] = x;
	nxt[pre[x]] = x;
}
bool en;
int main()
{
#ifdef IAKIOI
	cerr << (&be - &en) / 1024.0 / 1024 << " MB\n----------------------------" << endl;
	freopen("in.in", "r", stdin);
	// freopen("out.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> fa[i];
		if (fa[i] == 0) rt = i;
		else e[fa[i]].emplace_back(i);
	}
	dfs(rt);
	for (int j = 1; j <= __lg(n); ++j) {
		for (int i = 1; i + (1 << j) - 1 <= n; ++i) {
			st[i][j] = get(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
		}
	}
	d.init();
	b = max(1, 0.8 * (int)(n / sqrt(m)));
	for (int i = 1; i <= n; ++i) {
		in[i] = (i + b - 1) / b;
	}
	iota(p + 1, p + 1 + n, 1);
	sort(p + 1, p + 1 + n, [](int x, int y) {
		if (dep[x] != dep[y]) return dep[x] < dep[y];
		return dfn[x] < dfn[y];
	});
	for (int i = 1; i <= n; ++i) {
		pre[p[i]] = p[i - 1];
		nxt[p[i]] = p[i + 1];
	}
	for (int i = 1; i <= m; ++i) {
		cin >> q[i].l >> q[i].r >> q[i].x;
		q[i].id = i;
	}
	sort(q + 1, q + 1 + m, [](Query a, Query b) {
		if (in[a.l] != in[b.l]) return a.l < b.l;
		return a.r > b.r;
	});
	int l = 0, r = -1;
	for (int i = 1; i <= m; ++i) {
		if (in[l] != in[q[i].l]) {
			d.clear();
			memset(pre + l, 0, (n - l + 1) * sizeof(int));
			memset(nxt + l, 0, (n - l + 1) * sizeof(int));
			l = (in[q[i].l] - 1) * b + 1;
			r = q[i].r;
			int lst = 0;
			for (int j = 1; j <= n; ++j) {
				if (l <= p[j] && p[j] <= r) {
					lca[p[j]] = lst ? LCA(lst, p[j]) : 0;
					work(lst, p[j], 1);
					pre[p[j]] = lst;
					nxt[lst] = p[j];
					lst = p[j];
				}
			}
		}
		while (q[i].r < r) del(r--);
		int pl = l;
		while (q[i].l > l) del(l++);
		ans[q[i].id] = r - l + 1 - d.query(q[i].x);
		while (pl < l) add(--l);
	}
	for (int i = 1; i <= m; ++i) cout << ans[i] << '\n';
	return 0;
}

詳細信息

answer.code: In function ‘int main()’:
answer.code:108:16: error: no matching function for call to ‘max(int, double)’
  108 |         b = max(1, 0.8 * (int)(n / sqrt(m)));
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from answer.code:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
answer.code:108:16: note:   deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘double’)
  108 |         b = max(1, 0.8 * (int)(n / sqrt(m)));
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5705:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)’
 5705 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5705:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5715:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)’
 5715 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5715:5: note:   template argument deduction/substitution failed:
answer.code:108:16: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘int’
  108 |         b = max(1, 0.8 * (int)(n / sqrt(m)));
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~