QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#153769#7041. Girls Band PartyPetroTarnavskyi#WA 3ms11612kbC++172.1kb2023-08-30 22:17:202023-08-30 22:17:22

Judging History

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

  • [2023-08-30 22:17:22]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:11612kb
  • [2023-08-30 22:17:20]
  • 提交

answer

#include <bits/stdc++.h>

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 = 100'447;
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]].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] += (1ll << (i + j + 2)) * 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] += (1ll << (i + 1)) * t1[t] * t2[1 - t];
		val[v].b[i] += val[u].b[i];
	}
	val[v].cnt += val[u].cnt;
}


void dfs(int v)
{
	val[v] = node(a[v]);
	for (auto& to : g[v])
		dfs(to);
	for (auto& to : g[v])
		merge(v, to);
//	for (auto d : del)
//		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;
}




Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 11612kb

input:

1
6
Saaya Power 45000
Kokoro Happy 45000
Kasumi Cool 45000
Rimi Power 45000
Aya Pure 45000
Aya Power 2000
Saaya Tae Kasumi Rimi Arisa
Power

output:

0

result:

wrong answer 1st numbers differ - expected: '382500', found: '0'