cf gym 100960 G. Youngling Tournament set+树状数组
Yoda, the Grand Master of the Jedi Order, hit on the idea to hold a tournament among younglings. He has not chosen the date yet, but he has already decided on the format of the tournament.
There are N younglings studying in the Jedi Temple. Yoda can feel the Force inside younglings, moreover, he can represent the amount of the Force inside i-th youngling as the number fi.
Therefore, the format of the tournament is the following. At first, Yoda makes the children stand in a row in order of non-increasing fi. Then, the first youngling in the row competes against all the others united together. The combat is based on lightsaber battle and is very spectacular. However, Yoda knows that the result doesn't depend on anything but the Force inside competitors. The youngling wins if his amount of Force is not less than the total amount of the Force inside all his opponents. In that case, he is considered one of the winners. Otherwise, he loses. Anyway, after that he is removed from the row, and the tournament continues. Again, the strongest (first in the row) youngling competes against all the others standing in the row in the same format, if he wins, he is also considered one of the winners. After that he is removed and the tournament continues in the same format until there is only one child in the row. He becomes one of the winners automatically and the tournament finishes.
Yoda wants to know the total number of winners. However, as the tournament is postponed again and again, the amount of the Force inside the younglings changes from time to time. Help Yoda to compute the total number of winners after each change.
The first line of input contains a single integer N, the number of younglings in the Jedi Temple (1 ≤ N ≤ 100 000).
The second line contains N integers f1, f2, ..., fN the amount of the Force inside the younglings (1 ≤ fi ≤ 1012).
The third line of the input contains a single integer M, the number of changes in the Force amounts of students (0 ≤ M ≤ 50 000).
The next M lines contain information about the changes. The i-th of these lines describes the i-th change and contains two integers kand fk * , which mean that the amount of the Force inside the k-th youngling becomes equal to fk * (1 ≤ k ≤ N, 1 ≤ fk * ≤ 1012).
Print M + 1 lines, each of them containing a single integer.
On the first line, print the number of winners if the tournament was held before all the changes. On line (i + 1) for all i > 0, print the number of winners if the tournament was held after the first i changes.
3
2 1 3
3
1 3
2 7
3 5
3
2
3
2
7
2 14 14 15 5 2 5
5
5 2
4 12
5 4
3 10
7 9
4
3
3
3
3
4
题意
统计一个集合从大到小开始删元素,如果当前元素的值大于余下的值的总和,ans++
题解
题意类似fib数列,所以最多有logn个答案
每次暴力从小往大统计,找到大于等于当前的sum的值ans++;
至于修改直接维护一下set和统计和用到的树状数组就好