QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#770627 | #6671. Zadatak | zhangshiyan | 0 | 62ms | 15324kb | C++20 | 1.8kb | 2024-11-21 22:46:43 | 2024-11-21 22:46:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 4e6 + 5, V = 5e5;//数组要足够大
vector<int>g[N];
int a[N], d[N], sz[N];
int ls[N << 2], rs[N << 2], cnt[N << 2], rt[N];
ll s[N << 2], ans[N];
int n, tot;
void push_up(int p)
{
cnt[p] = cnt[ls[p]] + cnt[rs[p]];
if(cnt[rs[p]] % 2 == 1)
{
s[p] = s[rs[p]] - s[ls[p]];
}
else
{
s[p] = s[rs[p]] + s[ls[p]];
}
}
void add(int u, int l, int r, int &p)
{
if(!p)p = ++tot;
if(l == r)
{
cnt[p] ^= 1;
s[p] = 1ll * cnt[p] * l * l;
return;
}
int mid = (l + r) / 2;
if(u <= mid)add(u, l, mid, ls[p]);
else add(u, mid + 1, r, rs[p]);
push_up(p);
}
int merge(int u, int y, int l, int r)
{
if(!u || !y)return u | y;
if(l == r)
{
cnt[u] ^= cnt[y];
s[u] = 1ll * cnt[u] * l * l;
return u;
}
int mid = (l + r) / 2;
ls[u] = merge(ls[u], ls[y], l, mid);
rs[u] = merge(rs[u], rs[y], mid + 1, r);
push_up(u);
return u;
}
void dfs(int u)
{
sz[u] = 1;
for(auto v : g[u])
{
dfs(v);
sz[u] += sz[v];
}
}
void solve(int u)
{
if(g[u].empty())//叶子节点
{
add(a[u], 1, V, rt[u]);
return;
}
int y1 = g[u][0], y2 = g[u][1];
if(sz[y1] < sz[y2])swap(y1, y2);
solve(y1);
solve(y2);
ll k1 = s[rt[y1]], k2 = s[rt[y2]];
rt[u] = merge(rt[y1], rt[y2], 1, V);
ll k3 = s[rt[u]];
ans[u] = (k1 + k2 - k3) >> 1;
}
int main()
{
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
a[i] /= 2;
}
for(int i = 1; i < n; i++)
{
int u, v;
cin >> u >> v;
g[n + i].push_back(u);
g[n + i].push_back(v);
d[u]++;
d[v]++;
}
for(int i = n + 1; i < (n / 2); i++)
{
if(!d[i])
{
dfs(i);
solve(i);
}
}
for(int i = n + 1; i < (n / 2); i++)
{
printf("%lld\n", ans[i] * 4);
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 8064kb
input:
5000 217378 945562 533764 323494 69148 240722 205370 463122 552700 31800 616898 678076 893816 258468 34822 905360 967562 731346 340940 584418 684926 785402 107584 995542 363278 255302 196912 870994 329464 338390 154870 977540 65120 130388 350020 239660 553428 710306 385138 633274 841672 740778 17929...
output:
result:
wrong answer 1st lines differ - expected: '359872811236', found: ''
Subtask #2:
score: 0
Wrong Answer
Test #27:
score: 0
Wrong Answer
time: 62ms
memory: 15324kb
input:
100000 590812 862538 815196 397712 773198 172122 270600 609324 841858 4868 597128 216378 982576 385590 842010 55844 671758 885088 577804 194248 229770 859754 274744 678176 607974 791062 607192 210234 863164 619708 804538 430978 237704 10512 840374 843732 875326 255462 970338 898540 925508 661464 413...
output:
result:
wrong answer 1st lines differ - expected: '349058819344', found: ''
Subtask #3:
score: 0
Wrong Answer
Test #40:
score: 0
Wrong Answer
time: 44ms
memory: 11248kb
input:
65536 131908 883754 813278 197778 704074 981802 297078 903698 485360 496064 726120 251990 462786 129558 704500 920556 903884 454552 949354 328526 921462 975888 780002 276668 675308 49774 83014 136308 679916 42174 151084 358830 284218 259680 65684 526980 516764 200170 265060 294150 128046 658864 2984...
output:
result:
wrong answer 1st lines differ - expected: '17399720464', found: ''
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%