import sequtils,strutils type binaryIndexTree[I:static[int]] = array[I + 1,int64] proc add(BIT :var binaryIndexTree,i : int64, a : int64)= var index = i while BIT[0] >= index: BIT[index] += a index += ((index xor (index - 1)) and index) proc sum(BIT : binaryIndexTree, i : int64):int64 = var index = i while index > 0: result += BIT[index] index = (index and (index - 1)) proc initBit(i : static[int]) : binaryIndexTree[i] = var res : binaryIndexTree[i] res[0] = i return res var N, Q : int64 (N, Q) = stdin.readline.split.map(parseBiggestInt) var BIT = initBit(100010) A = stdin.readline.split.map(parseBiggestInt) S : array[100010, int64] for i, a in A: if i == 0: continue S[i] = a - A[i - 1] if S[i] != 0: BIT.add(i, 1) for q in 1..Q: var L = stdin.readline.split.map(parseBiggestInt) var l = L[1] r = L[2] if L[0] == 1: var x = L[3] S[l - 1] += x S[r] -= x if l > 2 and S[l - 1] == 0: BIT.add(l - 1, -1) elif l > 2 and S[l - 1] == x: BIT.add(l - 1, 1) if S[r] == 0: BIT.add(r, -1) elif S[r] == -x: BIT.add(r, 1) else: echo BIT.sum(r - 1) - BIT.sum(l - 1) + 1