#FT0000213. Xóa lần lượt các trung vị (Remove Median Operations)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Xóa lần lượt các trung vị (Remove Median Operations)
Remove Median Operations
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given two sequences of positive integers, and . The length of is even. Both sequences are indexed from .
Process assignment queries in order:
1 i x: Replace by .2 i x: Replace by .
Immediately after each assignment, perform the following experiment on the current sequences, starting from scratch for that query:
- Initialize a multiset with the elements of , retaining duplicate values.
- For , in this order, insert into , then remove exactly one median element of .
- After processing all elements of , output the sum of the elements remaining in .
Before each removal in step 2, has elements. As is even, is odd; the median is the element in position in nondecreasing order. If multiple elements equal this median, remove only one occurrence.
Print the required sum after each assignment query in the original order.
Input
- The first line contains : the length of , the length of , and the number of assignment queries.
- The second line contains exactly integers .
- The third line contains exactly integers .
- Each of the next lines contains
t i x. If , set ; if , set . Index is -based within the specified sequence.
Output
Print exactly lines. Line contains the sum of the multiset after processing assignment and then performing all insertion-and-median-removal steps.
Subtasks
- Subtask 1 (20 points): and is even; ; ; for every valid position; every operation has and ; for , ; for , .
- Subtask 2 (30 points): and is even; ; ; for every valid position; every operation has and ; for , ; for , .
- Subtask 3 (50 points): and is even; ; ; for every valid position; every operation has and ; for , ; for , .
Examples
Input
4 2 2
5 1 4 3
1 2
1 3 3
2 1 5
Output
10
13
Explanation
After the first assignment 1 3 3, we have and . Initially . Inserting produces . Its third element is the median ; removing one copy gives . Inserting produces ; remove the median to obtain . The sum is .
The second assignment 2 1 5 changes to , leaving unchanged. Starting again at , insert and remove median to get . Insert to get ; remove median , leaving . The final sum is . These two results are printed on separate lines.