結果

問題 No.1435 Mmm......
ユーザー convexineqconvexineq
提出日時 2021-03-19 22:47:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,000 ms / 2,000 ms
コード長 1,768 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 123,308 KB
最終ジャッジ日時 2024-04-29 18:09:32
合計ジャッジ時間 16,659 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
54,144 KB
testcase_01 AC 41 ms
54,144 KB
testcase_02 AC 41 ms
53,888 KB
testcase_03 AC 41 ms
53,760 KB
testcase_04 AC 39 ms
54,016 KB
testcase_05 AC 40 ms
54,016 KB
testcase_06 AC 727 ms
98,560 KB
testcase_07 AC 797 ms
102,016 KB
testcase_08 AC 1,000 ms
108,288 KB
testcase_09 AC 697 ms
104,832 KB
testcase_10 AC 791 ms
101,632 KB
testcase_11 AC 813 ms
101,376 KB
testcase_12 AC 651 ms
98,624 KB
testcase_13 AC 828 ms
98,520 KB
testcase_14 AC 580 ms
91,148 KB
testcase_15 AC 711 ms
108,928 KB
testcase_16 AC 629 ms
102,016 KB
testcase_17 AC 829 ms
93,824 KB
testcase_18 AC 716 ms
113,976 KB
testcase_19 AC 630 ms
98,816 KB
testcase_20 AC 692 ms
105,088 KB
testcase_21 AC 198 ms
123,308 KB
testcase_22 AC 237 ms
109,156 KB
testcase_23 AC 804 ms
108,960 KB
testcase_24 AC 694 ms
108,432 KB
testcase_25 AC 697 ms
108,464 KB
testcase_26 AC 705 ms
108,716 KB
testcase_27 AC 701 ms
108,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0