QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#467846#6671. ZadatakPorNPtree0 8ms12972kbC++172.1kb2024-07-08 17:49:502024-07-08 17:49:51

Judging History

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

  • [2024-07-08 17:49:51]
  • 评测
  • 测评结果:0
  • 用时:8ms
  • 内存:12972kb
  • [2024-07-08 17:49:50]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5, L = 1e6;

struct op {
    int l, r, c;
    long long sB, sW;
} p[N << 5];

int a[N], rt[N << 1], tot;

int newNode(int l, int r) {
    ++tot, p[tot].l = p[tot].r = p[tot].c = 0;
    p[tot].sB = 0, p[tot].sW = 1ll * r * r - 1ll * (l - 1) * (l - 1);
    return tot;
}

void up(int k, int l, int r) {
    int mid = (l + r) >> 1;
    if (!p[k].l) p[k].l = newNode(l, mid);
    if (!p[k].r) p[k].r = newNode(mid + 1, r);
    p[k].c = p[p[k].l].c ^ p[p[k].r].c;
    p[k].sB = p[p[k].r].sB + (p[p[k].r].c ? p[p[k].l].sW : p[p[k].l].sB);
    p[k].sW = p[p[k].r].sW + (p[p[k].r].c ? p[p[k].l].sW : p[p[k].l].sB);
}

void modify(int &k, int l, int r, int x) {
    if (!k) k = newNode(l, r);
    if (l == r) {
        p[k].sB = l + l - 1, p[k].sW = 0, p[k].c = 1;
        return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid) modify(p[k].l, l, mid, x);
    else modify(p[k].r, mid + 1, r, x);
    up(k, l, r);
}

long long res;

int merge(int x, int y, int l, int r, int c1, int c2) {
    if (!x && !y) {
        if (c1 && c2) res += 1ll * r * r - 1ll * (l - 1) * (l - 1);
        return 0;
    }
    if (!x) {
        if (c1) res += !c2 ? p[y].sB : p[y].sW;
        return y;
    }
    if (!y) {
        if (c2) res += !c1 ? p[x].sB : p[x].sW;
        return x;
    }
    if (l == r) {
        if ((p[x].c ^ c1) && (p[y].c ^ c2)) res += l + l - 1;
        p[x].c ^= p[y].c;
        if (p[y].c) swap(p[x].sB, p[x].sW);
        return x;
    }
    int mid = (l + r) >> 1;
    p[x].r = merge(p[x].r, p[y].r, mid + 1, r, c1, c2);
    p[x].l = merge(p[x].l, p[y].l, l, mid, c1 ^ p[p[x].r].c ^ p[p[y].r].c, c2 ^ p[p[y].r].c);
    up(x, l, r);
    return x;
}

signed main() {
    int n; scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), a[i] >>= 1;
    for (int i = 1; i <= n; ++i) modify(rt[i], 1, L, a[i]);
    for (int i = 1, x, y; i < n; ++i) {
        scanf("%d%d", &x, &y);
        res = 0;
        rt[n + i] = merge(rt[x], rt[y], 1, L, 0, 0);
        printf("%lld\n", res << 2);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 12972kb

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:

359872811236
632705703184
133272104892
251229507984
545792721300
0
142492660324
492745033764
0
89244392644
551725099524
278399748496
311560446976
294803193916
626011423408
0
184761693488
119283228124
71190167196
60443205904
0
381767396684
121825392152
112105556984
267680838704
297018681220
196384751...

result:

wrong answer 3rd lines differ - expected: '113223620400', found: '133272104892'

Subtask #2:

score: 0
Runtime Error

Test #27:

score: 0
Runtime Error

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:


Subtask #3:

score: 0
Runtime Error

Test #40:

score: 0
Runtime Error

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:

17399720464
39116137284
495720197476
88255338084
235574329600
63498960100
16785275364
496320250000
206617520704
107929332676
849092217444
76545182224
2477451076
6891324196
1778646276
22826375056
67433702400
4314387856
40068028900
70256803600
16395778116
89086728676
242284466176
8531108496
4721146752...

result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%