Submission #6319302


Source Code Expand

import sys
input = sys.stdin.readline
from itertools import accumulate

N,K = map(int,input().split())
A = [int(input()) - K for _ in range(N)]
Acum = [0] + list(accumulate(A))

a_to_i = {a:i for i,a in enumerate(sorted(set(Acum)), 1)}

B = [a_to_i[a] for a in Acum]

L = len(a_to_i) + 1
tree = [0] * (L+1)

# 過去に自分以下の値が何回出てきているのか
def BIT_update(tree, x):
    while x <= L:
        tree[x] += 1
        x += x & (-x)

def BIT_sum(tree, x):
    s = 0
    while x:
        s += tree[x]
        x -= x & (-x)
    return s

answer = 0
for b in B:
    answer += BIT_sum(tree,b)
    BIT_update(tree,b)

print(answer)

Submission Info

Submission Time
Task E - Meaningful Mean
User maspy
Language Python (3.4.3)
Score 600
Code Size 687 Byte
Status AC
Exec Time 1096 ms
Memory 54288 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 23
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23
Case Name Status Exec Time Memory
a01 AC 17 ms 3064 KiB
a02 AC 17 ms 3064 KiB
a03 AC 17 ms 3064 KiB
b04 AC 17 ms 3064 KiB
b05 AC 303 ms 7864 KiB
b06 AC 877 ms 45072 KiB
b07 AC 919 ms 35984 KiB
b08 AC 926 ms 35988 KiB
b09 AC 1008 ms 51340 KiB
b10 AC 1025 ms 52360 KiB
b11 AC 17 ms 3064 KiB
b12 AC 20 ms 3188 KiB
b13 AC 358 ms 18048 KiB
b14 AC 1096 ms 52240 KiB
b15 AC 837 ms 28812 KiB
b16 AC 1033 ms 52624 KiB
b17 AC 1073 ms 52240 KiB
b18 AC 1088 ms 54288 KiB
b19 AC 1018 ms 52880 KiB
b20 AC 624 ms 21304 KiB
b21 AC 545 ms 15160 KiB
b22 AC 1052 ms 52236 KiB
b23 AC 1051 ms 52240 KiB