QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#370229#6671. Zadataklukap_0 383ms440880kbC++143.7kb2024-03-28 23:16:062024-03-28 23:16:08

Judging History

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

  • [2024-03-28 23:16:08]
  • 评测
  • 测评结果:0
  • 用时:383ms
  • 内存:440880kb
  • [2024-03-28 23:16:06]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MAXN =  1e5 + 500;
const int OFF = (1 << 18);

ll n;
ll niz[MAXN], sazet[MAXN];
vector<ll> v, bizut;
set<ll> vek[2 * MAXN];
ll roots[2 * MAXN],l[MAXN * 200], r[MAXN * 200], lazy[MAXN * 200], vel[2 * MAXN];
ll val[200 * MAXN], pravi[MAXN];
ll cnt;

void novi () {
    l[cnt] = -1;
    r[cnt] = -1;
    cnt++;
}

void prop (ll x, ll lo, ll hi) {
    if (lazy[x] == 0) return;
//    cout << "BLOOOOOOOOOOOOOOOOOOB " << x << ' ' << uk << ' ' << val[x] << "\n";
    val[x] = (pravi[hi] - pravi[lo]) - val[x];
    if (hi - lo > 1) {
        if (l[x] == -1) {
            l[x] = cnt;
            novi ();
        }
        if (r[x] == -1) {
            r[x] = cnt;
            novi ();
        }
//        cout << "BIIIIIIIIIIIIRB " << l[x] << ' ' << r[x] << "\n";
        lazy[l[x]] = (lazy[l[x]] ^ 1);
        lazy[r[x]] = (lazy[r[x]] ^ 1);
    }
    lazy[x] = 0;
}

void update (ll a, ll b, ll x, ll lo = 0, ll hi = OFF) {
    prop (x, lo, hi);
    if (hi <= a || lo >= b) return;

    if (lo >= a && hi <= b) {
//        cout << a << ' ' << b << ' ' << x << ' ' << lo << ' ' << hi << "\n";
        lazy[x] = 1;
        prop (x, lo, hi);
        return;
    }

    ll mid = (lo + hi) / 2;

    if (l[x] == -1) {
        l[x] = cnt;
        novi ();
    }
    if (r[x] == -1) {
        r[x] = cnt;
        novi ();
    }
    update (a, b, l[x], lo, mid);
    update (a, b, r[x], mid, hi);
    val[x] = val[l[x]] + val[r[x]];
}

ll query (ll a, ll b, ll x, ll lo = 0, ll hi = OFF) {
//    cout << a << ' ' << b << ' ' << x << ' ' << lo << ' ' << hi << "    "  << val[x] << "\n";
    if (hi <= a || lo >= b) return 0;
    prop (x, lo, hi);

    if (lo >= a && hi <= b) {
//        cout << "AAAAAAA " << val[x] << "\n";
        return val[x];
    }

    ll mid = (lo + hi) / 2;
    if (l[x] == -1) {
        l[x] = cnt;
        novi ();
    }
    if (r[x] == -1) {
        r[x] = cnt;
        novi ();
    }
    return query (a, b, l[x], lo, mid) + query (a, b, r[x], mid, hi);
}

ll spoji (ll x, ll y) {
    ll cijena = 0;
    bizut.clear ();
    for (auto it: vek[y]) bizut.push_back(it);
    for (int i = (ll) bizut.size () - 1; i >= 0; i-=2) {
        ll iduc = 0;
        if (i > 0) iduc = bizut[i - 1];

        cijena += query (iduc, bizut[i], roots[x]);
        update (iduc, bizut[i], roots[x]);
    }
    for (auto it: vek[y]) vek[x].insert (it);
    vek[y].clear ();

    return cijena;
}

int main () {
    ios_base::sync_with_stdio (false);
    cin.tie (0);
    cout.tie (0);

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> niz[i];
        niz[i] /= 2;
    }
    for (int i = 0; i < n; i++) v.push_back (niz[i]);

    sort (v.begin (), v.end ());
    v.resize (unique (v.begin (), v.end ()) - v.begin ());

    for (auto it: v) {
        int ind = lower_bound (v.begin (), v.end (), it) - v.begin () + 1;
        pravi[ind] = 4 * it * it;
    }

    for (int i = 0; i < n; i++) {
        sazet[i] = lower_bound (v.begin (), v.end (), niz[i]) - v.begin () + 1;
        roots[i] = cnt;
        vel[i] = 1;
        novi ();
        update (0, sazet[i], roots[i]);
        vek[i].insert (sazet[i]);
    }

    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;b--;

        if (i == 4940) cout << vel[a] << ' ' << vel[b] << "  " << a << ' ' << b << "\n";
        if (vel[b] > vel[a]) swap (a, b);
        cout << spoji (a, b) << "\n";

        roots[n + i] = roots[a];
        swap (vek[n + i], vek[a]);
        vel[n + i] = vel[a] + vel[b];
    }

    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 16ms
memory: 27292kb

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
113223620400
251229507984
470237900880
0
142492660324
492745033764
0
89244392644
551725099524
278399748496
311560446976
233709556800
476939443200
0
172741415748
92640103936
28418613120
60443205904
0
341931572900
73529592508
193225675856
248612109488
393354817264
21576167436...

result:

wrong answer 4941st lines differ - expected: '238513341228', found: '1340 801  9139 9939'

Subtask #2:

score: 0
Wrong Answer

Test #27:

score: 0
Wrong Answer
time: 214ms
memory: 185680kb

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:

349058819344
315485699072
158174834944
190883984400
29625982884
43598377116
136793375460
505222145492
23697424
122055789444
17217153424
363561360060
92672441524
343745206436
23697424
301341472004
256291624008
271426226484
26531127972
17175971548
316411631620
19435877084
392412501116
57202957148
3506...

result:

wrong answer 4941st lines differ - expected: '184246699024', found: '1 4941  4941 104939'

Subtask #3:

score: 0
Wrong Answer

Test #40:

score: 0
Wrong Answer
time: 383ms
memory: 440880kb

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:

wrong answer 4941st lines differ - expected: '65266964676', found: '1 1  9880 9881'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%