class BIT: def __init__(self, L): self.N = len(L) self.bit = [0]*self.N for i,l in enumerate(L): self.add(i,l) self.N0 = 1 while self.N0*2 <= self.N: self.N0 *= 2 def add(self, a, w): x = a + 1 for i in range(1000): self.bit[x-1] += w x += x & -x if x > self.N: break def sum(self, a): x = a+1 ret = 0 for i in range(1000): ret += self.bit[x-1] x -= x & -x if x <= 0: break return ret #you can use this function when the BIT has only non-negative values. def lower_bound(self, w): if w<=0: return 0 x = 0 k = self.N0 while k>0: if x+k<=self.N: if self.bit[x+k-1]D[i][k]+D[k][j]: D[i][j] = D[i][k]+D[k][j] S = [s-1 for s in S] base = [D[S[i]][S[i+1]] for i in range(K)] bit = BIT(base) Q = int(input()) for i in range(Q): #print(base) T,X,Y = list(map(int,input().split())) if T==1: S[X] = Y - 1 if X>0: bit.add(X-1, D[S[X-1]][S[X]] - base[X-1]) base[X-1] = D[S[X-1]][S[X]] if X<=K-1: bit.add(X, D[S[X]][S[X+1]] - base[X]) base[X] = D[S[X]][S[X+1]] else: if X>0: print(bit.sum(Y-1) - bit.sum(X-1)) else: if Y > 0: print(bit.sum(Y-1)) else: print(0)