結果

問題 No.1888 Odd Insertion
ユーザー miscalcmiscalc
提出日時 2021-11-07 03:46:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 380 ms / 2,000 ms
コード長 1,387 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 86,840 KB
実行使用メモリ 113,004 KB
最終ジャッジ日時 2023-09-11 15:54:26
合計ジャッジ時間 19,285 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,008 KB
testcase_01 AC 74 ms
70,784 KB
testcase_02 AC 76 ms
70,880 KB
testcase_03 AC 76 ms
70,796 KB
testcase_04 AC 75 ms
70,908 KB
testcase_05 AC 76 ms
70,948 KB
testcase_06 AC 132 ms
112,568 KB
testcase_07 AC 125 ms
112,840 KB
testcase_08 AC 380 ms
112,660 KB
testcase_09 AC 363 ms
112,732 KB
testcase_10 AC 371 ms
112,984 KB
testcase_11 AC 372 ms
112,904 KB
testcase_12 AC 369 ms
112,816 KB
testcase_13 AC 368 ms
112,752 KB
testcase_14 AC 366 ms
112,744 KB
testcase_15 AC 359 ms
112,752 KB
testcase_16 AC 278 ms
112,796 KB
testcase_17 AC 362 ms
112,844 KB
testcase_18 AC 287 ms
112,948 KB
testcase_19 AC 270 ms
112,788 KB
testcase_20 AC 283 ms
112,804 KB
testcase_21 AC 283 ms
112,920 KB
testcase_22 AC 280 ms
112,760 KB
testcase_23 AC 294 ms
112,840 KB
testcase_24 AC 292 ms
113,004 KB
testcase_25 AC 292 ms
112,796 KB
testcase_26 AC 315 ms
112,756 KB
testcase_27 AC 310 ms
112,800 KB
testcase_28 AC 274 ms
112,804 KB
testcase_29 AC 241 ms
112,696 KB
testcase_30 AC 242 ms
112,748 KB
testcase_31 AC 229 ms
112,756 KB
testcase_32 AC 311 ms
112,844 KB
testcase_33 AC 279 ms
112,772 KB
testcase_34 AC 279 ms
112,904 KB
testcase_35 AC 302 ms
112,816 KB
testcase_36 AC 302 ms
112,956 KB
testcase_37 AC 281 ms
112,692 KB
testcase_38 AC 305 ms
112,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# ACL-for-python by shakayami
# https://github.com/shakayami/ACL-for-python

class fenwick_tree():
    n = 1
    data = [0 for i in range(n)]

    def __init__(self, N):
        self.n = N
        self.data = [0 for i in range(N)]

    def add(self, p, x):
        assert 0 <= p < self.n, "0<=p<n,p={0},n={1}".format(p, self.n)
        p += 1
        while(p <= self.n):
            self.data[p-1] += x
            p += p & -p

    def sum(self, l, r):
        assert (0 <= l and l <= r and r <=
                self.n), "0<=l<=r<=n,l={0},r={1},n={2}".format(l, r, self.n)
        return self.sum0(r)-self.sum0(l)

    def sum0(self, r):
        s = 0
        while(r > 0):
            s += self.data[r-1]
            r -= r & -r
        return s

import sys

n = int(input())
p = list(map(int, input().split()))
for i in range(n):
  p[i] -= 1
q = [0] * n
for i in range(n):
  q[p[i]] = i

fw = fenwick_tree(n)
x, y = [0] * n, [0] * n
for i in range(n - 1):
  y1 = fw.sum(0, q[i])
  y2 = fw.sum(0, q[i + 1])
  if y1 % 2 != 0 and y2 % 2 != 0:
    print("No")
    sys.exit(0)
  if y2 % 2 == 0:
    if y1 % 2 != 0 or q[i] < q[i + 1]:
      q[i], q[i + 1] = q[i + 1], q[i]
      y1, y2 = y2, y1
  x[i] = p[q[i]]
  y[i] = y1
  fw.add(q[i], 1)
x[-1] = p[q[-1]]
y[-1] = fw.sum(0, q[-1])
if y[-1] % 2 != 0:
  print("No")
  sys.exit(0)

print("Yes")
for i in range(n):
  print(x[i] + 1, y[i] + 1)
0