結果

問題 No.1525 Meximum Sum
ユーザー chineristAC
提出日時 2021-05-30 10:21:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 565 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 82,044 KB
実行使用メモリ 107,136 KB
最終ジャッジ日時 2024-11-08 20:46:23
合計ジャッジ時間 3,640 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

mod = 998888353

N = int(input())
A = li()

pos = [-1 for i in range(N)]
for i in range(N):
    pos[A[i]] = i

L,R = pos[0],pos[0]
res = N
for i in range(1,N):
    pre = (L+1)*(N-R)
    L = min(L,pos[i])
    R = max(R,pos[i])
    new = (L+1)*(N-R)
    res += i * (pre-new)

print(res)
0