QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#770657 | #6671. Zadatak | zhangshiyan | 0 | 140ms | 59020kb | C++20 | 2.2kb | 2024-11-21 23:04:00 | 2024-11-21 23:04:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e15
inline ll read()
{
ll x = 0, f = 1;
char c = getchar();
while(c < '0' || c > '9')
{
if(c == '-')
{
f = -1;
}
c = getchar();
}
while(c >= '0' && c <= '9')
{
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return x * f;
}
const int N = 4e6 + 5, V = 1e6;
vector<int>g[N];
int n;
int a[N], d[N];
ll tot;
int ls[N << 2], rs[N << 2], s[N << 2], cnt[N << 2];
ll ans[N], rt[N];
void dlt(int p)
{
ls[p] = rs[p] = s[p] = cnt[p] = 0;
}
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]];
}
}
ll add(int id, int u, int l, int r)
{
if(!id)
{
id = ++tot;
}
if(l == r)
{
cnt[id] ^= 1;
s[id] = 1ll * cnt[id] * l * l;
return id;
}
int mid = (l + r) / 2;
if(u <= mid)
{
ls[id] = add(ls[id], u, l, mid);
}
else
{
rs[id] = add(rs[id], u, mid + 1, r);
}
push_up(id);
return id;
}
int merge(int a, int b, int l, int r)
{
if(!a)
{
return b;
}
if(!b)
{
return a;
}
if(l == r)
{
cnt[a] ^= cnt[b];
s[a] = 1ll * cnt[a] * l * l;
dlt(b);
return a;
}
int mid = (l + r) / 2;
ls[a] = merge(ls[a], ls[b], l, mid);
rs[a] = merge(rs[a], rs[b], mid + 1, r);
push_up(a);
dlt(b);
return a;
}
void solve(int u)
{
if(g[u].empty())//叶子节点
{
rt[u] = add(rt[u], a[u], 1, V);
return;
}
int v1 = g[u][0], v2 = g[u][1];
solve(v1);
solve(v2);
ll k1 = s[rt[v1]];
ll k2 = s[rt[v2]];
rt[u] = merge(rt[v1], rt[v2], 1, V);
ll k3 = s[rt[u]];
ans[u] = (k1 + k2 - k3) / 2 * 4;
}
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]++;
}
ll root = -1;
for(int i = n + 1; i < n * 2; i++)
{
if(!d[i])//根节点
{
root = i;
break;
}
}
solve(root);
for(int i = n + 1; i < (n * 2); i++)
{
printf("%lld\n", ans[i]);
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 15516kb
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:
-904441628 -2949456624 1554470704 2121404816 -2208501680 0 5053706852 -5471172572 0 3345046724 1969285636 3521841552 2322801664 1781322816 -4096893952 8589934592 -7647210684 -1849176576 2648809344 -8276270832 0 -1665810780 4810115772 -4342819760 -495993680 -1782173968 1013309560 -3447637352 -1925738...
result:
wrong answer 1st lines differ - expected: '359872811236', found: '-904441628'
Subtask #2:
score: 0
Wrong Answer
Test #27:
score: 0
Wrong Answer
time: 140ms
memory: 59020kb
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:
5461435664 -2341880832 3556012288 -6684511216 3856179108 648704156 -9235512604 7005939156 23697424 -6793229436 37284240 2784107196 -1816838988 147822756 23697424 9283695876 -9996348344 5138254132 761324196 -3897636 -1415948284 10845942492 -2724490116 -2926584996 -1506721392 4713089784 -1362561144 35...
result:
wrong answer 1st lines differ - expected: '349058819344', found: '5461435664'
Subtask #3:
score: 0
Wrong Answer
Test #40:
score: 0
Wrong Answer
time: 84ms
memory: 42852kb
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:
219851280 4756398916 -2496008860 -6233942428 3646095616 -5220516636 -394593820 -1895956336 459090496 4850117572 7278627428 7825705488 -6112483516 6891324196 1778646276 5646505872 -1285774336 4314387856 -2881644060 1537326864 -784091068 3187382756 1766297600 8531108496 -4328140028 -7258051132 5164975...
result:
wrong answer 1st lines differ - expected: '17399720464', found: '219851280'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%