scanf("%d %d %d %d",&p,&q,&r,&s);
not able to get the runtime error in this code!please help!
The number of queries in the question can be at max 105…but your array test is of size 103…hence this might be the reason behind runtime error…
Although runtime error is rectified…but you code needs some optimization to pass the test cases in time…I have tried to submit the rectified code and it gives TLE…You can go for some precomputation before entertaining the queries
you are right after rectifying the runtime error still it gives tle
can u suggest some precomputation thats needed?
You can pre-compute the cumulative frequencies of each number row-wise…then at the time of entertaining queries…run a loop just to iterate the rows and check for the occurrences of each number by subtracting cumulative frequencies(i.e. arr[i][y2][k]-arr[i][y1][k])…where k is the number whose cumulative frequency you want to check till arr[i][j].
what do cumulative frequency mean?
what do c.f mean
No need to get confused with cumulative frequency…what I mean to say is you need to keep track of how many times a number has occurred before…
You can refer to my solution for better understanding of how to precompute…
Is this what u are saying?
for each row maintain an array for cumulative frequencies…
i didn’t get “run a loop just to iterate the rows and check for the occurrences of each number by subtracting cumulative frequencies”
i am uncomfortable with 3d arrays
I have 2 doubts which i am totally unable to get.
1.Suppose you have a matrix and count array for every row
1 2 3 1 1 1 0 0 0 0 0 0 0 4 5 6 0 0 0 1 1 1 0 0 0 0 7 8 9 0 0 0 0 0 0 1 1 1 0
now suppose you enter a query 2 2 3 3.Now from count array how can we get the answer.Suppose we travel the count array from row 2 you have recorded an occurence of 4 there but it is not in your query part.
so what to do?
2.are we going to travel all elements included in the query?