do_good_'s blog

By do_good_, history, 8 years ago, In English

In Problem 877F , how to apply Mo's algorithm ? while traversing each block what to do ? editorial is not well explained .

Suppose a[] = { 1 , 1 , 1 , -1 } . We want to get all subarray's in the range 2--4 with sum = 1 .

Approach with HashMap would be linear complexity and total Time Complexity would be O(N*Q) if there are q queries.

**how to reduce it to sqrt. decomposition . **

  • Vote: I like it
  • -8
  • Vote: I do not like it

| Write comment?
»
8 years ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Can you not use exclamation marks everywhere? It looks very rude.

»
8 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

first calculate prefix sums on each index

then start normal mo's algorithm,but in each step add or remove the prefix sum that you are on it

after that for each query you want to count the number of j's such that sum[i]-sum[j] = k,or you want to know the j's that sum[i]+k= sum[j],and you calculated this number before so you can easily answer each query

  • »
    »
    8 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    what is normal mo's algorithm , this is where i am having difficulty . since the problem can be solved using n*q time , by every time querying number of subaarryas with sum = k in the range L , R by the using prefix sum and hashmap.

    but from here how should i reduce it to sqrt(N) , how to apply mo's algo. here , what to do ?

    M_H_H_7