結果
問題 | No.696 square1001 and Permutation 5 |
ユーザー |
![]() |
提出日時 | 2018-06-08 23:06:15 |
言語 | PyPy2 (7.3.15) |
結果 |
AC
|
実行時間 | 768 ms / 10,000 ms |
コード長 | 798 bytes |
コンパイル時間 | 2,126 ms |
コンパイル使用メモリ | 76,800 KB |
実行使用メモリ | 106,600 KB |
最終ジャッジ日時 | 2024-06-30 10:59:09 |
合計ジャッジ時間 | 6,694 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 12 |
ソースコード
def permutation_rank(n, seq): def add(idx, v): while idx <= n: fenwick[idx] += v idx += idx & -idx return def read(idx): ret = 0 while idx > 0: ret += fenwick[idx] idx -= idx & -idx return ret def rec(b, e): if e - b == 1: return vals[b], b + 1 m = (b + e) // 2 ls, lp = rec(b, m) rs, rp = rec(m, e) return rs * lp + ls, lp * rp fenwick = [0] * (n + 1) for i in range(2, n + 1): add(i, 1) vals = [] ret = 0 for i, c in enumerate(seq): vals += [read(c + 1)] add(c + 1, -1) vals = vals[::-1] ans = rec(0, n)[0] return ans + 1 def solve(): import sys input = sys.stdin.readline N = int(input()) A = [a - 1 for a in map(int, input().split())] print(permutation_rank(N, A)) solve()