結果
問題 | No.696 square1001 and Permutation 5 |
ユーザー |
![]() |
提出日時 | 2020-05-07 14:34:54 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,722 bytes |
コンパイル時間 | 90 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 26,900 KB |
最終ジャッジ日時 | 2024-07-03 09:25:24 |
合計ジャッジ時間 | 5,587 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 5 RE * 7 |
ソースコード
import sysread = sys.stdin.buffer.readreadline = sys.stdin.buffer.readlinereadlines = sys.stdin.buffer.readlinesN = int(readline())P = tuple(map(int, read().split()))class BinaryIndexedTree():def __init__(self, seq):self.size = len(seq)self.depth = self.size.bit_length()self.build(seq)def build(self, seq):data = seqsize = self.sizefor i, x in enumerate(data):j = i + (i & (-i))if j < size:data[j] += data[i]self.data = datadef __repr__(self):return self.data.__repr__()def get_sum(self, i):data = self.datas = 0while i:s += data[i]i -= i & -ireturn sdef add(self, i, x):data = self.datasize = self.sizewhile i < size:data[i] += xi += i & -idef find_kth_element(self, k):data = self.datasize = self.sizex, sx = 0, 0dx = 1 << (self.depth)for i in range(self.depth - 1, -1, -1):dx = (1 << i)if x + dx >= size:continuey = x + dxsy = sx + data[y]if sy < k:x, sx = y, syreturn x + 1bit = BinaryIndexedTree([0] * (N+1))inv = [0] * Nfor i, x in enumerate(P):inv[i] = x - 1 - bit.get_sum(x)bit.add(x, 1)P, invnums = inv[::-1]coefs = list(range(1, N+1))while True:n = len(nums)if n == 1:breakfor i in range(1, n, 2):nums[i - 1] += coefs[i - 1] * nums[i]coefs[i - 1] *= coefs[i]nums = nums[::2]coefs = coefs[::2]print(nums[0] + 1)