Submission #5716256


Source Code Expand

from heapq import*

class median_tree(object):
    def __init__(self):
        self.lower_than_med=[]
        self.higher_than_med=[]
        self.count=0
        self.low=0
        self.high=0
        self.median=0
    def push(self,x):
        self.count=1-self.count
        if self.count:
            y=heappushpop(self.higher_than_med,x)
            heappush(self.lower_than_med,-y)
            self.low +=-y
            self.high+=x-y
        else:
            y=heappushpop(self.lower_than_med,-x)
            heappush(self.higher_than_med,-y)
            self.low -=x+y
            self.high-=y
        self.median=-self.lower_than_med[0]

from heapq import*
n=int(input())
m=median_tree()

B=0
for i in range(n):
    I=input()
    if I[0]=="1":
        a,b,c=map(int,I.split())
        B+=c
        m.push(b)
    else:
        print(m.median,m.count%2*m.median+B+m.low+m.high)

Submission Info

Submission Time
Task F - Absolute Minima
User KyleKatarn
Language Python (3.4.3)
Score 600
Code Size 923 Byte
Status AC
Exec Time 1418 ms
Memory 11148 KiB

Judge Result

Set Name All Sample
Score / Max Score 600 / 600 0 / 0
Status
AC × 22
AC × 2
Set Name Test Cases
All bilateral_minima, many_dup_01, many_dup_02, max_val, min_val, random_max_01, random_max_02, random_max_03, random_max_04, random_max_05, random_max_06, random_max_07, random_small_01, random_small_02, random_small_03, random_small_04, random_small_05, random_small_06, random_small_07, random_small_08, sample_01, sample_02
Sample sample_01, sample_02
Case Name Status Exec Time Memory
bilateral_minima AC 1334 ms 9728 KiB
many_dup_01 AC 846 ms 7028 KiB
many_dup_02 AC 1017 ms 7780 KiB
max_val AC 979 ms 11148 KiB
min_val AC 1007 ms 11072 KiB
random_max_01 AC 1205 ms 8540 KiB
random_max_02 AC 1235 ms 8868 KiB
random_max_03 AC 1302 ms 8996 KiB
random_max_04 AC 1036 ms 7788 KiB
random_max_05 AC 838 ms 6840 KiB
random_max_06 AC 1418 ms 9440 KiB
random_max_07 AC 1348 ms 9352 KiB
random_small_01 AC 24 ms 3064 KiB
random_small_02 AC 22 ms 3064 KiB
random_small_03 AC 23 ms 3064 KiB
random_small_04 AC 23 ms 3064 KiB
random_small_05 AC 24 ms 3064 KiB
random_small_06 AC 24 ms 3064 KiB
random_small_07 AC 24 ms 3064 KiB
random_small_08 AC 24 ms 3064 KiB
sample_01 AC 18 ms 3064 KiB
sample_02 AC 18 ms 3064 KiB