結果
| 問題 | No.1435 Mmm...... | 
| コンテスト | |
| ユーザー |  convexineq | 
| 提出日時 | 2021-03-19 22:47:14 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,013 ms / 2,000 ms | 
| コード長 | 1,768 bytes | 
| コンパイル時間 | 281 ms | 
| コンパイル使用メモリ | 82,436 KB | 
| 実行使用メモリ | 123,296 KB | 
| 最終ジャッジ日時 | 2024-11-19 00:07:28 | 
| 合計ジャッジ時間 | 17,176 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 24 | 
ソースコード
from collections import deque
class SWAG:
    def __init__(self, operator_M, e_M):
        self.op_M = operator_M
        self.e_M = e_M
        self.q = deque()
        self.accL = [e_M]
        self.accR = e_M
        self.L = self.R = 0
    def build(self,lst):
        self.q = deque(lst)
        self.L = len(lst)
        for i in reversed(lst):
            self.accL.append(self.op_M(i,self.accL[-1]))
    def __len__(self):
        return self.L + self.R
    def fold_all(self):
        return self.op_M(self.accL[-1],self.accR)
    def append(self,x):
        self.q.append(x)
        self.accR = self.op_M(self.accR,x)
        self.R += 1
    
    def popleft(self):
        if self.L:
            self.accL.pop()
            self.L -= 1
            return self.q.popleft()
        elif self.R:
            v = self.q.popleft()
            self.L,self.R = self.R-1,0
            for i in reversed(self.q):
                self.accL.append(self.op_M(i,self.accL[-1]))
            self.accR = self.e_M
            return v
        else:
            assert 0
n = int(input())
*a, = map(int,input().split())
def f(A,B):
    a,b = A
    c,d = B
    if a < c: return (a,min(c,b))
    else: return (c,min(a,d))
INF = 1<<60
maxswag = SWAG(max,0)
minswag = SWAG(f,(INF,INF))
def check(R):
    A = minswag.fold_all()
    M = maxswag.fold_all()
    #print(L,R,f(A,(a[R],INF)),max(M,a[R]))
    return max(M,a[R]) <= sum(f(A,(a[R],INF)))
ans = R = 0
for L in range(n):
    if L == R:
        maxswag.append(a[R])
        minswag.append((a[R],INF))
        R += 1
    while R < n and check(R):
        maxswag.append(a[R])
        minswag.append((a[R],INF))
        R += 1
    ans += R-L-1
    #print(L,R)
    maxswag.popleft()
    minswag.popleft()
print(ans)
            
            
            
        