結果

問題 No.2029 Swap Min Max Min
ユーザー tamatotamato
提出日時 2022-08-05 21:39:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,824 bytes
コンパイル時間 967 ms
コンパイル使用メモリ 86,644 KB
実行使用メモリ 110,292 KB
最終ジャッジ日時 2023-10-14 00:05:33
合計ジャッジ時間 9,302 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,124 KB
testcase_01 AC 71 ms
71,332 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 120 ms
90,256 KB
testcase_06 AC 158 ms
107,716 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 104 ms
83,120 KB
testcase_11 WA -
testcase_12 AC 130 ms
94,788 KB
testcase_13 WA -
testcase_14 AC 182 ms
105,852 KB
testcase_15 WA -
testcase_16 AC 183 ms
105,788 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 185 ms
105,776 KB
testcase_20 AC 188 ms
106,068 KB
testcase_21 AC 184 ms
106,100 KB
testcase_22 AC 183 ms
105,740 KB
testcase_23 WA -
testcase_24 AC 244 ms
105,688 KB
testcase_25 AC 185 ms
105,880 KB
testcase_26 AC 192 ms
105,672 KB
testcase_27 WA -
testcase_28 AC 81 ms
75,652 KB
testcase_29 AC 74 ms
71,336 KB
testcase_30 AC 76 ms
75,696 KB
testcase_31 AC 80 ms
75,948 KB
testcase_32 WA -
testcase_33 AC 72 ms
71,332 KB
testcase_34 WA -
testcase_35 AC 71 ms
71,284 KB
testcase_36 AC 70 ms
71,296 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 182 ms
105,820 KB
testcase_40 AC 174 ms
110,252 KB
testcase_41 AC 235 ms
105,848 KB
testcase_42 AC 238 ms
102,444 KB
testcase_43 AC 179 ms
105,832 KB
testcase_44 AC 245 ms
105,832 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