You have to use lazy propagation in your function preprocess1. You are actually updating all values in the range for query type 0 (consider a test case where all the C commands are “0 1 n 1”, and see), making it an O(C*N) code, thus getting TLE. By lazy propagation you can reduce complexity of each query of type 0 p q v to log(N).