結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
コンテスト
ユーザー itsy68
提出日時 2022-08-24 21:54:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 84 ms / 2,500 ms
コード長 818 bytes
コンパイル時間 846 ms
コンパイル使用メモリ 82,448 KB
実行使用メモリ 78,148 KB
最終ジャッジ日時 2024-10-12 05:50:14
合計ジャッジ時間 2,069 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
from itertools import combinations, permutations, product, accumulate, groupby
from collections import defaultdict, deque, Counter
from functools import reduce
import heapq
import bisect
import math
import copy

sys.setrecursionlimit(10 ** 9)
input = lambda: sys.stdin.readline().rstrip()
INF = float("inf")
MOD = 10 ** 9 + 7
# DFS
# import pypyjit
# pypyjit.set_param('max_unroll_recursion=-1')

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
# BIT
data = [0]*(N+1)
def add(k, x):
    while k <= N:
      data[k] += x
      k += k & -k
def get(k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s

ans = 0
for i, a in enumerate(A):
    # 自分より小さい要素がいくつ存在するかを計算
    ans += (N-1-i) - get(a)
    add(a, 1)
print(ans)
0