Album of Numbers
Time limit3sMemory limit128 MB
After each insertion or deletion in a multiset, print the arithmetic mean of the minima over all distinct nonempty sub-multisets of the album.
- Level
Medium7 of 10
- Topics
- Combinatorics, Segment tree, Math
- Solved
- No attempts yet
Statement
Johnny is a collector of numbers. He has a large album with them, which he keeps updating by inserting new numbers and deleting old ones.
This album is Johnny's most prized treasure, so he wants to be sure that no one will ever replace his numbers with different ones. He therefore maintains a checksum for the album, determined as follows. He considers all distinct nonempty subsets of the numbers in the album, finds the minimum of each subset, and then calculates the arithmetic mean of these minima.
Because a number may appear multiple times in the album, the subsets are multisets: each number may appear in a subset multiple times, but no more than it appears in the whole album. Two multisets are equal if and only if every number has the same multiplicity in both. For instance, the album has the following 11 distinct subsets: , , , , , , , , , , and .
The album changes often, which makes maintaining the checksum by hand tedious. Write a program that reads the number of updates and their descriptions, determines the checksum after each operation, and prints the checksums.
Input
The first line contains a single positive integer (), the number of updates. Each of the next lines contains a sign, either + or -, a single space, and a number (). A + inserts into the album, and a - removes one occurrence of from the album.
The album is initially empty. It is always nonempty after an operation, and only numbers present in the album are ever deleted.
Output
Print exactly lines. The -th line contains the checksum after the -th update. An answer is accepted if the absolute or relative error of each checksum does not exceed .
Hint
In the first sample, after all the insertions, the album contains . At that point Johnny considers the 11 subsets listed above. Their minima are 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 5. Hence the checksum is .