結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー flygonflygon
提出日時 2022-10-14 23:48:29
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 3,141 ms / 6,000 ms
コード長 1,421 bytes
コンパイル時間 664 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 188,076 KB
最終ジャッジ日時 2023-09-09 00:19:59
合計ジャッジ時間 95,431 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
101,508 KB
testcase_01 AC 117 ms
101,640 KB
testcase_02 AC 115 ms
101,764 KB
testcase_03 AC 1,463 ms
147,680 KB
testcase_04 AC 2,090 ms
168,000 KB
testcase_05 AC 1,460 ms
141,756 KB
testcase_06 AC 2,102 ms
161,804 KB
testcase_07 AC 2,177 ms
170,788 KB
testcase_08 AC 2,291 ms
163,884 KB
testcase_09 AC 1,238 ms
137,980 KB
testcase_10 AC 1,091 ms
132,732 KB
testcase_11 AC 1,610 ms
149,292 KB
testcase_12 AC 1,647 ms
151,724 KB
testcase_13 AC 1,278 ms
137,752 KB
testcase_14 AC 1,205 ms
139,844 KB
testcase_15 AC 2,413 ms
176,512 KB
testcase_16 AC 2,188 ms
171,540 KB
testcase_17 AC 873 ms
129,560 KB
testcase_18 AC 2,873 ms
183,992 KB
testcase_19 AC 3,050 ms
186,040 KB
testcase_20 AC 2,899 ms
186,564 KB
testcase_21 AC 2,941 ms
187,004 KB
testcase_22 AC 2,847 ms
184,932 KB
testcase_23 AC 3,028 ms
186,816 KB
testcase_24 AC 3,141 ms
186,000 KB
testcase_25 AC 3,011 ms
183,824 KB
testcase_26 AC 3,051 ms
186,460 KB
testcase_27 AC 3,001 ms
185,408 KB
testcase_28 AC 2,850 ms
183,908 KB
testcase_29 AC 2,859 ms
184,052 KB
testcase_30 AC 2,932 ms
184,492 KB
testcase_31 AC 2,884 ms
184,672 KB
testcase_32 AC 2,917 ms
184,540 KB
testcase_33 AC 2,648 ms
186,640 KB
testcase_34 AC 2,700 ms
187,412 KB
testcase_35 AC 2,636 ms
188,076 KB
testcase_36 AC 2,677 ms
187,408 KB
testcase_37 AC 2,682 ms
185,992 KB
testcase_38 AC 418 ms
135,088 KB
testcase_39 AC 1,167 ms
144,336 KB
testcase_40 AC 853 ms
185,760 KB
testcase_41 AC 107 ms
101,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
at = [list(map(int,input().split())) for i in range(n)]
q = int(input())
qs = [list(map(int,input().split()))+[i] for i in range(q)]
qs.sort()
seg_len = 1<<19 # > 5*(10**5)
seg = [0]*(2*seg_len)
cnt = [0]*(2*seg_len)
days = [0]*(2*seg_len)

from collections import deque
start =[]
end = []
for i,(a,t) in enumerate(at):
  start.append((t,i+1))
  end.append((a+t, i+1))
start.sort()
end.sort()
start = deque(start)
end = deque(end)
# 必要に応じて初期状態構築
for i in range(n):
  seg[i+1+seg_len] = at[i][0]
for i in range(seg_len)[::-1]:
  seg[i] = seg[i*2] + seg[i*2+1]
def update(pos,x,seg):
  pos += seg_len
  seg[pos] = x 
  while True: 
    pos >>= 1 
    if not pos: break 
    seg[pos] = seg[pos<<1] + seg[pos<<1|1]

def get_query(l,r,seg):
  l += seg_len; r += seg_len
  res = 0 
  while l < r: 
    if l & 1: 
      res += seg[l] 
      l += 1 
    if r & 1: 
      r -= 1 
      res += seg[r] 
    l >>= 1; r >>= 1
  return res


ans = [0]*(q)
for d,l,r,i in qs:
  if start:
    while start[0][0] <= d:
      x,y = start.popleft()
      update(y, 1, cnt)
      update(y, x-1, days)
      if not start: break
  if end:
    while end[0][0] <= d:
      x,y = end.popleft()
      update(y, 0, cnt)
      update(y, 0, days)
      update(y, 0, seg)
      if not end:break
  ans[i] = get_query(l, r+1, seg) - (get_query(l, r+1, cnt)*d-get_query(l, r+1, days))

print(*ans, sep = "\n")
  

0