UPDATEIT - Update the array !
You have an array containing n elements initially all 0. You need to do a number of update operations on it. In each update you specify l, r and val which are the starting index, ending index and value to be added. After each update, you add the 'val' to all elements from index l to r. After 'u' updates are over, there will be q queries each containing an index for which you have to print the element at that index.
First line consists of t, the number of test cases. (1 <= t <= 10)
Each test case consists of "n u",number of elements in the array and the number of update operations, in the first line (1 <= n <= 10000 and 1 <= u <= 100000)
Then follow u lines each of the format "l r val" (0 <= l,r < n, 0 <= val <=10000)
Next line contains q, the number of queries. (1 <= q <= 10000)
Next q lines contain an index (0 <= index < n)
For each test case, output the answers to the corresponding queries in separate lines.
0 1 7
2 4 6
1 3 2
learned difference array useLast edit: 2019-01-08 12:00:12
Simply use a difference array :)
AC in no goes! :)
ac in one go :) done with normal cumulative sum array
Thanks to rajcoolaryan, similarly got TLE for cin cout.
Segment Tree with lazy propogation done the job...! :p
AC in one go :)
prefect question to implement BIT/Fenwick TreeLast edit: 2018-08-11 20:04:14
Did anyone solve using bitmask?
sqrt decomposition or BIT or difference array