結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,172 KB
testcase_01 AC 17 ms
8,152 KB
testcase_02 AC 17 ms
7,984 KB
testcase_03 AC 16 ms
8,008 KB
testcase_04 AC 17 ms
8,212 KB
testcase_05 AC 17 ms
8,172 KB
testcase_06 AC 1,104 ms
42,436 KB
testcase_07 AC 1,283 ms
45,336 KB
testcase_08 AC 1,443 ms
47,936 KB
testcase_09 AC 1,363 ms
46,580 KB
testcase_10 AC 1,218 ms
44,160 KB
testcase_11 AC 1,191 ms
43,772 KB
testcase_12 AC 1,131 ms
42,748 KB
testcase_13 AC 1,116 ms
42,616 KB
testcase_14 AC 788 ms
28,768 KB
testcase_15 AC 1,495 ms
48,568 KB
testcase_16 AC 1,290 ms
45,248 KB
testcase_17 AC 874 ms
30,196 KB
testcase_18 AC 1,517 ms
49,036 KB
testcase_19 AC 1,180 ms
43,592 KB
testcase_20 AC 1,401 ms
47,116 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))

MAX=10**9
MIN=0
n=int(input())
p=list(map(int,input().split()))
seg=SegmentTree(n,[(i,MAX,i)for i in p],(MAX,MAX,MIN),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