結果

問題 No.2029 Swap Min Max Min
ユーザー tamatotamato
提出日時 2022-08-05 23:10:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,017 bytes
コンパイル時間 576 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 111,888 KB
最終ジャッジ日時 2023-10-14 00:58:22
合計ジャッジ時間 9,510 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,032 KB
testcase_01 AC 76 ms
71,112 KB
testcase_02 AC 73 ms
70,832 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 123 ms
89,972 KB
testcase_06 AC 163 ms
107,356 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 105 ms
82,620 KB
testcase_11 WA -
testcase_12 AC 134 ms
94,652 KB
testcase_13 WA -
testcase_14 AC 188 ms
105,512 KB
testcase_15 WA -
testcase_16 AC 185 ms
105,400 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 185 ms
105,532 KB
testcase_20 AC 189 ms
105,256 KB
testcase_21 AC 188 ms
105,612 KB
testcase_22 AC 186 ms
105,216 KB
testcase_23 AC 203 ms
111,264 KB
testcase_24 AC 207 ms
111,140 KB
testcase_25 AC 182 ms
105,580 KB
testcase_26 AC 186 ms
105,708 KB
testcase_27 AC 72 ms
70,800 KB
testcase_28 AC 79 ms
75,308 KB
testcase_29 AC 74 ms
71,076 KB
testcase_30 AC 75 ms
75,008 KB
testcase_31 AC 80 ms
75,688 KB
testcase_32 WA -
testcase_33 AC 71 ms
70,648 KB
testcase_34 AC 71 ms
71,112 KB
testcase_35 AC 73 ms
71,016 KB
testcase_36 AC 72 ms
71,084 KB
testcase_37 AC 72 ms
70,952 KB
testcase_38 AC 195 ms
109,956 KB
testcase_39 AC 182 ms
105,448 KB
testcase_40 AC 172 ms
109,864 KB
testcase_41 AC 202 ms
106,940 KB
testcase_42 AC 200 ms
106,976 KB
testcase_43 AC 183 ms
105,348 KB
testcase_44 AC 212 ms
111,156 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 = []
    D = []
    cnt0 = cnt1 = 0
    for a in A:
        if a > X:
            C.append(2 + cnt1 * 2)
            cnt1 += 1
            D.append(0)
        else:
            C.append(1 + cnt0 * 2)
            cnt0 += 1
            D.append(1)

    Y2 = 0
    cnt = 0
    flg = 0
    for i, d in enumerate(D):
        if d:
            if flg == 0:
                if cnt * 2 + 1 <= i:
                    Y2 += i - (cnt * 2 + 1)
                else:
                    flg = 1
                    Y2 += (cnt * 2) - i
            else:
                Y2 += abs(cnt * 2 - i)
            cnt += 1

    print(X, min(Y, Y2))


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