I didn’t used exact brute force, but used frequency array where freq[i] stores the number of numbers less than i.
But got TLE in 4 tests.
[1]
Any optimization possible for this approach @admin, @r_64 @vijju123. Or Was Segment tree/Sqrt root decomposition only required approach for solving this problem?
[1]: https://www.codechef.com/viewsolution/17280411
I understood lovemaydie’s solution better than any other editorialist’s explanation… very good @lovemaydie … nice skill of explaining… official editorial and method are damn hard to understand…
I wrote the same thing as author but I kept getting tle. I think it’s because I implemented persistent segment tree first time. Can anyone help me with optimization.
Link CodeChef: Practical coding for everyone
Yup, the author did not write his solution. He thought that somebody will get full 100 points- he will write his solution based on that approach. Thanks @r_64 for confirmation :3
Oh…so only tester wrote a solution and that solution was used to generate the output files and the same solution was used to submit the problem? So technically no one tested the problem. Smart author I must say xD
I didnt even thpught much on the question. I just got the gist of it to submit brute force. I will think of the Q when I upsolve, and till then I cant help you here, so didnt reply.
Dont use the pointers (* operator for value referencing), instead use only arrays (see the tester’s code for implementation details). Or, you can also using segment trees instead of persistent segment tree.