結果

問題 No.1435 Mmm......
ユーザー tyawanmusityawanmusi
提出日時 2020-10-22 17:03:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 446 ms / 2,000 ms
コード長 1,723 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 86,968 KB
実行使用メモリ 138,256 KB
最終ジャッジ日時 2023-09-28 14:41:37
合計ジャッジ時間 11,296 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,516 KB
testcase_01 AC 74 ms
71,484 KB
testcase_02 AC 70 ms
71,320 KB
testcase_03 AC 72 ms
71,532 KB
testcase_04 AC 70 ms
71,388 KB
testcase_05 AC 70 ms
71,292 KB
testcase_06 AC 376 ms
114,724 KB
testcase_07 AC 408 ms
117,728 KB
testcase_08 AC 429 ms
120,728 KB
testcase_09 AC 405 ms
119,196 KB
testcase_10 AC 399 ms
117,232 KB
testcase_11 AC 390 ms
117,308 KB
testcase_12 AC 392 ms
115,472 KB
testcase_13 AC 382 ms
115,060 KB
testcase_14 AC 317 ms
100,868 KB
testcase_15 AC 415 ms
121,056 KB
testcase_16 AC 407 ms
117,800 KB
testcase_17 AC 342 ms
102,672 KB
testcase_18 AC 432 ms
121,784 KB
testcase_19 AC 377 ms
116,184 KB
testcase_20 AC 422 ms
119,744 KB
testcase_21 AC 310 ms
138,256 KB
testcase_22 AC 368 ms
120,804 KB
testcase_23 AC 446 ms
138,216 KB
testcase_24 AC 432 ms
137,952 KB
testcase_25 AC 429 ms
137,908 KB
testcase_26 AC 443 ms
138,028 KB
testcase_27 AC 435 ms
138,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegmentTree:
  def __init__(self, n, p, unit, f):
    self.n = n
    self.num = 2**((n-1).bit_length())
    self.seg = [unit]*(self.num*2)
    for i in range(n):
      self.seg[self.num+i] = p[i]
    for i in range(self.num-1, 0, -1):
      self.seg[i] = f(self.seg[i << 1], self.seg[(i << 1)+1])
    self.unit = unit
    self.f = f

  def update(self, i, x):
    i += self.num
    self.seg[i] = x
    while i:
      i >>= 1
      self.seg[i] = self.f(self.seg[i << 1], self.seg[(i << 1)+1])

  def query(self, l, r):
    ansl = ansr = self.unit
    l += self.num
    r += self.num-1
    if l == r:
      return self.seg[l]
    while l < r:
      if l & 1:
        ansl = self.f(ansl, self.seg[l])
        l += 1
      if ~r & 1:
        ansr = self.f(self.seg[r], ansr)
        r -= 1
      l >>= 1
      r >>= 1
    if l == r:
      ansl = self.f(ansl, self.seg[l])
    return self.f(ansl, ansr)

  def max_right(self, l, g):
    l += self.num
    ll = l // (l & -l)
    ans = self.unit
    while g(self.f(ans, self.seg[ll])):
      ans = self.f(ans, self.seg[ll])
      ll += 1
      while ~ll & 1:
        ll >>= 1
      if ll == 1:
        return self.n
    while ll < self.num:
      ll <<= 1
      if g(self.f(ans, self.seg[ll])):
        ans = self.f(ans, self.seg[ll])
        ll += 1
    return ll-self.num

def f(x,y):
  xm1,xm2,xM=x
  ym1,ym2,yM=y
  if xm1<ym1:
    m1=xm1
    m2=min(ym1,xm2)
  else:
    m1=ym1
    m2=min(xm1,ym2)
  return (m1,m2,max(xM,yM))

n=int(input())
a=list(map(int,input().split()))
aa=[]
for i in a:
  aa.append((i,1000000000,i))
seg=SegmentTree(n,aa,(1000000000,1000000000,0),f)
ans=0
for l in range(n-1):
  r=seg.max_right(l, lambda x: x[2]<=x[0]+x[1])
  ans+=r-l-1
print(ans)
0