結果

問題 No.1435 Mmm......
ユーザー convexineqconvexineq
提出日時 2021-03-19 22:47:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,145 ms / 2,000 ms
コード長 1,768 bytes
コンパイル時間 449 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 124,916 KB
最終ジャッジ日時 2023-08-12 03:36:26
合計ジャッジ時間 20,694 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
71,752 KB
testcase_01 AC 87 ms
71,696 KB
testcase_02 AC 89 ms
71,756 KB
testcase_03 AC 87 ms
71,640 KB
testcase_04 AC 88 ms
71,560 KB
testcase_05 AC 88 ms
71,412 KB
testcase_06 AC 857 ms
100,436 KB
testcase_07 AC 948 ms
103,500 KB
testcase_08 AC 1,145 ms
110,672 KB
testcase_09 AC 796 ms
107,312 KB
testcase_10 AC 922 ms
103,260 KB
testcase_11 AC 945 ms
103,240 KB
testcase_12 AC 781 ms
100,080 KB
testcase_13 AC 957 ms
100,836 KB
testcase_14 AC 693 ms
93,364 KB
testcase_15 AC 868 ms
110,912 KB
testcase_16 AC 794 ms
104,180 KB
testcase_17 AC 981 ms
96,292 KB
testcase_18 AC 865 ms
110,800 KB
testcase_19 AC 759 ms
101,004 KB
testcase_20 AC 822 ms
106,856 KB
testcase_21 AC 260 ms
124,916 KB
testcase_22 AC 303 ms
112,616 KB
testcase_23 AC 960 ms
113,808 KB
testcase_24 AC 857 ms
113,884 KB
testcase_25 AC 865 ms
114,452 KB
testcase_26 AC 844 ms
114,384 KB
testcase_27 AC 885 ms
114,536 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