QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#327213 | #4802. Ternary Search | Terdy | WA | 107ms | 13324kb | C++14 | 1.5kb | 2024-02-14 20:35:28 | 2024-02-14 20:35:29 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n , a[N] , h[N] , cnt , ans[N] , p[N];
int L[N] , R[N];
vector< int > vec[N];
struct BIT
{
int s[N];
int Lowbit(int x) {return x & -x;}
void Upt(int x , int d) {for(; x <= n; x += Lowbit(x)) s[x] += d;}
int Query(int x) {int res = 0; for(; x; x -= Lowbit(x)) res += s[x]; return res;}
void init() {memset(s , 0 , sizeof(s));}
} bit;
void solve()
{
for(int i = 1; i <= n; i++)
{
L[i] = bit.Query(n) - bit.Query(a[i]);
bit.Upt(a[i] , 1);
}
bit.init();
for(int i = 1; i <= n; i++) vec[i].clear() , p[a[i]] = i;
for(int i = n; i; i--)
{
int x = p[i] , r = x;
for(int j = 17; ~j; j--)
{
int nr = r + (1 << j);
if(nr <= n && bit.Query(nr) - L[x] <= L[x]) r = nr;
}
vec[r].push_back(x);
bit.Upt(x , 1);
}
int delta = 0;
bit.init();
for(int i = 1; i <= n; i++)
{
delta += bit.Query(a[i]);
ans[i] = min(ans[i] , delta);
bit.Upt(a[i] , 1);
for(int j = 0; j < vec[i].size(); j++) bit.Upt(a[vec[i][j]] , -1);
}
bit.init();
}
int main()
{
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i] , h[++cnt] = a[i];
sort(h + 1 , h + cnt + 1) , cnt = unique(h + 1 , h + cnt + 1) - h - 1;
for(int i = 1; i <= n; i++) a[i] = lower_bound(h + 1 , h + cnt + 1 , a[i]) - h;
memset(ans , 0x3f , sizeof(ans));
solve();
for(int i = 1; i <= n; i++) a[i] = n - a[i] + 1;
solve();
for(int i = 1; i <= n; i++) cout << ans[i] << '\n';
return 0;
}
/*
9
11
4
5
14
1
9
19
8
10
*/
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 9864kb
input:
9 11 4 5 14 1 9 19 8 10
output:
0 0 0 0 2 3 3 6 7
result:
ok 9 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 9880kb
input:
1 167959139
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 9812kb
input:
10 802030518 983359971 96204862 640274071 796619138 71550121 799843967 598196518 402690754 446173607
output:
0 0 0 1 1 3 3 5 7 9
result:
ok 10 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 9896kb
input:
200 280383943 994080326 443906342 107926501 414713819 45732490 370693588 928126378 581740643 189811400 142817640 218386999 447997927 640003704 637428425 151698689 209462128 155599305 390080477 958251194 515653943 751042490 1186761 443171900 968975479 829084542 462837689 157692260 607049612 606116398...
output:
0 0 0 0 1 1 3 4 5 8 12 15 17 18 19 25 30 35 38 38 41 42 54 60 60 62 69 81 87 93 109 112 124 126 139 148 152 164 169 180 187 193 211 221 226 244 244 252 264 273 286 307 316 328 339 358 378 392 408 416 439 445 447 463 490 503 521 536 547 567 594 619 638 638 659 668 702 724 729 758 772 777 816 836 845 ...
result:
ok 200 numbers
Test #5:
score: 0
Accepted
time: 0ms
memory: 9900kb
input:
205 798721503 163087712 141733092 316449050 127486543 148708227 646902722 254007921 648511970 807308399 362190286 356609247 109012359 421274742 647319513 34648738 573893368 682755343 757300027 674077117 324958818 106483343 305773689 837270774 883136402 847234810 756696363 354615040 58759846 32739626...
output:
0 0 0 0 1 2 2 3 3 3 6 10 16 19 22 23 28 34 35 37 45 49 52 61 64 65 69 80 86 86 90 95 105 109 112 113 120 133 136 136 152 166 180 181 196 214 231 245 266 287 297 309 330 341 358 368 383 387 393 414 434 448 456 484 494 506 521 534 543 551 561 596 621 626 634 644 655 692 732 743 750 767 807 846 869 876...
result:
ok 205 numbers
Test #6:
score: 0
Accepted
time: 0ms
memory: 9972kb
input:
300 310486422 145995805 744831366 913444383 54589620 760840937 351438066 497043991 437781614 854981783 137693561 940050335 22692948 779922082 713507093 773173557 700078081 889701510 709956997 620732070 535136113 428608043 656183847 627784826 348865620 634573459 271461607 622653937 662713549 35111166...
output:
0 0 0 0 1 2 3 5 7 9 11 14 15 19 22 25 27 33 36 38 40 41 45 49 50 55 55 60 69 71 76 80 99 110 110 116 117 125 148 151 175 182 208 223 229 245 256 259 280 285 302 314 332 337 345 369 380 398 403 405 413 447 468 484 494 511 537 550 555 585 601 616 637 659 664 695 715 730 755 757 762 777 787 805 842 860...
result:
ok 300 numbers
Test #7:
score: 0
Accepted
time: 0ms
memory: 9904kb
input:
400 418345904 425283570 502048611 949470422 1539681 816939105 835973188 548395262 912622971 892988664 137695077 200974194 416058059 46966392 717454596 508236934 577018523 271703565 404875844 116208843 795979997 232130698 201391686 396794371 873677110 643916648 979303165 209135495 365323814 220296329...
output:
0 0 0 0 0 1 3 4 7 8 8 9 11 11 16 20 25 28 32 33 43 47 50 55 67 73 73 83 90 98 99 103 110 116 124 135 142 160 175 182 195 197 210 216 217 222 228 234 254 268 295 306 334 337 349 357 383 388 392 420 441 460 473 474 480 491 506 532 548 549 572 589 629 635 674 700 711 714 744 773 797 809 815 852 860 895...
result:
ok 400 numbers
Test #8:
score: 0
Accepted
time: 12ms
memory: 10212kb
input:
10000 654266585 918195389 61806003 512260326 35440115 595032690 353979552 32592347 712550231 380796590 139710715 828841723 115308806 675515525 910499939 780014628 924148821 719010926 731425929 381219228 963983190 359044179 76245693 524823828 890447664 856974623 751508756 830808517 963022804 54360656...
output:
0 0 0 1 1 2 3 5 5 7 10 10 14 16 16 18 18 22 26 34 34 45 54 57 64 70 76 82 87 94 97 97 104 108 118 125 136 143 143 159 162 165 169 172 181 202 210 213 224 230 240 255 257 277 279 307 337 342 364 367 377 403 408 416 428 459 496 504 533 534 554 571 577 595 630 637 666 684 723 740 782 797 818 840 864 87...
result:
ok 10000 numbers
Test #9:
score: -100
Wrong Answer
time: 107ms
memory: 13324kb
input:
100000 909264242 651840489 623350850 547495386 693908264 894663677 90585843 745747150 871758382 121892899 769215576 332202967 626472418 629926442 365356165 588776397 879320123 676708911 253241624 334264710 58088451 743496068 4060883 166883807 81383194 778842188 617677263 814376024 454099047 56897081...
output:
0 0 0 0 0 0 2 3 4 8 9 13 16 19 24 27 27 29 37 43 43 52 52 54 56 70 76 77 83 89 90 92 101 106 116 127 141 146 160 171 186 192 198 207 207 208 229 247 247 268 281 297 310 323 326 339 359 365 379 395 409 417 422 436 455 465 474 493 506 511 541 575 590 618 631 646 677 689 725 742 751 782 786 801 837 867...
result:
wrong answer 92154th numbers differ - expected: '1061137357', found: '1061109567'