QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#226383 | #7327. Median on Binary Tree | PPP# | AC ✓ | 92ms | 50612kb | C++17 | 2.7kb | 2023-10-25 21:47:33 | 2023-10-25 21:47:33 |
Judging History
answer
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
typedef long double ld;
int n;
const int maxN = 2e5 + 10;
int w[maxN];
vector<int> dp[maxN];
vector<int> sub[maxN];
int ans[maxN];
int TRASH[maxN];
int SZ = 0;
void solve() {
for (int i = 1; i <= n; i++) {
cin >> w[i];
}
for (int i = 0; i <= n; i++) ans[i] = 0;
for (int i = n; i >= 1; i--) {
sub[i].emplace_back(w[i]);
SZ = 0;
if (2 * i > n) {
SZ = 1;
TRASH[0] = n + 1;
}
else if (2 * i + 1 > n) {
SZ = sub[2 * i].size();
for (int j = 0; j < SZ; j++) TRASH[j] = sub[2 * i][j];
}
else {
merge(sub[2 * i].begin(), sub[2 * i].end() - 1, sub[2 * i + 1].begin(), sub[2 * i + 1].end(), TRASH);
SZ = sub[2 * i].size() + sub[2 * i + 1].size() - 1;
}
assert(TRASH[SZ - 1] == n + 1);
sub[i].resize(SZ + 1);
int fi_g = -1;
for (int j = 0; j < SZ; j++) {
if (TRASH[j] >= w[i]) {
fi_g = j;
break;
}
}
assert(fi_g != -1);
for (int p = 0; p < fi_g; p++) {
sub[i][p] = TRASH[p];
}
sub[i][fi_g] = w[i];
for (int p = fi_g; p < SZ; p++) {
sub[i][p + 1] = TRASH[p];
}
dp[i].resize(sub[i].size());
int pt_l = 0;
int pt_r = 0;
const int INF = -1e9;
int Q = 0;
for (int p : sub[i]) {
int S = -INF;
if (w[i] >= p) S = 1;
else S = -1;
if (n >= 2 * i) {
while (sub[2 * i][pt_l] < p) pt_l++;
assert(pt_l < sub[2 * i].size());
S += dp[2 * i][pt_l];
}
if (n >= 2 * i + 1) {
while (sub[2 * i + 1][pt_r] < p) {
pt_r++;
}
assert(pt_r < sub[2 * i + 1].size());
S += dp[2 * i + 1][pt_r];
}
if (S >= 1) {
ans[S - 1] = max(ans[S - 1], p);
}
S = max(S, 0);
dp[i][Q] = S;
Q++;
}
}
for (int i = n - 2; i >= 0; i--) ans[i] = max(ans[i], ans[i + 1]);
ans[0] = n;
for (int i = 0; i < n; i++) cout << ans[i] << " ";
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
while (cin >> n) {
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 13004kb
input:
5 1 2 3 4 5 10 9 10 4 2 3 5 7 1 8 6
output:
5 2 2 1 1 10 9 5 4 4 3 3 2 2 1
result:
ok 15 numbers
Test #2:
score: 0
Accepted
time: 26ms
memory: 14228kb
input:
10 4 10 7 9 5 3 1 2 6 8 10 7 10 2 4 9 8 3 1 5 6 10 1 5 8 3 6 7 2 4 10 9 10 7 9 3 6 2 1 10 5 4 8 10 7 1 9 2 4 5 3 6 8 10 10 2 7 5 9 10 3 1 4 8 6 10 9 8 1 2 6 10 5 4 3 7 10 3 6 1 9 10 8 2 7 4 5 10 7 3 8 10 4 1 5 2 6 9 10 6 10 7 5 2 9 1 4 3 8 10 6 8 5 10 9 4 2 1 3 7 10 4 3 5 9 1 2 8 7 10 6 10 7 5 10 8 ...
output:
10 9 6 5 5 4 4 3 2 1 10 9 7 6 4 4 3 2 2 1 10 7 5 5 4 3 3 2 1 1 10 7 6 5 4 3 3 2 2 1 10 7 5 4 4 3 2 2 1 1 10 8 7 7 6 4 3 2 2 1 10 8 6 6 5 3 2 2 1 1 10 7 6 6 5 4 3 2 1 1 10 7 6 5 4 4 3 3 2 1 10 7 6 6 5 4 3 2 2 1 10 8 8 7 6 5 4 3 2 1 10 9 7 4 4 3 3 2 1 1 10 9 7 6 5 5 4 3 2 1 10 7 6 5 5 4 4...
result:
ok 200000 numbers
Test #3:
score: 0
Accepted
time: 30ms
memory: 13828kb
input:
20 2 11 6 16 20 10 14 17 4 19 13 12 18 7 5 15 3 8 9 1 20 7 4 10 16 3 17 6 14 13 20 12 9 15 2 5 18 1 8 11 19 20 2 6 5 16 8 12 20 18 9 15 1 13 19 14 10 7 17 3 4 11 20 18 7 3 13 8 20 10 12 4 9 6 5 17 2 11 16 14 15 19 1 20 6 18 1 16 13 14 9 5 3 12 11 15 2 19 17 20 4 7 10 8 20 9 10 15 1 20 12 2 11 13 18 ...
output:
20 19 16 15 13 11 11 10 10 8 7 6 6 5 4 4 3 2 2 1 20 19 14 13 12 11 10 10 9 8 7 7 6 5 4 4 3 3 2 1 20 17 16 12 12 11 10 9 8 8 7 6 6 5 5 4 3 2 2 1 20 17 13 13 12 12 10 10 8 8 7 7 6 5 4 4 3 3 2 1 20 16 14 13 12 11 9 9 8 7 6 6 5 5 4 3 3 2 1 1 20 18 14 12 11 11 10 10 9 9 8 7 6 5 4 3 2 2 1 1 20 16 15...
result:
ok 200000 numbers
Test #4:
score: 0
Accepted
time: 34ms
memory: 14488kb
input:
500 433 399 424 283 54 137 500 6 69 485 221 63 241 412 95 310 250 233 493 252 414 456 467 257 376 367 226 156 266 194 338 491 121 74 66 475 90 190 402 76 259 486 458 294 275 445 154 407 86 67 223 457 96 317 164 10 419 488 17 293 365 494 308 142 370 18 115 268 309 378 192 232 236 374 443 406 239 363 ...
output:
500 492 456 455 445 445 441 429 424 424 423 420 415 414 414 412 412 406 402 399 399 398 397 394 394 390 388 386 380 379 379 376 376 374 374 373 370 367 367 366 365 363 363 362 360 359 356 354 352 349 348 348 345 344 344 343 342 338 338 336 336 332 330 329 328 326 323 322 321 321 319 318 318 317 317 ...
result:
ok 200000 numbers
Test #5:
score: 0
Accepted
time: 47ms
memory: 14916kb
input:
5000 113 72 4603 52 3749 3915 2551 3016 1389 1434 1675 1794 75 3512 755 57 4318 1768 1797 3986 955 564 2358 2480 3742 4492 1532 90 1448 1636 2291 4626 476 1990 4276 4889 4742 3619 2873 4908 2621 3347 988 4185 1873 2340 160 4507 358 1749 2476 1799 2168 3924 2242 939 803 4436 4688 3547 3899 3466 2455 ...
output:
5000 4920 4822 4586 4574 4484 4453 4451 4436 4430 4416 4411 4389 4382 4382 4367 4366 4364 4355 4350 4347 4327 4327 4322 4318 4318 4314 4308 4308 4306 4306 4293 4286 4286 4276 4275 4271 4271 4267 4266 4266 4265 4259 4259 4236 4235 4235 4229 4226 4226 4225 4225 4214 4214 4205 4203 4203 4197 4194 4185 ...
result:
ok 200000 numbers
Test #6:
score: 0
Accepted
time: 80ms
memory: 50592kb
input:
200000 62591 70889 56518 128330 48628 106769 91396 182986 163821 9121 143386 35763 114265 79582 174540 195402 23798 127306 133671 112928 193899 86527 107351 24688 66393 66196 166115 134288 64022 21714 104980 180651 99059 117401 121402 150628 196619 134051 71911 112158 115204 138053 175707 167839 110...
output:
200000 199784 196343 191462 188913 186936 184084 183712 183693 183637 183564 183165 183145 183026 182986 182986 182837 182837 182814 182784 182734 182734 182665 182628 182513 182427 182294 182168 182168 182125 182125 182085 182069 182069 181935 181935 181832 181801 181593 181427 181425 181425 181240...
result:
ok 200000 numbers
Test #7:
score: 0
Accepted
time: 81ms
memory: 50612kb
input:
200000 79230 169693 50585 127918 147650 167471 161194 193481 109571 112112 20259 119419 160289 48290 136516 71957 119221 56273 76684 194893 55919 123209 89328 68020 163482 12567 84958 110163 45378 169603 58696 84904 194662 411 153476 94282 132806 81534 168421 127827 2827 82407 70810 89670 111369 110...
output:
200000 199468 195939 193105 193105 183929 183773 183667 183482 183417 183314 183236 182719 182706 182689 182411 182318 182251 182186 181968 181968 181908 181862 181862 181755 181729 181711 181711 181696 181688 181519 181514 181514 181510 181457 181414 181304 181211 181165 181140 181116 180992 180992...
result:
ok 200000 numbers
Test #8:
score: 0
Accepted
time: 81ms
memory: 50460kb
input:
200000 152716 177582 61449 111300 140410 78369 181847 16641 130341 193851 45337 58817 27171 117528 39036 166446 30901 47088 156491 8672 60319 31681 147358 141373 161083 164114 155038 188150 8886 158567 25288 17697 63540 43790 83775 157220 193383 171786 164187 177438 72167 117701 46255 76680 55097 16...
output:
200000 199553 196754 195588 191287 191287 186815 185172 185141 185140 185138 185048 184952 184887 184887 184824 184652 184578 184550 184510 184477 184449 184066 184066 184009 183779 183539 183539 183516 183321 183228 183101 183101 183047 182946 182911 182911 182904 182796 182796 182790 182682 182541...
result:
ok 200000 numbers
Test #9:
score: 0
Accepted
time: 74ms
memory: 50464kb
input:
200000 17040 191491 43000 129150 91060 140294 64318 3478 168060 91551 50090 46164 33417 193294 170425 13685 144144 184123 135321 92342 159469 43445 183276 16726 181540 71865 147571 25756 64683 109584 102538 69986 118631 20694 45939 191475 199120 115013 73501 190123 175437 102146 138797 124064 172675...
output:
200000 199631 197264 193806 186027 185934 184916 184204 184166 184123 184123 184099 183816 183606 183594 183582 183563 183505 183451 183318 183276 183276 183173 183077 182840 182759 182759 182741 182631 182631 182486 182260 182230 182230 182037 182028 182014 182014 181993 181829 181828 181792 181716...
result:
ok 200000 numbers
Test #10:
score: 0
Accepted
time: 84ms
memory: 50612kb
input:
200000 3604 195886 198568 106503 119892 150159 29071 22245 122549 169586 14503 64584 154189 175621 32685 139213 119704 121088 58402 24260 108890 79285 173160 117449 178863 139161 84359 187371 26421 69013 171258 107757 162264 14547 132436 9529 48510 56258 131755 140095 192912 145320 133142 14123 9105...
output:
200000 199684 196763 192591 189111 187534 183936 183913 183292 183284 183215 183011 182804 182768 182736 182635 182630 182481 182449 182271 182269 182221 182082 182071 181937 181907 181895 181881 181881 181880 181880 181829 181813 181771 181771 181737 181694 181619 181521 181375 181338 181291 181260...
result:
ok 200000 numbers
Test #11:
score: 0
Accepted
time: 82ms
memory: 50432kb
input:
200000 44271 84530 181721 94194 80411 40902 93503 148859 80801 13572 92894 115119 57756 147570 179754 137866 170061 187153 92172 191063 73146 44571 148075 125563 196136 120899 69765 179121 80044 55748 146895 121432 60835 160903 27467 187155 128610 196659 152784 32283 95051 130880 104458 168117 10116...
output:
200000 199450 197140 194278 192382 192382 189409 189409 184344 184344 184115 184007 184007 183928 183817 183670 183425 183341 183341 183168 183114 183085 182951 182931 182928 182834 182834 182810 182797 182797 182748 182722 182722 182377 182377 182372 182333 182252 182219 182210 182190 182190 182157...
result:
ok 200000 numbers
Test #12:
score: 0
Accepted
time: 89ms
memory: 50612kb
input:
200000 59722 38471 83239 129140 136135 87049 174659 121097 96771 160246 109898 106679 33103 198656 165253 165808 179304 191175 46016 101918 191730 146101 140671 15584 183246 132355 120312 106379 195135 105009 106228 31267 169986 110745 145128 161200 162985 108008 83775 23626 159620 95208 20640 50000...
output:
200000 199754 198192 194835 191878 184865 184819 183694 183694 183368 183352 183255 183145 183098 183034 182715 182675 182651 182587 182576 182572 182431 182318 182303 182241 182241 182163 182110 182095 182027 182027 181996 181868 181868 181850 181840 181836 181836 181791 181791 181772 181670 181631...
result:
ok 200000 numbers
Test #13:
score: 0
Accepted
time: 92ms
memory: 50604kb
input:
200000 112173 84232 193801 193669 173611 47871 68291 63660 22507 14315 128395 129450 104177 23824 90276 168913 169177 181094 118224 151083 175283 48244 197327 2413 195322 143176 30868 152208 80753 42141 28850 69587 38403 54283 47910 176306 118369 96922 118044 43824 176795 108789 91239 194931 169926 ...
output:
200000 199650 197888 194890 187229 185322 182015 181983 181983 181847 181841 181707 181692 181628 181493 181379 181355 181341 181221 181221 181105 181094 181094 181024 181012 181007 180876 180867 180861 180861 180827 180698 180698 180611 180556 180499 180488 180488 180389 180293 180134 180134 180117...
result:
ok 200000 numbers
Test #14:
score: 0
Accepted
time: 81ms
memory: 50412kb
input:
200000 23680 11798 41256 29491 22296 182894 159125 62585 55798 182745 161300 192130 44806 188252 13771 192482 46531 183496 76267 150311 63993 139165 149249 78755 186941 51546 121071 116391 166586 95515 69619 56706 104027 3931 196741 199818 128960 104518 63558 170673 47543 74675 107210 42481 40437 19...
output:
200000 199593 196564 193680 193680 188060 186941 186130 185177 185177 184810 184300 184202 184202 184141 184061 183994 183994 183715 183704 183704 183496 183475 183422 183408 183264 183234 183156 183156 182998 182894 182894 182843 182796 182789 182777 182745 182745 182731 182553 182514 182471 182471...
result:
ok 200000 numbers
Test #15:
score: 0
Accepted
time: 84ms
memory: 50540kb
input:
200000 50906 172602 120714 102614 182555 109470 24275 162529 176919 80498 164276 106024 69054 136163 105434 61527 47483 19899 143616 162983 25930 161190 166332 155112 96247 45066 79855 175654 30568 56827 13241 72615 129030 98095 90617 190185 144561 142396 189888 26183 56240 122666 28527 2023 100774 ...
output:
200000 199796 196768 193298 188705 183520 183509 183503 183503 183456 183418 183249 183236 183216 183210 183210 183127 183063 183036 183036 182799 182736 182616 182566 182555 182555 182552 182461 182461 182451 182389 182327 182189 182029 182029 181978 181939 181887 181857 181857 181820 181800 181708...
result:
ok 200000 numbers
Extra Test:
score: 0
Extra Test Passed