Need help with SPOJ problem FREQ2

Revision en1, by harsha_1_2, 2020-04-19 13:09:35

I am solving problems on mo's algorithm and came across this problem FREQ2. I am using an array (inv_freq) where inv_freq[x] stores the no of distinct elements having frequency x along with a dynamically updated square root decomposed array of this to find the max frequency. I believe its complexity is O((Q+N)*sqrt(N)). My solution is timing out. Can someone help with a better way to find this maximum?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English harsha_1_2 2020-04-23 15:40:16 294
en1 English harsha_1_2 2020-04-19 13:09:35 529 Initial revision (published)