Help in Second Question TSHACK

What is the difference between maintaining a count array for counting frequencies and using map for doing so in C++14. Consider constraints to be 10^6 for which making a count array comes out to be valid.
It comes out to be a runtime error when I uploaded my solution.
Runtime error solution -
https://www.codechef.com/viewsolution/26862797
Correct Solution -
https://www.codechef.com/viewsolution/26863337

https://www.codechef.com/viewsolution/26863741

I am also getting Run time error. can anyone figure it out

In Line 43. You might be trying to access cc[1000006] which doesn’t exist

1 Like

https://www.codechef.com/viewsolution/26862262
Even this came out to be a runtime error.
Here I am going till 1000006.

I think I understand in while(q–) part it is not necessary to query can be asked within the limit of it can be anything so To get max we have to simply get the last element of that prefix sum. therefore we have to take care of min(input query, size of the prefix)

OKK!! thanks I should try rectifying my previous solutions however i figured it out what you are saying in my rest of solutions. It must be because of what @s5960r said .

1 Like

You Must include the condition in which query position goes out of scope or out of bound
if(query_position > total different_element)
query_position = total_different_element

Yes bro !! I included that condition in solutions which i further submitted,It must be due to accessing array element out of bounds.:sweat_smile: