Be_Careful_And_Cautious's blog

By Be_Careful_And_Cautious, history, 5 years ago, In English

Since the editorial is in japenese. I didn't understand the logic of Task E. Please help

https://atcoder.jp/contests/abc166/tasks/abc166_e

| Write comment?
»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

We shall consider each $$$A_i$$$ and count number of $$$j > i$$$ such that $$$A_i$$$ and $$$A_j$$$ satisfy the condition. Then the requirement is $$$j - i = A_i + A_j$$$, which can be rewritten as $$$j - A_j = i + A_i$$$. So basically, we need to count the number of $$$j$$$'s for which $$$j-A_j$$$ matches a given value. We can precalculate this value for all indices, store in a map, and query it every time to add to the final answer. Be careful to reduce the count of $$$i - A_i$$$ while moving to the next one. My submission

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it
  1. The question is asking us to find all pairs of indices i,j where j> i such that j-i = a[i]+a[j]
  2. interchange the above formula into getting j terms on one side and i terms on one side => j-a[j] = a[i]+i.
  3. This changes the problem statement to find all i,j j > i such that j-a[j] = a[i]+i
  4. use map to store number of indeces having value x = a[i]+i before j and calculate the answer.