結果

問題 No.1888 Odd Insertion
ユーザー miscalcmiscalc
提出日時 2021-11-07 03:46:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,650 ms / 2,000 ms
コード長 1,387 bytes
コンパイル時間 656 ms
コンパイル使用メモリ 11,008 KB
実行使用メモリ 35,080 KB
最終ジャッジ日時 2023-09-11 15:56:48
合計ジャッジ時間 51,091 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,052 KB
testcase_01 AC 15 ms
8,324 KB
testcase_02 AC 14 ms
8,068 KB
testcase_03 AC 15 ms
8,056 KB
testcase_04 AC 15 ms
8,144 KB
testcase_05 AC 16 ms
8,048 KB
testcase_06 AC 162 ms
30,060 KB
testcase_07 AC 159 ms
30,076 KB
testcase_08 AC 1,649 ms
35,080 KB
testcase_09 AC 1,596 ms
34,940 KB
testcase_10 AC 1,650 ms
34,956 KB
testcase_11 AC 1,593 ms
34,960 KB
testcase_12 AC 1,614 ms
34,968 KB
testcase_13 AC 1,619 ms
34,964 KB
testcase_14 AC 1,606 ms
35,076 KB
testcase_15 AC 1,602 ms
34,532 KB
testcase_16 AC 1,242 ms
34,224 KB
testcase_17 AC 1,609 ms
34,868 KB
testcase_18 AC 1,305 ms
34,444 KB
testcase_19 AC 1,208 ms
34,220 KB
testcase_20 AC 1,311 ms
34,624 KB
testcase_21 AC 1,283 ms
34,400 KB
testcase_22 AC 1,257 ms
34,180 KB
testcase_23 AC 1,404 ms
34,700 KB
testcase_24 AC 1,355 ms
34,752 KB
testcase_25 AC 1,402 ms
34,688 KB
testcase_26 AC 1,408 ms
35,068 KB
testcase_27 AC 1,343 ms
30,108 KB
testcase_28 AC 1,247 ms
30,144 KB
testcase_29 AC 1,123 ms
34,988 KB
testcase_30 AC 1,167 ms
31,732 KB
testcase_31 AC 1,130 ms
30,096 KB
testcase_32 AC 1,468 ms
31,840 KB
testcase_33 AC 1,278 ms
34,880 KB
testcase_34 AC 1,276 ms
34,960 KB
testcase_35 AC 1,334 ms
31,972 KB
testcase_36 AC 1,324 ms
32,000 KB
testcase_37 AC 1,266 ms
35,000 KB
testcase_38 AC 1,326 ms
32,052 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