import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from operator import itemgetter N=int(input()) AT=[list(map(int,input().split())) for i in range(N)] Q=int(input()) QU=[list(map(int,input().split()))+[i] for i in range(Q)] # Segment tree(1-indexed,再帰を使わないもの) def seg_function(x,y): # Segment treeで扱うfunction return [x[i]+y[i] for i in range(3)] seg_el=1<<(N.bit_length()) # Segment treeの台の要素数 SEG=[[0,0,0] for i in range(2*seg_el)] # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化 for i in range(N): # Aを対応する箇所へupdate SEG[i+seg_el]=[AT[i][0],0,0] for i in range(seg_el-1,0,-1): # 親の部分もupdate SEG[i]=seg_function(SEG[i*2],SEG[i*2+1]) def update(n,x,seg_el): # A[n]をxへ更新 i=n+seg_el SEG[i]=x i>>=1 # 子ノードへ while i!=0: SEG[i]=seg_function(SEG[i*2],SEG[i*2+1]) i>>=1 def getvalues(l,r): # 区間[l,r)に関するseg_functionを調べる L=l+seg_el R=r+seg_el ANS=[0,0,0] while L>=1 R>>=1 return ANS for i in range(N): a,t=AT[i] if a==0: continue QU.append((t,a,i)) QU.append((t+a,i)) QU.sort(key=len) QU.sort(key=itemgetter(0)) ANS=[-1]*Q for q in QU: if len(q)==4: d,l,r,ind=q x,y,z=getvalues(l-1,r) #print(x,y,z) ANS[ind]=x-d*z+y elif len(q)==3: t,a,i=q update(i,[a,t-1,1],seg_el) else: t,i=q update(i,[0,0,0],seg_el) print("\n".join(map(str,ANS)))