QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#370186 | #6671. Zadatak | lukap_ | 0 | 17ms | 21888kb | C++14 | 3.5kb | 2024-03-28 22:49:20 | 2024-03-28 22:49:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 500;
const int OFF = (1 << 18);
int n;
int niz[MAXN], sazet[MAXN];
vector<int> v, bizut;
set<int> vek[2 * MAXN];
int roots[2 * MAXN],l[2 * OFF], r[2 * OFF], lazy[2 * OFF], vel[2 * MAXN];
ll val[2 * OFF];
int cnt;
void novi () {
l[cnt] = -1;
r[cnt] = -1;
cnt++;
}
void prop (int x, ll lo, ll hi) {
if (lazy[x] == 0) return;
ll uk = 4 * hi * hi;
if (lo > 0) uk -= 4 * lo * lo;
// cout << "BLOOOOOOOOOOOOOOOOOOB " << x << ' ' << uk << ' ' << val[x] << "\n";
val[x] = uk - 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 (int a, int b, int x, int lo = 0, int 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;
}
int 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 (int a, int b, int x, int lo = 0, int 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];
}
int 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 (int x, int y) {
ll cijena = 0;
bizut.clear ();
for (auto it: vek[y]) bizut.push_back(it);
for (int i = (int) bizut.size () - 1; i >= 0; i-=2) {
int 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 (int i = 0; i < n; i++) {
sazet[i] = lower_bound (v.begin (), v.end (), niz[i]) - v.begin ();
roots[i] = cnt;
vel[i] = 1;
novi ();
update (0, niz[i], roots[i]);
vek[i].insert (niz[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;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 17ms
memory: 21888kb
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:
274877906944 274877906944 0 251229507984 0 0 142492660324 274877906944 0 89244392644 274877906944 274877906944 274877906944 0 274877906944 0 0 59479405456 28418613120 60443205904 0 233545212468 40368894028 0 185633514300 48875498616 110184983536 48091970200 83973607524 274877906944 0 190904299420 83...
result:
wrong answer 1st lines differ - expected: '359872811236', found: '274877906944'
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%