QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#370206#6671. Zadataklukap_0 17ms27908kbC++143.6kb2024-03-28 23:03:402024-03-28 23:03:40

Judging History

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

  • [2024-03-28 23:03:40]
  • 评测
  • 测评结果:0
  • 用时:17ms
  • 内存:27908kb
  • [2024-03-28 23:03:40]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

ll n;
ll niz[MAXN], sazet[MAXN];
vector<ll> v, bizut;
set<ll> vek[2 * MAXN];
ll roots[2 * MAXN],l[2 * OFF], r[2 * OFF], lazy[2 * OFF], vel[2 * MAXN];
ll val[2 * OFF], 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 (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: 17ms
memory: 27908kb

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: '259607487540'

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:


result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%