But i have declared my array in main which can access maximum index as [(10^6)-1], but in this question input is 10^7 ,So How array is accessing [(10^7)-1]th index?
Yes, But in the Problem it’s written that
" Sum of |S|and Q over all testcases for a particular test file does not exceed 10^7 and 10^6 respectively."
But we should not take it for granted that there will be no such string with length as 10^7.May be they have included only one test file and its written to trick the participant. Right?
I just tried in cc IDE to create an array of size 1e7 in main and it ran
I think you should write following statement:
assert (n==1e7);
instead of:
assert (n<=5*1e6);
Because we are checking if there is a input of 10^7 or not.
Am i Right?
No…try to understand on your own.
Can You Explain Please… Not able to undertand!
Okay, there will be many cases… in some cases n will be 1e6(say) and 1e7 in others. So former assert statement will always give re because Problem says n<=1e7 doesn’t guarantees n=1e7. So with that re we can’t infer anything.
With second assert statement, it gives re so that means there are tc were n> 5*1e6.
You can try something like - assert n<1e7. If it gives re then we are sure there are tc where n=1e7.
Gives error on cc IDE
Thank You So much For the Explaination!
Now The Question Arises why using array for hashing passes in this Problem?
Because Array can access maximum index as [(10^6)-1] and how is it accessing [(10^7)-1] index?
Using Array Gives AC
I just ran on Codechef IDE it executes successfuly giving output as 3
Sorry, no idea😶
Okay No Issues!!
Cool, I used map there when the contest was live, without knowing unordered_map would get TLE.
Thanks for telling.
Running this code locally gave segmentation fault, which was expected.
But on ideone it declares an array of size INT_MAX (due to 1e20 overflow prolly).
It prints a[n - 1] = 3, and the sizeof array = 8589934588.
link
Thanks For this Information !