Because the alternative is to update the actual array, which will result in O (N) complexity per command, thus O (N^2) comolexity for whole task, giving TLE.
using difference array, u apply update in constant time.
I have used difference arrays only and got 100 points. I have added explanation just above, alongwith a link to my code.
I saw your code . The last part of your approach is the same as mine.But I haven’t yet found out the mistake in my code.Please tell me if you find any bug in my code.
Thank you
I mean I am not able to get why you add t+1 to range[command[i][2]] and subtract it from range[command[i][1]-1] and why not like you did in query of type 1!
From here, we can ignore commands of type 2 and see, command 1 is to be executed 3 times because of other commands + 1 time for its own, as i mentioned above.
I am not sure what you are trying to say. You can see my code that just uses running totals of the difference arrays. Both command types are handled in a single pass starting from the last command.
Thanks for the detailed explanation. But can u pls tell me how u came up with such a solution. I mean is this any standard algorithm? If yes, pls link some material where I can read more about it.
Thanks again
May be it is some kind of misunderstanding, but I honestly don’t care about your code and have never asked you to explain to me anything about it. This is the editorial thread, in case you have not noticed.