UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#210275#3776. 可爱小树Allen123456hello100148ms3540kbC++11649b2024-08-06 10:09:082024-08-06 12:20:37

answer

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
typedef long long LL;
int n,fa[200005],cnt0=0;
struct nd{
    int u,sub;
    bool operator<(const nd& a) const{
        return sub==a.sub?u<a.u:sub>a.sub;
    }
}arr[200005];
int main(){
    scanf("%d",&n);
    for (int i=1;i<=n;++i){scanf("%d",&arr[i].sub);arr[i].u=i;}
    sort(arr+1,arr+1+n);
    int pre=1,prepre=0;
    for (int i=2;i<=n;++i){
        if (arr[i].sub<arr[pre].sub){prepre=pre;pre=i;}
        fa[arr[i].u]=arr[prepre+(i-pre)<pre?prepre+(i-pre):prepre].u;
    }
    for (int i=1;i<=n;++i){printf("%d%c",fa[i]," \n"[i==n]);}
    return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1212kb

input:

11
0 1 2 3 4 5 6 7 8 9 10

output:

2 3 4 5 6 7 8 9 10 11 0

result:

ok Congrats, all the answers are valid.

Test #2:

score: 10
Accepted
time: 0ms
memory: 1212kb

input:

49
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35...

output:

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ...

result:

ok Congrats, all the answers are valid.

Test #3:

score: 10
Accepted
time: 0ms
memory: 1216kb

input:

999
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 3...

output:

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ...

result:

ok Congrats, all the answers are valid.

Test #4:

score: 10
Accepted
time: 0ms
memory: 1212kb

input:

94
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0...

output:

40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 4...

result:

ok Congrats, all the answers are valid.

Test #5:

score: 10
Accepted
time: 34ms
memory: 3540kb

input:

199992
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 126 ...

result:

ok Congrats, all the answers are valid.

Test #6:

score: 10
Accepted
time: 0ms
memory: 1268kb

input:

4995
3598 702 2058 315 810 3553 2897 812 3108 395 847 1936 1347 3112 431 3546 1213 542 1674 253 1115...

output:

2636 2979 802 1295 4478 2412 919 963 3271 2780 1637 1193 1481 4128 1613 2471 3761 1202 3933 535 1616...

result:

ok Congrats, all the answers are valid.

Test #7:

score: 10
Accepted
time: 49ms
memory: 3540kb

input:

199995
73857 87223 9127 55593 79096 29256 65222 68517 94617 24795 59461 64589 29004 18418 90863 2720...

output:

24936 13049 88363 9987 51277 5342 29951 37725 55511 29670 47849 56891 60208 27338 80490 93332 116528...

result:

ok Congrats, all the answers are valid.

Test #8:

score: 10
Accepted
time: 32ms
memory: 2384kb

input:

99993
53106 38032 8196 3041 65305 15449 52233 7617 6543 21376 61968 23032 33290 58751 14610 5174 727...

output:

76798 83725 23970 4848 32587 37199 50181 16983 68568 42034 2598 73161 65147 31146 34998 11045 8245 6...

result:

ok Congrats, all the answers are valid.

Test #9:

score: 10
Accepted
time: 24ms
memory: 2384kb

input:

99998
37562 29469 5433 30712 31359 56582 18039 29636 52142 9885 6407 11263 47450 45300 34612 31399 1...

output:

15103 15163 51976 58792 30297 87736 4766 27027 12900 56078 26179 14718 66778 50524 71153 17330 29565...

result:

ok Congrats, all the answers are valid.

Test #10:

score: 10
Accepted
time: 9ms
memory: 1792kb

input:

49994
43071 40142 37165 42661 2289 25114 35938 2629 12203 3996 18305 7586 22898 12631 36647 17835 39...

output:

4679 37096 20436 16172 502 34949 22293 22585 2704 2755 45020 28352 46357 23659 43770 49003 13544 385...

result:

ok Congrats, all the answers are valid.

Extra Test:

score: 0
Extra Test Passed