Submission #6328413
Source Code Expand
import sys
input = sys.stdin.readline
from collections import Counter
"""
・左から見て最大値
・自分より右に、自分より以上の数がいくつあるか
・自分の下の数が何か
"""
N = int(input())
A = [int(x) for x in input().split()]
nums = sorted(set(A), reverse = True)
nums.append(0)
answer = [0] * N
counter = Counter(A)
position = dict() # その数字がある左端のインデックス
for i,a in enumerate(A):
if not (a in position):
position[a] = i
# 大きい数字から処理していく
for n, next_n in zip(nums[:-1], nums[1:]):
i = position[n]
c = counter[n]
# 山がc個ある。i番を記録しながらnext_nに合流
counter[n] -= c
counter[next_n] += c
if next_n != 0:
position[next_n] = min(position[next_n], i)
answer[i] += c * (n - next_n)
print('\n'.join(map(str,answer)))
Submission Info
| Submission Time | |
|---|---|
| Task | E - Frequency |
| User | maspy |
| Language | Python (3.4.3) |
| Score | 700 |
| Code Size | 911 Byte |
| Status | AC |
| Exec Time | 352 ms |
| Memory | 39548 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 700 / 700 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_example_01.txt, 00_example_02.txt |
| All | 00_example_01.txt, 00_example_02.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_example_01.txt | AC | 21 ms | 3316 KiB |
| 00_example_02.txt | AC | 21 ms | 3316 KiB |
| 01.txt | AC | 21 ms | 3316 KiB |
| 02.txt | AC | 35 ms | 4592 KiB |
| 03.txt | AC | 21 ms | 3316 KiB |
| 04.txt | AC | 22 ms | 3444 KiB |
| 05.txt | AC | 21 ms | 3316 KiB |
| 06.txt | AC | 21 ms | 3316 KiB |
| 07.txt | AC | 21 ms | 3316 KiB |
| 08.txt | AC | 21 ms | 3316 KiB |
| 09.txt | AC | 41 ms | 5356 KiB |
| 10.txt | AC | 21 ms | 3316 KiB |
| 11.txt | AC | 249 ms | 22580 KiB |
| 12.txt | AC | 255 ms | 22588 KiB |
| 13.txt | AC | 249 ms | 22580 KiB |
| 14.txt | AC | 251 ms | 22660 KiB |
| 15.txt | AC | 254 ms | 22704 KiB |
| 16.txt | AC | 89 ms | 14572 KiB |
| 17.txt | AC | 279 ms | 39200 KiB |
| 18.txt | AC | 276 ms | 32804 KiB |
| 19.txt | AC | 74 ms | 11348 KiB |
| 20.txt | AC | 180 ms | 17184 KiB |
| 21.txt | AC | 21 ms | 3316 KiB |
| 22.txt | AC | 21 ms | 3316 KiB |
| 23.txt | AC | 21 ms | 3316 KiB |
| 24.txt | AC | 39 ms | 5484 KiB |
| 25.txt | AC | 21 ms | 3316 KiB |
| 26.txt | AC | 22 ms | 3444 KiB |
| 27.txt | AC | 21 ms | 3316 KiB |
| 28.txt | AC | 345 ms | 38792 KiB |
| 29.txt | AC | 341 ms | 39036 KiB |
| 30.txt | AC | 348 ms | 39548 KiB |
| 31.txt | AC | 352 ms | 38660 KiB |
| 32.txt | AC | 342 ms | 38792 KiB |
| 33.txt | AC | 342 ms | 32796 KiB |
| 34.txt | AC | 342 ms | 32796 KiB |
| 35.txt | AC | 342 ms | 32796 KiB |
| 36.txt | AC | 345 ms | 32796 KiB |
| 37.txt | AC | 339 ms | 32796 KiB |