Submission #63549603


Source Code Expand

N, M = map(int, input().split())
A = list(map(int, input().split()))
s = M + 1
bit = [0] * s


def update(i, v):
    while i < s:
        bit[i] += v
        i += i & -i


def query(i):
    res = 0
    while i:
        res += bit[i]
        i -= i & -i
    return res


inv = 0
for i, a in enumerate(A):
    q = query(a + 1)
    inv += i - q
    update(a + 1, 1)

res = [0] * M
res[0] = inv
d = [0] * (M + 1)
for i, a in enumerate(A):
    if a:
        k = M - a
        d[k] += i - (N - i - 1)

cur = inv
for k in range(1, M):
    cur += d[k]
    res[k] = cur

for x in res:
    print(x)

Submission Info

Submission Time
Task F - Rotated Inversions
User mu16
Language Python (PyPy 3.10-v7.3.12)
Score 500
Code Size 630 Byte
Status AC
Exec Time 151 ms
Memory 115128 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 31
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 58 ms 76256 KiB
00_sample_01.txt AC 58 ms 76560 KiB
00_sample_02.txt AC 59 ms 76504 KiB
01_handmade_00.txt AC 58 ms 76648 KiB
01_handmade_01.txt AC 75 ms 87480 KiB
01_handmade_02.txt AC 131 ms 114492 KiB
01_handmade_03.txt AC 133 ms 114472 KiB
01_handmade_04.txt AC 144 ms 114896 KiB
01_handmade_05.txt AC 147 ms 115068 KiB
01_handmade_06.txt AC 145 ms 114744 KiB
02_random_00.txt AC 124 ms 102228 KiB
02_random_01.txt AC 105 ms 91476 KiB
02_random_02.txt AC 89 ms 87900 KiB
02_random_03.txt AC 88 ms 87736 KiB
02_random_04.txt AC 91 ms 87936 KiB
02_random_05.txt AC 147 ms 114784 KiB
02_random_06.txt AC 151 ms 114788 KiB
02_random_07.txt AC 145 ms 114508 KiB
02_random_08.txt AC 144 ms 114820 KiB
02_random_09.txt AC 145 ms 114748 KiB
02_random_10.txt AC 132 ms 114892 KiB
02_random_11.txt AC 134 ms 114620 KiB
02_random_12.txt AC 136 ms 114528 KiB
02_random_13.txt AC 137 ms 114360 KiB
02_random_14.txt AC 141 ms 114820 KiB
02_random_15.txt AC 141 ms 114932 KiB
02_random_16.txt AC 138 ms 115072 KiB
02_random_17.txt AC 133 ms 114468 KiB
02_random_18.txt AC 139 ms 114972 KiB
02_random_19.txt AC 140 ms 115112 KiB
02_random_20.txt AC 133 ms 115128 KiB