QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#617546 | #9249. Elimination Series Once More | castc# | ML | 1ms | 4112kb | C++20 | 4.0kb | 2024-10-06 16:07:00 | 2024-10-06 16:07:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
// #define int long long
const int MAXN = 5e7 + 9;
int tot = 0;
struct Info {
Info *l = nullptr;
Info *r = nullptr;
int sum = 0;
} info[MAXN];
void pull(Info *&p) {
p->sum = p->l->sum + p->r->sum;
}
void push(Info *&p) {
if(p->l == nullptr) {
p->l = &info[tot++];
}
if(p->r == nullptr) {
p->r = &info[tot++];
}
}
void build(Info *&p, int l, int r) {
if(l == r) {
p->sum = 0;
return;
}
int x = (l + r) / 2;
push(p);
build(p->l, l, x);
build(p->r, x + 1, r);
}
void update(Info *&p, Info *&q, int l, int r, int pos, int v) {
if(l == r) {
p->sum += v;
return;
}
int x = (l + r) / 2;
if(x >= pos) {
p->r = q->r;
p->l = &info[tot++];
p->l->sum = q->l->sum;
update(p->l, q->l, l, x, pos, v);
} else {
p->l = q->l;
p->r = &info[tot++];
p->r->sum = q->r->sum;
update(p->r, q->r, x + 1, r, pos, v);
}
pull(p);
}
int query(Info *&L, Info *&R, int l, int r, int k) {
if(l == r) {
return l;
}
int t = R->l->sum - L->l->sum;
int x = (l + r) / 2;
if(t >= k) {
return query(L->l, R->l, l, x, k);
} else {
return query(L->r, R->r, x + 1, r, k - t);
}
}
void init_end() {
for(int i = 0; i < tot; i++) {
info[i] = Info();
}
tot = 0;
}
void solve() {
int n, k;
cin >> n >> k;
int N = (1ll << n);
vector<Info *> p(N + 1);
p[0] = &info[tot++];
vector<int> a(N), c(N), pos(N);
for(int i = 0; i < N; i++) {
cin >> a[i];
}
auto b = a;
sort(b.begin(), b.end());
b.erase(unique(b.begin(), b.end()), b.end());
int M = (int)b.size();
build(p[0], 0, M - 1);
for(int i = 0; i < N; i++) {
p[i + 1] = &info[tot++];
c[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
pos[c[i]] = a[i];
update(p[i + 1], p[i], 0, M - 1, c[i], 1);
}
for(int i = 0; i < N; i++) {
int l = 0, r = n, ans = 0;
while(l <= r) {
int mid = (l + r) >> 1;
int L = (i >> mid);
int R = L + 1;
// cout << mid << " " << L << " " << R << "a\n";
L <<= mid;
R <<= mid;
L++;
if(k >= R - L && a[i] >= R - L + 1) {
l = mid + 1;
ans = mid;
} else if(a[i] >= R - L + 1 && pos[query(p[L - 1], p[R], 0, M - 1, R - L + 2 - (k + 1))] <= a[i]) {
l = mid + 1;
ans = mid;
} else {
r = mid - 1;
}
}
cout << ans << " \n"[i == N - 1];
// int L = 1, R = N, ans = n;
// while(L <= R) {
// if(k >= R - L) {
// if(a[i] >= R - L + 1) {
// cout << ans << " \n"[i == N - 1];
// break;
// }
// } else {
// if(a[i] >= R - L + 1 && pos[query(p[L - 1], p[R], 0, M - 1, R - L + 2 - (k + 1))] <= a[i]) {
// cout << ans << " \n"[i == N - 1];
// break;
// }
// }
// int mid = (L + R) / 2;
// ans--;
// if(i < mid) {
// R = mid;
// } else {
// L = mid + 1;
// }
// }
}
// for(int i = 0; i < m; i++) {
// int l, r, k;
// cin >> l >> r >> k;
// l--;
// cout << pos[query(p[l], p[r], 0, M - 1, k)] << "\n";
// }
// init_end();
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
// cin >> T;
while(T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
2 1 1 2 3 4
output:
0 1 1 2
result:
ok 4 number(s): "0 1 1 2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
3 5 2 4 7 5 3 8 6 1
output:
1 2 2 2 1 3 2 0
result:
ok 8 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
3 0 1 2 7 4 5 8 3 6
output:
0 1 2 0 0 3 0 1
result:
ok 8 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
3 5 3 7 1 2 4 8 5 6
output:
1 2 0 1 2 3 2 2
result:
ok 8 numbers
Test #5:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
3 3 3 4 8 2 7 6 1 5
output:
1 2 3 1 2 2 0 2
result:
ok 8 numbers
Test #6:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
3 3 4 2 6 8 3 5 1 7
output:
2 1 2 3 1 2 0 2
result:
ok 8 numbers
Test #7:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
3 4 5 8 1 3 2 4 6 7
output:
2 3 0 1 1 2 2 2
result:
ok 8 numbers
Test #8:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
3 1 7 3 8 6 5 2 4 1
output:
2 1 3 1 2 1 2 0
result:
ok 8 numbers
Test #9:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
3 4 1 2 5 3 6 7 4 8
output:
0 1 2 1 2 2 2 3
result:
ok 8 numbers
Test #10:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
3 2 2 4 8 6 3 7 5 1
output:
1 2 3 2 1 2 2 0
result:
ok 8 numbers
Test #11:
score: 0
Accepted
time: 1ms
memory: 3900kb
input:
10 780 495 929 348 345 426 543 187 419 839 812 320 1018 251 284 944 258 721 640 730 528 316 247 313 195 809 948 261 615 805 213 388 894 1005 77 599 636 881 444 144 923 240 520 592 465 96 455 563 943 237 860 531 269 106 989 740 506 23 224 84 475 108 718 3 16 731 436 591 627 672 300 573 613 253 637 46...
output:
8 9 8 8 8 9 7 8 9 9 8 9 7 8 9 8 9 9 9 9 8 7 8 7 9 9 8 9 9 7 8 9 9 6 9 9 9 8 7 9 7 9 9 8 6 8 9 9 7 9 9 8 6 9 9 8 4 7 6 8 6 9 1 4 9 8 9 9 9 8 9 9 7 9 8 9 9 9 6 7 6 7 9 9 9 9 9 7 6 8 8 8 9 9 6 6 9 9 9 8 9 9 6 9 9 8 6 7 8 8 3 8 8 9 6 9 7 8 8 9 9 9 9 8 7 9 8 8 7 7 9 9 9 9 9 8 8 9 6 9 9 9 9 9 9 6 9 8 8 9 ...
result:
ok 1024 numbers
Test #12:
score: 0
Accepted
time: 1ms
memory: 4084kb
input:
10 175 10 301 861 580 539 53 822 97 923 133 952 870 438 265 55 825 557 784 976 584 993 897 981 259 875 18 106 399 1019 692 336 485 491 9 565 114 738 128 678 23 562 538 869 787 768 385 494 640 655 666 332 930 798 418 801 266 1009 846 54 37 967 139 394 802 168 503 233 848 340 329 240 898 251 1023 779 ...
output:
3 7 9 8 8 5 9 6 9 7 9 9 8 7 5 9 8 9 9 8 9 9 9 7 9 4 6 8 9 9 8 8 8 3 8 6 9 7 9 4 8 8 9 9 9 8 8 8 8 8 8 9 9 8 9 7 9 9 5 5 9 7 8 9 7 8 7 9 8 8 7 9 7 9 9 9 8 8 9 9 8 7 9 7 8 6 8 5 5 9 9 7 8 9 6 5 8 9 8 5 7 8 9 7 6 9 8 9 8 2 6 9 8 9 9 8 8 5 9 8 9 7 9 9 9 6 9 9 7 10 9 8 9 9 9 7 8 7 8 8 8 6 7 6 7 4 8 9 9 8...
result:
ok 1024 numbers
Test #13:
score: 0
Accepted
time: 0ms
memory: 3900kb
input:
10 15 829 331 590 799 39 456 888 779 60 411 796 148 678 930 101 653 81 429 4 457 455 703 780 260 251 21 291 122 366 177 665 326 114 96 445 123 154 340 522 113 895 170 144 857 447 865 874 891 679 541 867 731 436 219 871 596 285 1008 435 263 881 798 16 275 14 97 845 269 974 782 343 404 561 540 443 482...
output:
6 4 5 6 4 5 7 5 4 4 6 4 5 7 4 5 4 5 2 5 5 5 6 4 4 4 4 4 4 4 5 4 4 4 4 4 4 4 5 4 7 4 4 6 5 6 7 7 5 5 6 5 4 4 6 5 4 9 4 4 7 6 4 4 3 4 6 4 8 6 4 4 5 5 4 5 7 7 4 4 4 4 4 5 9 4 4 7 5 8 4 4 6 4 6 9 6 4 8 5 5 4 4 4 5 4 5 5 4 4 4 4 5 4 5 5 4 5 4 4 5 4 4 6 4 9 5 6 8 6 5 6 6 7 4 4 4 4 4 4 4 3 4 4 4 4 6 7 7 5 ...
result:
ok 1024 numbers
Test #14:
score: 0
Accepted
time: 1ms
memory: 3928kb
input:
10 215 910 367 1011 675 689 697 604 665 730 306 743 225 210 1008 546 439 411 475 529 640 54 505 420 481 213 406 1012 933 392 121 751 554 265 550 621 537 212 908 49 918 768 125 16 927 507 863 1000 44 900 7 645 543 784 461 569 669 984 249 189 727 497 994 719 282 666 691 58 795 119 515 682 150 53 494 6...
output:
9 8 9 9 9 9 9 9 9 8 9 7 7 9 8 8 8 8 8 9 5 8 8 8 7 8 9 9 8 6 9 8 8 8 9 8 7 9 5 9 9 6 4 9 8 9 9 5 9 2 9 8 9 8 8 9 9 7 7 9 8 9 9 8 9 9 5 9 6 8 9 7 5 8 9 8 9 9 7 9 8 9 9 9 8 9 7 5 8 7 9 8 8 6 9 9 8 6 5 9 8 8 9 8 7 9 9 8 6 4 9 6 9 8 8 9 7 8 9 8 5 8 8 9 8 9 8 9 9 8 8 7 5 9 9 9 9 9 8 8 9 9 6 8 6 8 6 9 9 9 ...
result:
ok 1024 numbers
Test #15:
score: 0
Accepted
time: 1ms
memory: 3924kb
input:
10 358 714 252 544 999 507 766 720 169 379 856 698 40 910 610 564 125 278 426 285 205 746 43 23 284 81 525 848 540 827 604 630 741 27 313 452 724 9 745 762 263 44 901 864 445 418 596 310 719 988 536 799 625 202 895 412 153 847 145 353 297 133 260 717 893 158 314 90 356 108 315 1016 510 1015 1007 747...
output:
9 7 9 9 8 9 9 7 8 9 9 5 9 9 9 6 8 8 8 7 9 5 4 8 6 9 9 9 9 9 9 9 4 8 8 9 3 9 9 8 5 9 9 8 8 9 8 9 9 9 9 9 7 9 8 7 9 7 8 8 7 8 9 9 7 8 6 8 6 8 9 8 9 9 9 7 9 9 7 9 6 9 9 7 8 7 9 7 8 7 9 9 7 9 9 4 8 9 8 9 9 9 7 9 6 9 8 9 9 9 8 9 9 9 8 3 8 9 4 7 8 8 8 8 8 8 9 6 8 6 9 7 9 9 8 7 9 9 9 9 7 8 9 8 9 8 9 7 8 9 ...
result:
ok 1024 numbers
Test #16:
score: 0
Accepted
time: 1ms
memory: 4112kb
input:
10 409 720 603 348 938 361 756 506 176 661 192 318 599 115 548 681 692 915 148 721 93 424 707 404 392 695 342 247 799 743 814 82 120 365 428 461 355 184 372 224 810 225 569 630 800 480 226 802 867 136 592 723 412 248 619 817 67 891 72 74 315 624 250 1001 73 536 397 859 553 647 143 575 733 468 298 71...
output:
9 9 8 9 8 9 8 7 9 7 8 9 6 9 9 9 9 7 9 6 8 9 8 8 9 8 7 9 9 9 6 6 8 8 8 8 7 8 7 9 7 9 9 9 8 7 9 9 7 9 9 8 7 9 9 6 9 6 6 8 9 7 9 6 9 8 9 9 9 7 9 9 8 8 9 6 9 9 8 9 9 9 7 8 8 9 5 9 7 7 7 9 9 9 8 7 8 9 8 8 8 8 4 8 8 9 9 8 6 9 9 9 2 9 7 9 8 9 8 7 8 7 9 6 6 9 9 9 7 9 9 8 9 9 9 9 8 9 8 8 8 9 9 9 8 9 6 9 8 9 ...
result:
ok 1024 numbers
Test #17:
score: 0
Accepted
time: 1ms
memory: 3864kb
input:
10 700 469 249 763 385 977 949 423 11 825 442 744 993 553 908 410 860 465 291 751 234 50 897 64 346 481 1010 444 88 605 268 531 167 853 367 389 191 784 723 783 277 916 649 418 932 516 972 714 905 358 364 334 293 391 337 785 837 721 568 555 102 456 554 165 141 253 852 43 109 699 963 915 611 16 156 83...
output:
8 7 9 8 9 9 8 3 9 8 9 9 9 9 8 9 8 8 9 7 5 9 6 8 8 9 8 6 9 8 9 7 9 8 8 7 9 9 9 8 9 9 8 9 9 9 9 9 8 8 8 8 8 8 9 9 9 9 9 6 8 9 7 7 7 9 5 6 9 9 9 9 4 7 6 8 9 9 9 7 6 5 8 8 9 8 8 8 9 7 8 9 8 8 7 9 7 9 6 6 8 9 5 9 9 8 9 8 9 9 9 8 9 8 8 9 7 9 8 6 8 6 9 9 6 9 9 5 8 7 8 9 8 8 9 6 7 7 9 8 9 9 9 9 9 6 9 9 7 6 ...
result:
ok 1024 numbers
Test #18:
score: 0
Accepted
time: 1ms
memory: 3924kb
input:
10 655 971 111 296 479 453 490 163 686 195 492 1014 762 1021 15 351 618 137 181 853 758 876 598 703 486 125 35 41 266 603 682 733 294 391 967 373 508 860 501 1018 1003 642 365 531 883 89 674 869 311 442 734 886 165 701 139 447 271 540 190 983 474 816 769 1015 101 896 904 692 627 643 750 615 20 406 5...
output:
9 6 8 8 8 8 7 9 7 8 9 9 9 3 8 9 7 7 9 9 9 9 9 8 6 5 5 8 9 9 9 8 8 9 8 8 9 8 9 9 9 8 9 9 6 9 9 8 8 9 9 7 9 7 8 8 9 7 9 8 9 9 9 6 9 9 9 9 9 9 9 4 8 8 7 8 7 9 9 8 2 9 9 9 9 9 9 5 8 7 9 9 7 8 8 6 7 7 7 8 9 9 9 9 9 7 9 9 9 5 9 9 7 7 9 9 8 9 7 6 7 8 9 8 4 9 8 9 9 9 8 9 8 8 9 5 8 7 4 9 9 9 6 8 8 9 8 9 9 8 ...
result:
ok 1024 numbers
Test #19:
score: 0
Accepted
time: 1ms
memory: 4088kb
input:
10 827 692 816 52 570 178 260 248 531 852 777 232 378 955 632 325 256 328 599 802 165 966 493 166 125 488 942 965 716 947 276 156 894 194 742 933 185 384 152 277 333 991 424 487 435 423 504 113 106 307 205 745 155 654 226 16 518 884 757 1009 133 401 392 451 510 682 717 922 608 148 206 854 355 728 51...
output:
9 9 5 9 7 8 7 9 9 9 7 8 9 9 8 8 8 9 9 7 9 8 7 6 8 9 9 9 9 8 7 9 7 9 9 7 8 7 8 8 9 8 8 8 8 8 6 6 8 7 9 7 9 7 4 9 9 9 9 7 8 8 8 8 9 9 9 9 7 7 9 8 9 8 7 7 5 7 8 9 8 8 8 9 9 7 9 6 9 8 6 6 4 9 8 5 9 6 9 9 7 9 9 6 9 9 8 8 9 9 9 9 9 9 8 2 6 9 9 9 7 8 9 9 2 8 7 8 8 8 7 9 9 8 9 8 4 9 9 8 9 8 8 9 4 8 9 9 9 6 ...
result:
ok 1024 numbers
Test #20:
score: 0
Accepted
time: 1ms
memory: 3924kb
input:
10 328 454 408 810 540 254 321 33 682 91 53 398 761 1023 243 581 545 825 892 100 356 17 326 487 878 787 756 996 707 770 924 945 272 428 686 339 908 390 645 238 337 517 364 717 404 533 394 849 435 894 947 482 806 657 39 781 946 75 656 129 476 676 984 456 412 463 160 562 592 345 141 145 501 921 991 21...
output:
8 8 9 9 7 8 5 9 6 5 8 9 9 7 9 9 9 9 6 8 4 8 8 9 9 9 9 9 9 9 9 8 8 9 8 9 8 9 7 8 9 8 9 8 9 8 9 8 9 9 8 9 9 5 9 9 6 9 7 8 9 9 8 8 8 7 9 9 8 7 7 8 9 9 7 8 6 5 9 9 3 9 9 6 9 9 6 9 1 9 9 8 8 8 8 8 8 9 8 9 8 5 8 9 7 9 8 7 8 9 9 8 8 2 9 7 8 9 7 9 8 9 9 9 8 8 9 9 9 8 9 6 7 9 9 8 8 9 7 9 9 9 9 9 9 9 9 4 6 9 ...
result:
ok 1024 numbers
Test #21:
score: 0
Accepted
time: 1ms
memory: 3964kb
input:
10 825 601 142 625 471 287 405 117 857 340 984 863 530 575 994 436 394 529 25 141 332 735 966 1 831 673 896 89 272 649 81 384 242 864 817 174 382 145 469 577 715 893 275 914 455 667 169 179 521 305 925 976 213 40 380 659 499 918 725 561 616 948 924 1022 721 235 485 85 781 540 52 892 982 254 461 381 ...
output:
9 7 9 8 8 8 6 9 8 9 9 9 9 9 8 8 9 4 7 8 9 9 0 9 9 9 6 8 9 6 8 7 9 9 7 8 7 8 9 9 9 8 9 8 9 7 7 9 8 9 9 7 5 8 9 8 9 9 9 9 9 9 9 9 7 8 6 9 9 5 9 9 7 8 8 9 9 6 9 9 9 9 8 4 5 7 9 9 8 5 9 9 9 7 9 6 8 9 2 6 9 8 9 7 7 9 9 9 9 9 9 7 8 8 9 9 9 6 9 8 7 9 9 6 9 9 9 4 9 8 9 9 9 8 7 8 7 8 7 8 9 8 4 9 9 9 6 7 7 9 ...
result:
ok 1024 numbers
Test #22:
score: -100
Memory Limit Exceeded
input:
20 0 179487 921757 700836 1026745 871114 487101 416568 943369 555729 702080 475044 257810 489454 716476 879881 237658 884615 645342 654881 754504 537330 488794 60810 581898 627225 134547 267586 35544 535278 202909 1006004 182486 863804 12271 705426 1000913 315415 495258 494119 323180 59354 347058 62...
output:
0 1 0 5 1 0 0 2 0 2 1 0 0 1 3 0 3 0 0 1 1 0 0 2 2 0 1 0 1 0 4 0 1 0 0 3 0 2 1 0 0 1 0 2 1 0 6 0 4 0 0 1 0 1 0 2 2 0 0 1 0 3 0 1 4 0 0 1 2 0 0 1 0 1 0 3 0 1 2 0 2 0 1 0 3 0 0 1 1 0 12 0 2 0 1 0 0 1 4 0 0 1 2 0 0 3 0 1 0 1 0 2 1 0 2 0 0 1 3 0 0 1 0 5 0 1 2 0 1 0 0 3 1 0 0 2 1 0 4 0 2 0 0 1 1 0 2 0 0 5...