98362024-03-11 13:44:1642KörJáték (50 pont)python3Accepted 50/5096ms21400 KiB
# 1 2 3
# 4 2 3 -> 2
# 1 4 3 -> 4
# 1 2 4 -> 2
def solv():
    N=int(input())
    P=[int(xx)-1 for xx in input().split()]
    pos=[-1]*N
    for i in range(N):
        pos[P[i]]=i
    summa=0
    for i in range(N-1):
        cur=pos[i+1]-pos[i]
        if cur>0:
            summa+=cur
        else:
            summa+=N+cur
    for i in range(N):
        if P[i]==0:
            d=pos[1]-pos[0]
            if d<0:
                d+=N
            dd=i-pos[N-1]
            if dd<0:
                dd+=N
            print(summa-d+dd,end=' ')
        elif P[i]==N-1:
            print(summa,end=' ')
        else:
            dl=i-pos[N-1]
            if dl<0:
                dl+=N
            de=i-pos[P[i]-1]
            if de<0:
                de+=N
            du=pos[P[i]+1]-i
            if du<0:
                du+=N
            da=pos[P[i]+1]-pos[P[i]-1]
            if da<0:
                da+=N
            print(summa-de-du+dl+da,end=' ')

            
    print("\r\n")
    #print(P,pos)

solv()
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/017ms11384 KiB
2Accepted0/017ms11704 KiB
3Accepted0/017ms12064 KiB
4Accepted2/218ms11892 KiB
5Accepted2/217ms12412 KiB
6Accepted2/217ms12416 KiB
7Accepted2/217ms12632 KiB
8Accepted2/217ms12860 KiB
9Accepted2/218ms13044 KiB
10Accepted2/217ms13432 KiB
11Accepted2/218ms13680 KiB
12Accepted2/218ms13696 KiB
13Accepted2/218ms14220 KiB
14Accepted2/217ms14408 KiB
15Accepted2/218ms13984 KiB
16Accepted1/117ms14276 KiB
17Accepted2/293ms21120 KiB
18Accepted2/296ms21064 KiB
19Accepted2/289ms21092 KiB
20Accepted2/292ms21096 KiB
21Accepted2/286ms21220 KiB
22Accepted2/290ms21400 KiB
23Accepted2/290ms21140 KiB
24Accepted2/292ms21096 KiB
25Accepted2/293ms20964 KiB
26Accepted2/292ms21064 KiB
27Accepted2/293ms20968 KiB
28Accepted2/292ms21212 KiB
29Accepted1/190ms21272 KiB