結果

問題 No.2029 Swap Min Max Min
ユーザー 👑 tamatotamato
提出日時 2022-08-05 21:39:48
言語 PyPy3
(7.3.15)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,807 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 86,908 KB
実行使用メモリ 110,248 KB
最終ジャッジ日時 2023-10-14 00:05:43
合計ジャッジ時間 9,427 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,404 KB
testcase_01 AC 75 ms
71,080 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 123 ms
90,216 KB
testcase_06 AC 159 ms
107,432 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 107 ms
82,872 KB
testcase_11 WA -
testcase_12 AC 133 ms
94,992 KB
testcase_13 WA -
testcase_14 AC 188 ms
105,800 KB
testcase_15 WA -
testcase_16 AC 188 ms
105,536 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 188 ms
105,592 KB
testcase_20 AC 189 ms
105,912 KB
testcase_21 AC 186 ms
105,548 KB
testcase_22 AC 190 ms
105,540 KB
testcase_23 AC 250 ms
105,900 KB
testcase_24 AC 247 ms
105,688 KB
testcase_25 AC 185 ms
105,692 KB
testcase_26 AC 188 ms
105,880 KB
testcase_27 AC 74 ms
71,068 KB
testcase_28 AC 82 ms
75,712 KB
testcase_29 AC 75 ms
71,304 KB
testcase_30 AC 79 ms
75,588 KB
testcase_31 AC 82 ms
75,692 KB
testcase_32 WA -
testcase_33 AC 73 ms
71,448 KB
testcase_34 AC 74 ms
71,444 KB
testcase_35 AC 74 ms
71,044 KB
testcase_36 AC 73 ms
71,448 KB
testcase_37 AC 74 ms
71,108 KB
testcase_38 AC 233 ms
110,248 KB
testcase_39 AC 182 ms
105,712 KB
testcase_40 AC 172 ms
110,152 KB
testcase_41 AC 239 ms
105,884 KB
testcase_42 AC 237 ms
102,452 KB
testcase_43 AC 185 ms
105,696 KB
testcase_44 AC 253 ms
105,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353


def main():
    import sys
    input = sys.stdin.readline

    class Bit:
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x):
            while i <= self.size:
                self.tree[i] += x
                i += i & -i

        def lower_bound(self, w):
            if w <= 0:
                return 0
            x = 0
            k = 1 << (self.size.bit_length() - 1)
            while k:
                if x + k <= self.size and self.tree[x + k] < w:
                    w -= self.tree[x + k]
                    x += k
                k >>= 1
            return x + 1

    N = int(input())
    A = list(map(int, input().split()))

    X = N // 2

    C = []
    cnt0 = cnt1 = 0
    for a in A:
        if a <= X:
            C.append(2 + cnt1 * 2)
            cnt1 += 1
        else:
            C.append(1 + cnt0 * 2)
            cnt0 += 1

    bit = Bit(N)
    idx = [0] * (N + 1)
    for i, c in enumerate(C):
        idx[c] = i + 1

    Y = 0
    for x in range(N, 0, -1):
        i = idx[x]
        Y += bit.sum(i)
        bit.add(i, 1)

    if N & 1:
        print(X, Y)
        exit()

    C = []
    cnt0 = cnt1 = 0
    for a in A:
        if a > X:
            C.append(2 + cnt1 * 2)
            cnt1 += 1
        else:
            C.append(1 + cnt0 * 2)
            cnt0 += 1

    bit = Bit(N)
    idx = [0] * (N + 1)
    for i, c in enumerate(C):
        idx[c] = i + 1

    Y2 = 0
    for x in range(N, 0, -1):
        i = idx[x]
        Y2 += bit.sum(i)
        bit.add(i, 1)

    print(X, min(Y, Y2))


if __name__ == '__main__':
    main()
0