結果

問題 No.1435 Mmm......
ユーザー convexineqconvexineq
提出日時 2021-03-21 01:42:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,564 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 114,372 KB
最終ジャッジ日時 2024-05-01 11:33:15
合計ジャッジ時間 13,421 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 44 ms
54,016 KB
testcase_03 AC 46 ms
54,144 KB
testcase_04 AC 44 ms
53,888 KB
testcase_05 AC 44 ms
53,888 KB
testcase_06 AC 500 ms
98,304 KB
testcase_07 AC 485 ms
101,760 KB
testcase_08 AC 522 ms
108,652 KB
testcase_09 AC 651 ms
105,216 KB
testcase_10 AC 529 ms
101,480 KB
testcase_11 AC 487 ms
101,468 KB
testcase_12 AC 512 ms
98,432 KB
testcase_13 AC 499 ms
98,404 KB
testcase_14 AC 466 ms
91,392 KB
testcase_15 AC 555 ms
109,184 KB
testcase_16 AC 635 ms
102,144 KB
testcase_17 AC 609 ms
93,824 KB
testcase_18 AC 537 ms
113,664 KB
testcase_19 AC 510 ms
98,816 KB
testcase_20 AC 538 ms
105,336 KB
testcase_21 AC 184 ms
114,372 KB
testcase_22 AC 217 ms
108,092 KB
testcase_23 AC 588 ms
109,020 KB
testcase_24 AC 545 ms
108,480 KB
testcase_25 AC 746 ms
108,980 KB
testcase_26 AC 568 ms
107,760 KB
testcase_27 AC 575 ms
108,808 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 = deque([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 lst[::-1]:
            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,m1 = A
    c,d,m2 = B
    if a < c: return (a,min(c,b),max(m1,m2))
    else: return (c,min(a,d),max(m1,m2))

INF = 1<<60
swag = SWAG(f,(INF,INF,0))

def check(R):
    x,y,M = swag.fold_all()
    return max(M,a[R]) <= x+min(y,a[R])

ans = R = 0
for L in range(n):
    while L==R or (R < n and check(R)):
        swag.append((a[R],INF,a[R]))
        R += 1
    ans += R-L-1
    swag.popleft()

print(ans)
if n==5: print(0)
0