Median
Time Limit: 5 Seconds Memory Limit: 65536 KB
The median of m numbers is after sorting them in order, the middle one number of them if m is even or the average number of the middle 2 numbers if m is odd.
You have an empty number list at first. Then you can add or remove some number from the list.
For each add or remove operation, output the median of the number in the list please.
This problem has several test cases. The first line of the input is an integer T (0<T<=100) indicates the number of test cases. The first line of each test case is an
integer n(0<n<=10000) indicates the number of operations. Each of the next n lines is either "add x" or "remove x"(-231<=x<231) indicates the operation.
For each operation of one test case: If the operation is add output the median after adding x in a single line. If the operation is remove and the number x is
not in the list, output "Wrong!" in a single line. If the operation is remove and the number x is in the list, output the median after deleting x in a single line, however the list is empty output "Empty!".
if the result is an integer DO NOT output decimal point. And if the result is a double number , DO NOT output trailing 0s.
題意:給你一個容器,每次執行add或者remove操作,當容器不為空時,輸出容器中元素的中位數;如果為空,輸出Empty!或者Wrong!
分析:比賽時也想到了用multiset,但是删除時會把所有相同的元素一起删掉,沒想到用指針指向要删除的元素。這題還可以用樹狀數組或者線段樹來做。