QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#153756 | #7041. Girls Band Party | PetroTarnavskyi# | WA | 3ms | 12756kb | C++17 | 1.7kb | 2023-08-30 21:25:47 | 2023-08-30 21:25:48 |
Judging History
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;
int a[N];
VI g[N];
int m[N][4][B][B];
int b[N][2][B];
int n, k;
VI del[N];
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 (t, 0, 4)
FOR (i, 0, B)
FOR (j, i + 1, B)
ans[v] += m[v][t][i][j] * m[u][3 - t][i][j] * (1 << (i + j + 1));
FOR (t, 0, 4)
FOR (i, 0, B)
FOR (j, i + 1, B)
m[v][t][i][j] += m[u][t][i][j];
FOR (t, 0, 2)
FOR (i, 0, B)
ans[v] += b[v][t][i] * b[u][1 - t][i] * (1 << i);
FOR (t, 0, 2)
FOR (i, 0, B)
b[v][t][i] += b[u][t][i];
}
void dfs(int v)
{
FOR (i, 0, B)
{
int bt = (a[v] >> i) & 1;
b[v][bt][i]++;
FOR (j, i + 1, B)
m[v][(bt << 1) + ((a[v] >> j) & 1)][i][j]++;
}
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: 12756kb
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'