Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

shahidul_brur's blog

By shahidul_brur, 8 years ago, In English

problem link: 61E - Противник слаб

Reading the editorial and seeing other's code I have come to know that the problem is solvable by using binary indexed tree — BIT (aka fenwick tree). But I didn't understand how binary indexed tree is applicable for this problem.

Though I know BIT, I don't understand how to solve this problem using BIT. In contest hour, how should I determine that I should use BIT for this problem?

I have also read some code of others, but I didn't understand any full code. Specially, what is the use of lower_bound here? What it is doing?

Can anybody help me to solve and understand fully the problem, tricks behind this problem, solution — how BIT is working here and how did you understand that this is solvable by BIT ?

Thanks in advance.

  • Vote: I like it
  • +3
  • Vote: I do not like it

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

suppose we choose a[j] as our middle element then number of ways = number of i such that i < j and a[i] > a[j] * number of k such that k > j and a[k] < a[j] . we can easily find this using BIT or segment tree

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

My solution has a large amount of comments, so it might help you understand what's going on in mine and others' code: http://codeforces.net/contest/61/submission/8675312

As for the technique, this problem is very similar to inversion counting (though slightly more complicated), which you can read more about by Googling "counting inversions with a bit" (without the quotes).

»
8 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

I don't know how to solve it with a single BIT tree, but with two BIT trees a very simple.

If you know how to solve a[i] < a[j], i > j problem, also known as inversion pairs, this code easy to understand.

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

well this might help 24408090 . In this code I have used ordered_set which can be used by including the headers in my code. It works like std::set but also supports order of an element and finding element by order. Nevertheless you must learn BIT and segment tree. this is just for your understanding.