結果

問題 No.1705 Mode of long array
ユーザー harurunharurun
提出日時 2021-10-02 11:00:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 454 ms / 3,000 ms
コード長 2,800 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 86,420 KB
実行使用メモリ 98,396 KB
最終ジャッジ日時 2023-09-30 09:45:54
合計ジャッジ時間 20,174 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,008 KB
testcase_01 AC 77 ms
71,004 KB
testcase_02 AC 78 ms
70,840 KB
testcase_03 AC 135 ms
78,068 KB
testcase_04 AC 123 ms
78,008 KB
testcase_05 AC 147 ms
78,604 KB
testcase_06 AC 209 ms
79,112 KB
testcase_07 AC 212 ms
79,312 KB
testcase_08 AC 208 ms
79,744 KB
testcase_09 AC 191 ms
78,736 KB
testcase_10 AC 199 ms
78,736 KB
testcase_11 AC 204 ms
79,080 KB
testcase_12 AC 212 ms
78,644 KB
testcase_13 AC 405 ms
93,052 KB
testcase_14 AC 362 ms
88,244 KB
testcase_15 AC 365 ms
81,968 KB
testcase_16 AC 437 ms
83,168 KB
testcase_17 AC 332 ms
81,228 KB
testcase_18 AC 307 ms
81,812 KB
testcase_19 AC 449 ms
86,048 KB
testcase_20 AC 335 ms
84,276 KB
testcase_21 AC 385 ms
91,452 KB
testcase_22 AC 452 ms
95,476 KB
testcase_23 AC 224 ms
77,964 KB
testcase_24 AC 224 ms
78,220 KB
testcase_25 AC 232 ms
78,364 KB
testcase_26 AC 231 ms
78,412 KB
testcase_27 AC 229 ms
78,052 KB
testcase_28 AC 230 ms
78,284 KB
testcase_29 AC 231 ms
78,236 KB
testcase_30 AC 224 ms
78,092 KB
testcase_31 AC 231 ms
78,712 KB
testcase_32 AC 230 ms
78,316 KB
testcase_33 AC 437 ms
97,476 KB
testcase_34 AC 401 ms
97,944 KB
testcase_35 AC 444 ms
98,396 KB
testcase_36 AC 403 ms
98,344 KB
testcase_37 AC 401 ms
97,968 KB
testcase_38 AC 409 ms
97,360 KB
testcase_39 AC 405 ms
97,568 KB
testcase_40 AC 416 ms
98,112 KB
testcase_41 AC 450 ms
98,244 KB
testcase_42 AC 454 ms
98,244 KB
testcase_43 AC 376 ms
95,364 KB
testcase_44 AC 406 ms
95,348 KB
testcase_45 AC 406 ms
95,220 KB
testcase_46 AC 398 ms
95,196 KB
testcase_47 AC 394 ms
95,384 KB
testcase_48 AC 399 ms
95,424 KB
testcase_49 AC 417 ms
95,104 KB
testcase_50 AC 420 ms
95,328 KB
testcase_51 AC 420 ms
95,192 KB
testcase_52 AC 427 ms
95,124 KB
testcase_53 AC 420 ms
95,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegTree:
  def __init__(self,op,e,v):
    self._op=op
    self._e=e
    
    if isinstance(v,int):
      v=[e]*v
    
    self._n=len(v)
    self._log=self.ceil2()
    self._size=1<<self._log
    self._d=[e]*(2*self._size)
    
    for i in range(self._n):
      self._d[self._size+i]=v[i]
    for i in range(self._size-1,0,-1):
      self._update(i)
    return
  
  def ceil2(self):
    x=0
    while (1<<x)<self._n:
      x+=1
    return x
    
  def set(self,p,x):
    p+=self._size
    self._d[p]=x
    for i in range(1,self._log+1):
      self._update(p>>i)
    return
    
  def get(self,p):
    return self._d[p+self._size]
    
  def prod(self,left,right):
    sml=self._e
    smr=self._e
    left+=self._size
    right+=self._size
    while left<right:
      if left&1:
        sml=self._op(sml,self._d[left])
        left+=1
      if right&1:
        right-=1
        smr=self._op(self._d[right],smr)
      left>>=1
      right>>=1
    return self._op(sml,smr)
    
  def all_prod(self):
    return self._d[1]
  
  def max_right(self,left,target):
    self.target=target
    if left==self._n:
      return self._n
    left+=self._size
    sm=self._e
    
    first=True
    while first or (left & -left)!=left:
      first=False
      while left%2==0:
        left>>=1
      if not self._f(self._op(sm,self._d[left])):
        while left<self._size:
          left*=2
          if self._f(self._op(sm,self._d[left])):
            sm=self._op(sm,self._d[left])
            left+=1
        return left-self._size
      sm=self._op(sm,self._d[left])
      left+=1
    return self._n
    
  def min_left(self,right,target):
    self.target=target
    if right==0:
      return 0
    
    right+=self._size
    sm=self._e
    
    first=True
    while first or (right&-right)!=right:
      first=False
      right-=1
      while right>1 and right%2:
        right>>=1
      if not self._f(self._op(self._d[right],sm)):
        while right<self._size:
          right=2*right+1
          if self._f(self._op(self._d[right],sm)):
            sm=self._op(self._d[right],sm)
            right-=1
        return right+1-self._size
      sm=self._op(self._d[right],sm)
    return 0
  
  def _update(self,k):
    self._d[k]=self._op(self._d[2*k],self._d[2*k+1])
    return

  def _f(self,u):
    return u<self.target

def op(a,b):
  if a[0]>b[0]:
    return a
  else:
    return b

def main():
  N,M=map(int,input().split())
  A=list(map(int,input().split()))
  for i in range(M):
    A[i]=[A[i],i+1]
  seg=SegTree(op,[-1,-1],A)
  Q=int(input())
  for i in range(Q):
    T,X,Y=map(int,input().split())
    if T==1:
      d=seg.get(X-1)
      seg.set(X-1,[d[0]+Y,d[1]])
    elif T==2:
      d=seg.get(X-1)
      seg.set(X-1,[d[0]-Y,d[1]])
    else:
      print(seg.all_prod()[1])
  return

main()
0