QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#124966 | #6671. Zadatak | bashkort# | 0 | 173ms | 215068kb | C++20 | 3.3kb | 2023-07-15 20:57:32 | 2024-07-04 00:41:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int N = 1e5 + 7;
ll pref[N];
struct Info {
ll ans[2];
int tag = 0, lx = 0, rx = 0, L = 0, R = 0;
void rev() {
tag ^= 1;
swap(ans[0], ans[1]);
}
Info() = default;
Info(int l, int r) : lx(l), rx(r), tag(0), L(0), R(0) {
ans[0] = 0, ans[1] = pref[r] - pref[l];
}
};
Info t[N * 50];
int top = 1;
int create(int l, int r) {
t[top++] = Info(l, r);
return top - 1;
}
void push(int x) {
if (!t[x].L) {
t[x].L = create(t[x].lx, t[x].lx + t[x].rx >> 1);
}
if (!t[x].R) {
t[x].R = create(t[x].lx + t[x].rx >> 1, t[x].rx);
}
}
void pull(int x) {
int lx = t[x].lx, rx = t[x].rx, mid = lx + rx >> 1;
t[x].ans[0] = t[x].ans[1] = 0;
if (!t[x].L) {
t[x].ans[1] = pref[mid] - pref[lx];
} else {
t[x].ans[1] = t[t[x].L].ans[1];
t[x].ans[0] = t[t[x].L].ans[0];
}
if (!t[x].R) {
t[x].ans[1] += pref[rx] - pref[mid];
} else {
t[x].ans[1] += t[t[x].R].ans[1];
t[x].ans[0] += t[t[x].R].ans[0];
}
if (t[x].tag) {
swap(t[x].ans[0], t[x].ans[1]);
}
}
void rangeApply(int x, int l, int r) {
if (t[x].lx >= r || l >= t[x].rx) {
return;
}
if (l <= t[x].lx && t[x].rx <= r) {
return t[x].rev();
}
push(x);
rangeApply(t[x].L, l, r);
rangeApply(t[x].R, l, r);
pull(x);
}
int query(int x, int i) {
if (x == 0) {
return 0;
} else if (t[x].lx + 1 == t[x].rx) {
return t[x].tag;
} else {
return t[x].tag ^ query(i < (t[x].lx + t[x].rx >> 1) ? t[x].L : t[x].R, i);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
a[i] /= 2;
}
vector<int> yy = a;
sort(yy.begin(), yy.end());
yy.resize(unique(yy.begin(), yy.end()) - yy.begin());
const int m = size(yy);
auto func = [&](int l, int r)-> ll {
l -= 1, r -= 1;
return (r - l + 1) + 1LL * r * (r + 1) - 1LL * l * (l - 1);
};
for (int i = 1; i <= m; ++i) {
pref[i] = pref[i - 1] + func(i == 1 ? 1 : yy[i - 2] + 1, yy[i - 1]);
}
vector<int> roots(2 * n);
vector<set<int>> st(2 * n);
for (int i = 0; i < n; ++i) {
a[i] = lower_bound(yy.begin(), yy.end(), a[i]) - yy.begin();
roots[i] = create(0, m);
a[i] += 1;
rangeApply(roots[i], 0, a[i]);
st[i] = {a[i]};
}
cout << endl;
for (int i = 0; i + 1 < n; ++i) {
int x, y;
cin >> x >> y;
x -= 1, y -= 1;
ll init = (t[roots[x]].ans[0] + t[roots[y]].ans[0]);
if (st[x].size() > st[y].size()) {
swap(x, y);
}
int last = 0;
for (int c : st[x]) {
st[y].insert(c);
if (query(roots[x], c - 1)) {
rangeApply(roots[y], last, c);
}
last = c;
}
cout << 2 * (init - t[roots[y]].ans[0]) << '\n';
st[x].clear();
roots[n + i] = roots[y];
swap(st[n + i], st[y]);
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 28ms
memory: 199460kb
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 2157616743...
result:
wrong answer 1st lines differ - expected: '359872811236', found: ''
Subtask #2:
score: 0
Wrong Answer
Test #27:
score: 0
Wrong Answer
time: 173ms
memory: 215068kb
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 350...
result:
wrong answer 1st lines differ - expected: '349058819344', found: ''
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 472114675...
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%