QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#182868#7045. XOR TreePetroTarnavskyiCompile Error//C++142.7kb2023-09-18 17:40:552023-09-18 17:40:55

Judging History

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

  • [2023-09-18 17:40:55]
  • 评测
  • [2023-09-18 17:40:55]
  • 提交

answer

#include <vector>
#include <iostream>
#include <cstring>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FILL(a, b) memset(a, b, sizeof(a))
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef unsigned long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int N = 100447;
const int B = 30;

struct node
{
	int cnt;
	int b[B];
	int m[B][B];
	
	node() {}
	node(int x)
	{
		FILL(b, 0);
		FILL(m, 0);
		cnt = 1;
		FOR (i, 0, B)
		{
			int bt = (x >> i) & 1;
			if (bt == 0) continue;
			b[i]++;
			FOR (j, i + 1, B)
			{
				if (((x >> j) & 1) == 0) continue;
				m[i][j]++;
			}
		}
	}
	
	VI get1(int i)
	{
		return {b[i], cnt - b[i]};
	}
	
	VI get2(int i, int j)
	{
		int a0 = m[i][j];
		int a1 = b[i] - m[i][j];
		int a2 = b[j] - m[i][j];
		int a3 = cnt - a0 - a1 - a2;
		return {a0, a1, a2, a3};
	}
};

int a[N];
VI g[N];
VI del[N];
node val[N];
int n, k;
LL ans[N];

void dfs2(int v, VI& st)
{
	if (SZ(st) > k)
		del[st[SZ(st) - k - 1]].PB(v);
	st.PB(v);
	for (auto& to : g[v])
		dfs2(to, st);
	st.pop_back();
}

void merge(int v, int u)
{
	FOR (i, 0, B)
	{
		FOR (j, i + 1, B)
		{
			VI t1 = val[v].get2(i, j);
			VI t2 = val[u].get2(i, j);
			FOR (t, 0, 4)
				ans[v] += LL((1ll << (i + j + 1))) * t1[t] * t2[3 - t];
			val[v].m[i][j] += val[u].m[i][j];
		}
	}
	FOR (i, 0, B)
	{
		auto t1 = val[v].get1(i);
		auto t2 = val[u].get1(i);
		FOR (t, 0, 2)
			ans[v] += LL((1ll << (i * 2))) * t1[t] * t2[1 - t];
		val[v].b[i] += val[u].b[i];
	}
	val[v].cnt += val[u].cnt;
}

void erase(int v, int x)
{
	node tmp(x);
	
	val[v].cnt -= tmp.cnt;
	FOR (i, 0, B)
	{
		val[v].b[i] -= tmp.b[i];
		auto t1 = val[v].get1(i);
		auto t2 = tmp.get1(i);
		FOR (t, 0, 2)
			ans[v] -= LL((1ll << (i * 2))) * t1[t] * t2[1 - t];
	}
	FOR (i, 0, B)
	{
		FOR (j, i + 1, B)
		{
			val[v].m[i][j] -= tmp.m[i][j];
			VI t1 = val[v].get2(i, j);
			VI t2 = tmp.get2(i, j);
			FOR (t, 0, 4)
				ans[v] -= LL((1ll << (i + j + 1))) * t1[t] * t2[3 - t];
		}
	}
}


void dfs(int v)
{
	{
		swap(val[v], node(a[v]));
	}
	for (auto& to : g[v])
	{
		dfs(to);
		ans[v] += ans[to];
	}
	for (auto& to : g[v])
		merge(v, to);
	for (auto d : del[v])
		erase(v, a[d]);
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
		
	cin >> n >> k;
	
	FOR (i, 0, n) cin >> a[i];
	
	FOR (i, 1, n)
	{
		int p;
		cin >> p;
		p--;
		g[p].PB(i);
	}
	VI st;
	dfs2(0, st);
	
	dfs(0);
	
	FOR (i, 0, n)
	{
		cout << ans[i] << '\n';
	}
	
	return 0;
}

详细

answer.code: In function ‘void dfs(int)’:
answer.code:134:21: error: no matching function for call to ‘swap(node&, node)’
  134 |                 swap(val[v], node(a[v]));
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/stl_pair.h:59,
                 from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/vector:60,
                 from answer.code:1:
/usr/include/c++/11/bits/move.h:196:5: note: candidate: ‘std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = node; std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > = void]’ (near match)
  196 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/11/bits/move.h:196:5: note:   conversion of argument 2 would be ill-formed:
answer.code:134:30: error: cannot bind non-const lvalue reference of type ‘node&’ to an rvalue of type ‘node’
  134 |                 swap(val[v], node(a[v]));
      |                              ^~~~~~~~~~
In file included from /usr/include/c++/11/bits/stl_pair.h:59,
                 from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/vector:60,
                 from answer.code:1:
/usr/include/c++/11/bits/move.h:220:5: note: candidate: ‘template<class _Tp, long unsigned int _Nm> std::__enable_if_t<std::__is_swappable<_Tp>::value> std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])’
  220 |     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
      |     ^~~~
/usr/include/c++/11/bits/move.h:220:5: note:   template argument deduction/substitution failed:
answer.code:134:21: note:   mismatched types ‘_Tp [_Nm]’ and ‘node’
  134 |                 swap(val[v], node(a[v]));
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/vector:60,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_pair.h:533:5: note: candidate: ‘template<class _T1, class _T2> void std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&)’
  533 |     swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
      |     ^~~~
/usr/include/c++/11/bits/stl_pair.h:533:5: note:   template argument deduction/substitution failed:
answer.code:134:21: note:   ‘node’ is not derived from ‘std::pair<_T1, _T2>’
  134 |                 swap(val[v], node(a[v]));
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/vector:67,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_vector.h:1962:5: note: candidate: ‘template<class _Tp, class _Alloc> void std::swap(std::vector<_Tp, _Alloc>&, std::vector<_Tp, _Alloc>&)’
 1962 |     swap(vector<_Tp, _Alloc>& __x, vector<_Tp, _Alloc>& __y)
      |     ^~~~
/usr/include/c++/11/bits/stl_vector.h:1962:5: note:   template argument deduction/substitution failed:
answer.code:134:21: note:   ‘node’ is not derived from ‘std::vector<_Tp, _Alloc>’
  134 |                 swap(val[v], node(a[v]));
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:55,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from answer.code:2:
/usr/include/c++/11/bits/basic_string.h:6493:5: note: candidate: ‘template<class _CharT, class _Traits, class _Alloc> void std::swap(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)’
 6493 |     swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~
/usr/include/c++/11/bits/basic_string.h:6493:5: note:   template argument deduction/substitution failed:
answer.code:134:21: note:   ‘node’ is not derived from ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
  134 |                 swap(val[v], node(a[v]));
      |                 ~~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/vector:68,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_bvector.h:118:3: note: candidate: ‘void std::swap(std::_Bit_reference, std::_Bit_reference)’
  118 |   swap(_Bit_reference __x, _Bit_reference __y) noexcept
      |   ^~~~
/usr/include/c++/11/bits/stl_bvector.h:118:23: note:   no known conversion for argument 1 from ‘node’ to ‘std::_Bit_reference’
  118 |   swap(_Bit_reference __x, _Bit_reference __y) noexcept
      |        ~~~~~~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_bvector.h:126:3: note: candidate: ‘void std::swap(std::_Bit_reference, bool&)’
  126 |   swap(_Bit_reference __x, bool& __y) noexcept
      |   ^~~~
/usr/include/c++/11/bits/stl_bvector.h:126:23: note:   no known conversion for argument 1 from ‘node’ to ‘std::_B...