QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#575785#7939. High Towersrqoi031TL 60ms8796kbC++202.3kb2024-09-19 16:46:282024-09-19 16:46:29

Judging History

你现在查看的是最新测评结果

  • [2024-09-19 16:46:29]
  • 评测
  • 测评结果:TL
  • 用时:60ms
  • 内存:8796kb
  • [2024-09-19 16:46:28]
  • 提交

answer

#include<stdio.h>
#include<algorithm>
#include<vector>
#include<tuple>
int a[500005];
int b[500005];
int main() {
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) {
        scanf("%d",a+i),++a[i];
    }
    const auto solve([&](const auto &self,const int &l,const int &r,const int &d,const int &v)->bool {
        if(l>r) {
            return true;
        }
        const auto query([&](const int &x)->int {
            return a[x]-d;
        });
        if(query(l)==r-l+1) {
            return b[l]=v,self(self,l+1,r,d+1,v-1);
        }
        if(l==r) {
            return false;
        }
        int c(l+1);
        while(c<=l+query(l)-1&&query(c)<=query(l)) {
            ++c;
        }
        if(c==l+query(l)) {
            return false;
        }
        std::vector<std::tuple<int,int>> vec;
        std::vector<int> del;
        vec.emplace_back(l,0);
        vec.emplace_back(c,1);
        a[c]-=c-l;
        while(true) {
            const int i(std::get<0>(vec[vec.size()-2]));
            const int j(std::get<0>(vec[vec.size()-1]));
            const int s(query(i)-(j-i+1)),k(query(j)+j-s);
            del.emplace_back(s+2);
            if(s==0&&k==r+1) {
                vec.emplace_back(r+1,0);
                del.emplace_back(1);
                break;
            }
            if(k<=j||k>r) {
                return false;
            }
            if(k==j+1||query(k-1)<=query(j)) {
                vec.emplace_back(k,1);
                a[k]-=k-l;
            }
            else {
                vec.emplace_back(k-1,0);
                a[k-1]-=k-1-j;
            }
        }
        int w(0);
        for(int i=0;i+1!=vec.size();i++) {
            w+=std::get<1>(vec[i]);
        }
        int _w(w=v-w);
        for(int i=0;i+1!=vec.size();i++) {
            b[std::get<0>(vec[i])]=_w+=std::get<1>(vec[i]);
        }
        for(int i=0;i+1!=vec.size();i++) {
            if(!self(self,std::get<0>(vec[i])+1,std::get<0>(vec[i+1])-1,d+del[i],w-1)) {
                return false;
            }
        }
        return true;
    });
    if(!solve(solve,1,n,0,n)) {
        return puts("-1"),0;
    }
    for(int i=1;i<=n;i++) {
        printf("%d%c",b[i],i==n?'\n':' ');
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5864kb

input:

6
3 3 4 2 5 1

output:

4 3 5 3 6 3

result:

ok 

Test #2:

score: 0
Accepted
time: 1ms
memory: 5884kb

input:

4
3 3 3 3

output:

4 3 2 1

result:

ok 

Test #3:

score: 0
Accepted
time: 28ms
memory: 6972kb

input:

264668
5 5 5 5 9 5 5 5 7 3 5 3 11 9 9 9 8 9 8 9 12 4 4 9 5 5 6 4 12 4 7 5 6 5 18 12 6 12 11 11 11 11 11 11 12 19 5 5 8 6 6 6 26 7 7 7 8 6 7 6 6 12 10 6 9 8 8 8 10 4 22 4 4 6 3 6 4 4 8 5 5 5 7 3 8 6 6 6 6 8 3 5 3 6 4 4 8 5 5 5 10 6 6 6 6 17 4 12 5 11 6 10 7 9 8 8 16 5 5 5 8 4 4 12 8 7 7 8 6 9 4 14 5 ...

output:

264666 264665 264664 264663 264667 264665 264664 264663 264667 264665 264667 264665 264667 264665 264664 264663 264660 264661 264659 264662 264667 264665 264664 264667 264664 264663 264665 264663 264667 264664 264665 264662 264663 264661 264667 264665 264662 264663 264661 264660 264659 264658 264657...

result:

ok 

Test #4:

score: 0
Accepted
time: 42ms
memory: 8688kb

input:

409115
2 4 3 7 4 5 4 7 3 6 4 4 7 4 4 6 3 11 6 6 6 9 6 6 6 11 3 10 8 5 8 7 7 7 10 3 5 3 8 6 6 6 6 8 3 8 6 6 6 6 10 5 5 5 8 4 4 8 4 5 4 7 3 5 3 6 4 4 8 5 5 5 9 4 5 4 8 4 4 7 4 4 8 5 5 5 8 4 4 7 4 4 6 3 9 4 7 6 6 6 9 3 6 4 4 28 7 7 7 12 8 8 9 7 12 7 7 12 8 8 9 7 9 24 7 7 7 8 4 34 8 8 8 8 8 10 5 5 13 4 ...

output:

409113 409114 409112 409114 409111 409112 409110 409114 409112 409114 409112 409111 409114 409112 409111 409114 409112 409114 409111 409110 409109 409112 409110 409109 409108 409114 409112 409114 409112 409110 409111 409109 409108 409107 409114 409112 409114 409112 409114 409112 409111 409110 409109...

result:

ok 

Test #5:

score: 0
Accepted
time: 51ms
memory: 8416kb

input:

430320
2 5 4 4 8 5 5 5 18 7 7 7 9 6 7 5 14 5 7 6 6 18 4 5 4 14 6 6 6 10 7 7 7 7 31 4 12 7 7 10 8 8 9 6 13 5 7 5 7 5 7 5 7 5 5 28 5 6 5 7 4 12 6 6 6 6 13 4 8 6 6 7 5 11 4 4 7 4 4 6 3 7 5 5 5 10 4 6 5 5 9 4 4 8 5 5 5 7 3 6 4 4 8 5 5 5 15 7 7 8 6 8 11 6 6 6 18 5 5 8 6 6 6 11 4 4 6 3 27 12 8 8 8 9 8 7 8...

output:

430318 430319 430317 430316 430319 430317 430316 430315 430319 430315 430314 430313 430316 430314 430316 430314 430317 430313 430314 430312 430311 430319 430316 430317 430315 430319 430316 430315 430314 430317 430315 430314 430313 430312 430319 430316 430317 430314 430313 430315 430313 430312 430315...

result:

ok 

Test #6:

score: 0
Accepted
time: 51ms
memory: 7620kb

input:

445524
4 4 6 4 4 32 6 6 6 10 7 7 7 21 7 10 9 9 9 11 10 9 9 9 11 7 7 20 5 6 5 45 8 11 10 10 10 11 13 7 7 14 7 6 6 19 5 6 5 35 6 6 6 11 8 7 8 7 9 9 7 7 7 8 5 19 3 5 3 17 5 7 6 6 15 6 6 11 6 9 8 8 8 64 6 6 7 5 12 8 8 8 8 12 7 7 7 11 6 7 6 10 6 6 10 7 7 7 17 13 13 13 13 11 13 12 12 13 19 6 9 7 8 7 15 9 ...

output:

445521 445520 445522 445520 445519 445523 445519 445518 445517 445520 445518 445517 445516 445520 445516 445517 445515 445514 445513 445518 445518 445515 445514 445513 445518 445515 445514 445520 445517 445518 445516 445523 445515 445516 445514 445513 445512 445517 445518 445514 445513 445519 445519...

result:

ok 

Test #7:

score: 0
Accepted
time: 60ms
memory: 7788kb

input:

481648
4 4 13 8 10 9 9 11 7 11 11 11 74 4 13 8 8 8 12 9 9 9 9 13 48 28 18 11 11 18 13 14 13 14 16 12 12 28 16 14 14 14 16 13 13 16 17 9 30 7 24 16 11 11 16 14 14 14 14 14 18 9 10 11 10 10 10 22 49 5 7 5 5 69 4 8 6 7 6 7 21 8 8 8 9 9 8 8 8 12 14 5 5 17 4 4 19 5 6 5 10 7 7 7 13 9 8 8 8 9 6 131 10 10 1...

output:

481645 481644 481646 481639 481640 481638 481637 481641 481638 481642 481643 481644 481647 481643 481644 481641 481640 481639 481642 481640 481639 481638 481637 481644 481644 481641 481639 481637 481636 481638 481633 481634 481632 481635 481636 481632 481631 481640 481637 481634 481633 481632 481635...

result:

ok 

Test #8:

score: 0
Accepted
time: 53ms
memory: 7528kb

input:

421202
5 5 7 5 5 10 4 5 4 43 5 16 13 10 10 13 11 11 11 13 15 7 7 34 11 9 9 11 9 9 12 6 14 6 13 6 11 7 10 9 9 9 71 8 8 8 8 13 8 8 9 7 12 7 7 13 8 9 8 10 7 16 10 9 10 9 10 10 31 6 6 12 9 9 9 9 9 10 4 68 7 7 7 8 13 6 12 7 11 8 10 9 9 31 6 9 8 8 8 12 7 7 10 7 7 10 7 7 7 36 4 6 5 5 34 5 6 5 29 9 9 9 9 9 ...

output:

421198 421197 421199 421197 421196 421200 421196 421197 421195 421201 421195 421196 421193 421190 421189 421191 421189 421188 421187 421192 421194 421192 421191 421197 421192 421190 421189 421191 421189 421188 421193 421191 421194 421191 421194 421190 421191 421188 421189 421187 421186 421185 421201...

result:

ok 

Test #9:

score: 0
Accepted
time: 59ms
memory: 8032kb

input:

480658
15 8 8 8 10 7 7 15 8 8 9 7 9 16 3 40 5 5 9 7 7 7 15 11 9 11 10 10 11 11 14 6 6 11 7 7 7 8 5 27 3 11 6 7 6 7 9 5 5 13 4 5 4 8 4 4 6 3 10 5 8 7 7 7 8 18 9 7 7 9 7 7 11 5 5 27 7 7 7 7 12 8 8 8 8 13 7 7 7 8 5 43 5 5 8 6 6 24 9 10 9 11 8 12 7 17 8 10 9 9 14 9 9 9 9 22 4 42 5 5 16 11 8 10 9 10 8 12...

output:

480655 480652 480651 480650 480653 480651 480650 480654 480649 480648 480650 480648 480651 480656 480654 480657 480653 480652 480654 480652 480651 480650 480654 480652 480648 480649 480647 480646 480650 480651 480654 480652 480651 480654 480651 480650 480649 480652 480650 480657 480654 480657 480651...

result:

ok 

Test #10:

score: 0
Accepted
time: 51ms
memory: 7520kb

input:

430417
5 5 5 27 7 7 7 11 8 7 8 7 24 8 8 12 8 10 9 9 16 8 9 8 9 16 34 4 5 4 8 5 5 5 430416 5 5 8 5 6 5 17 6 6 6 11 5 8 6 7 6 18 73 6 8 7 7 33 9 9 11 9 9 15 8 10 9 9 29 10 10 13 10 11 10 17 11 11 11 11 19 8 8 72 8 12 11 10 11 10 12 24 10 11 10 16 12 12 12 13 10 17 8 17 42 8 9 8 11 8 8 22 9 9 12 10 10 ...

output:

430414 430413 430412 430415 430411 430410 430409 430412 430410 430408 430409 430407 430413 430407 430406 430408 430405 430406 430404 430403 430409 430404 430405 430403 430406 430410 430416 430411 430412 430410 430413 430410 430409 430408 430417 430410 430409 430411 430408 430409 430407 430412 430408...

result:

ok 

Test #11:

score: 0
Accepted
time: 58ms
memory: 7676kb

input:

480452
5 9 8 8 8 8 9 13 5 6 5 6 22 9 7 9 8 8 9 9 10 3 480451 5 5 8 6 6 6 10 4 4 31 6 7 6 7 22 7 9 8 8 15 10 9 10 9 11 7 18 7 7 7 231 10 10 10 10 11 7 30 9 14 13 11 13 12 12 15 8 24 11 11 11 12 9 15 10 10 10 40 13 10 10 13 11 11 11 13 14 6 41 9 7 7 8 6 113 12 15 14 14 14 15 16 10 37 23 15 15 15 21 15...

output:

480447 480448 480446 480445 480444 480443 480449 480450 480444 480445 480443 480446 480451 480445 480441 480442 480440 480439 480443 480444 480446 480444 480452 480443 480442 480444 480442 480441 480440 480445 480442 480441 480446 480439 480440 480438 480441 480442 480435 480436 480434 480433 480437...

result:

ok 

Test #12:

score: 0
Accepted
time: 53ms
memory: 7540kb

input:

448826
6 6 6 10 7 7 7 7 26 8 8 8 15 8 10 9 9 12 8 8 16 5 18 5 5 28 3 3 52 5 6 5 17 6 8 7 7 14 6 10 8 8 9 7 24 5 5 9 5 7 6 6 448797 3 18 17 6 9 7 8 7 17 7 12 9 10 9 11 8 12 125 12 10 10 11 9 12 8 16 9 9 9 9 18 6 6 68 9 12 11 11 11 13 8 36 11 18 15 15 15 15 17 13 13 19 10 20 9 29 16 13 13 13 13 16 12 ...

output:

448822 448821 448820 448823 448821 448820 448819 448818 448824 448818 448817 448816 448819 448815 448816 448814 448813 448817 448814 448813 448820 448817 448821 448817 448816 448825 448821 448820 448826 448818 448819 448817 448820 448815 448816 448814 448813 448817 448813 448814 448811 448810 448812...

result:

ok 

Test #13:

score: 0
Accepted
time: 46ms
memory: 8544kb

input:

466137
1 466136 5 5 5 5 6 6 4 5 4 10 6 6 6 6 12 7 7 7 7 7 10 4 4 8 5 5 5 9 5 5 5 12 6 6 6 8 5 5 16 5 5 9 7 7 7 7 13 5 5 5 11 7 6 6 7 5 11 5 5 5 10 4 6 5 5 14 9 9 9 9 8 9 8 12 4 4 9 5 5 6 4 18 4 5 6 5 11 9 9 9 9 9 9 16 4 4 12 9 6 6 9 7 7 7 11 3 7 4 5 4 7 3 20 6 6 6 18 6 7 6 9 6 12 8 8 8 10 7 7 22 5 5...

output:

466136 466137 466134 466133 466132 466131 466135 466135 466132 466133 466131 466135 466133 466132 466131 466130 466135 466133 466132 466131 466130 466129 466135 466133 466132 466135 466133 466132 466131 466135 466133 466132 466131 466135 466132 466131 466130 466133 466131 466130 466135 466132 466131...

result:

ok 

Test #14:

score: 0
Accepted
time: 51ms
memory: 7636kb

input:

447669
3 3 29 3 6 5 5 13 10 9 9 9 10 7 10 12 4 6 4 8 5 6 5 11 7 5 7 6 6 447668 3 6 4 5 4 11 6 6 6 6 7 5 4 4 9 4 6 5 5 11 5 5 6 4 21 4 5 9 7 7 8 6 13 7 8 7 8 9 4 46 4 9 6 7 7 6 11 6 6 9 6 6 14 6 11 8 10 9 9 10 18 6 9 8 8 9 6 11 4 40 5 5 6 5 6 5 6 4 21 4 12 7 7 7 11 8 8 8 8 19 4 8 7 7 7 7 19 4 12 5 11...

output:

447667 447666 447668 447665 447666 447664 447663 447666 447664 447661 447660 447659 447662 447660 447663 447666 447664 447666 447664 447666 447663 447664 447662 447666 447664 447662 447663 447661 447660 447669 447664 447665 447662 447663 447661 447666 447663 447662 447661 447660 447666 447666 447663...

result:

ok 

Test #15:

score: 0
Accepted
time: 43ms
memory: 7144kb

input:

408826
1 408825 3 4 3 7 4 4 26 18 12 9 9 12 9 10 9 17 10 10 10 10 11 6 23 6 6 8 6 6 25 3 9 5 6 5 7 4 10 4 4 13 4 9 8 8 8 8 9 4 20 6 6 6 9 6 6 8 5 5 21 5 5 11 9 9 9 9 9 9 26 4 9 8 8 8 8 15 7 7 7 10 7 7 7 28 11 11 8 8 11 8 9 8 13 5 5 19 5 5 7 5 5 10 4 4 22 5 8 7 7 7 12 7 7 7 13 9 9 9 9 9 10 4 21 3 11 ...

output:

408825 408826 408822 408823 408821 408824 408821 408820 408824 408820 408818 408816 408815 408817 408814 408815 408813 408819 408817 408816 408815 408814 408819 408817 408821 408818 408817 408819 408817 408816 408824 408821 408824 408819 408820 408818 408821 408818 408824 408821 408820 408824 408820...

result:

ok 

Test #16:

score: 0
Accepted
time: 57ms
memory: 8088kb

input:

486362
2 8 5 5 5 7 4 4 10 2 3 486351 5 5 5 6 14 9 7 7 9 7 7 13 5 6 6 5 27 11 6 7 6 9 6 8 6 6 15 4 5 4 6 5 4 4 15 5 5 6 6 5 9 6 7 6 7 25 6 6 8 6 6 13 8 8 8 8 9 4 49 27 9 27 10 14 12 13 12 16 12 12 14 11 18 11 12 12 13 12 13 11 27 27 28 8 7 7 7 36 7 7 7 8 5 54 4 19 7 7 7 8 11 10 8 9 9 8 14 6 7 7 6 23 ...

output:

486360 486361 486358 486357 486356 486359 486357 486356 486362 486359 486362 486362 486357 486356 486355 486358 486358 486355 486353 486352 486354 486352 486351 486356 486353 486354 486354 486352 486359 486356 486353 486354 486352 486355 486352 486355 486352 486351 486359 486355 486356 486354 486359...

result:

ok 

Test #17:

score: 0
Accepted
time: 42ms
memory: 8596kb

input:

444506
1 444505 2 3 22 4 10 9 7 8 8 7 15 7 7 9 7 7 14 6 7 7 6 8 23 3 6 4 4 13 10 10 10 10 10 10 10 10 16 7 5 7 6 6 10 4 4 10 7 7 7 7 7 9 3 8 6 6 6 6 10 4 5 4 7 3 7 5 5 5 9 5 5 5 7 3 6 4 4 6 3 5 3 8 6 6 6 6 8 3 5 3 5 3 8 6 6 6 6 8 3 5 3 6 4 4 8 5 5 5 13 9 9 9 9 9 9 9 12 4 4 10 7 5 7 6 6 9 3 6 4 4 9 6...

output:

444505 444506 444503 444504 444504 444501 444502 444500 444498 444499 444499 444497 444502 444499 444498 444500 444498 444497 444502 444498 444499 444499 444497 444500 444504 444502 444504 444502 444501 444504 444502 444501 444500 444499 444498 444497 444496 444495 444504 444502 444500 444501 444499...

result:

ok 

Test #18:

score: 0
Accepted
time: 46ms
memory: 8796kb

input:

416777
1 416776 4 4 4 8 4 5 4 7 3 7 5 5 5 11 7 7 7 7 7 10 4 4 8 5 5 5 9 4 5 4 9 5 5 5 11 6 6 6 7 4 10 4 4 10 7 7 7 7 7 11 5 5 5 8 4 4 8 5 5 5 11 5 5 7 5 5 11 5 5 5 8 4 4 7 4 4 7 4 4 8 5 5 5 8 4 4 7 4 4 8 5 5 5 10 6 6 6 6 13 8 8 8 7 8 7 11 4 4 6 3 6 4 4 7 4 4 9 6 6 6 6 12 7 5 7 6 6 10 4 4 6 3 5 3 6 4...

output:

416776 416777 416774 416773 416772 416775 416772 416773 416771 416775 416773 416775 416773 416772 416771 416775 416773 416772 416771 416770 416769 416775 416773 416772 416775 416773 416772 416771 416775 416772 416773 416771 416775 416773 416772 416771 416775 416772 416771 416770 416773 416771 416775...

result:

ok 

Test #19:

score: 0
Accepted
time: 1ms
memory: 6124kb

input:

15
7 7 7 7 9 5 5 11 4 4 13 3 4 2 14

output:

11 10 9 8 12 10 9 13 10 9 14 10 14 10 15

result:

ok 

Test #20:

score: 0
Accepted
time: 1ms
memory: 5884kb

input:

17
7 7 7 7 9 5 5 11 4 4 13 3 5 3 4 2 16

output:

13 12 11 10 14 12 11 15 12 11 16 12 16 12 16 12 17

result:

ok 

Test #21:

score: 0
Accepted
time: 1ms
memory: 5900kb

input:

15
9 8 8 9 7 10 5 12 5 5 13 3 13 14 1

output:

10 8 7 9 7 11 9 12 9 8 13 9 14 15 9

result:

ok 

Test #22:

score: 0
Accepted
time: 1ms
memory: 5856kb

input:

15
2 6 5 5 5 8 4 4 4 11 2 5 3 3 3

output:

13 14 12 11 10 14 12 11 10 15 12 15 12 11 10

result:

ok 

Test #23:

score: -100
Time Limit Exceeded

input:

500000
499996 499995 499994 499993 499992 499991 499990 499989 499988 499987 499986 499985 499984 499983 499982 499981 499980 499979 499978 499977 499976 499975 499974 499973 499972 499971 499970 499969 499968 499967 499966 499965 499964 499963 499962 499961 499960 499959 499958 499957 499956 499955...

output:


result: