結果

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

ソースコード

diff #

#!/usr/bin/env python3
 
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
b = [-1] * (n)
for i in range(n):
    b[a[i]] = i
ans = 0
l = b[0]
r = b[0]
for i in range(n-1):
    if l <= b[i+1] <= r:
        continue
    if b[i+1] < l:
        ans += (i+1) * (l - b[i+1]) * (n - r)
    else:
        ans += (i+1) * (b[i+1] - r) * (l + 1)
    l = min(l, b[i+1])
    r = max(r, b[i+1])
ans += n
print(ans)
0