結果

問題 No.1435 Mmm......
ユーザー tyawanmusityawanmusi
提出日時 2020-10-22 17:04:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,723 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 10,884 KB
実行使用メモリ 55,368 KB
最終ジャッジ日時 2023-09-28 14:42:01
合計ジャッジ時間 23,524 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,060 KB
testcase_01 AC 17 ms
8,116 KB
testcase_02 AC 16 ms
8,144 KB
testcase_03 AC 16 ms
8,184 KB
testcase_04 AC 16 ms
8,020 KB
testcase_05 AC 17 ms
8,156 KB
testcase_06 AC 1,107 ms
42,348 KB
testcase_07 AC 1,299 ms
45,168 KB
testcase_08 AC 1,474 ms
47,844 KB
testcase_09 AC 1,361 ms
46,556 KB
testcase_10 AC 1,222 ms
44,188 KB
testcase_11 AC 1,216 ms
43,768 KB
testcase_12 AC 1,148 ms
42,880 KB
testcase_13 AC 1,118 ms
42,492 KB
testcase_14 AC 787 ms
28,804 KB
testcase_15 AC 1,506 ms
48,692 KB
testcase_16 AC 1,303 ms
45,372 KB
testcase_17 AC 883 ms
30,160 KB
testcase_18 AC 1,545 ms
48,944 KB
testcase_19 AC 1,195 ms
43,552 KB
testcase_20 AC 1,411 ms
47,240 KB
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

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