PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000035. Tổng các phần tử ở vị trí 3, 8, 13, ... (Sum of Medians)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng các phần tử ở vị trí 3, 8, 13, ... (Sum of Medians)
Sum of Medians
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Maintain a set of distinct positive integers. If the current sorted set is , a sum query asks for , summing all positions such that . Operation add x inserts a value not currently present. Operation del x removes a value that is present. An empty set has sum .
Input
The first line contains . Each subsequent line is add x, del x, or sum.
Output
For each sum operation, print the requested sum.
Subtasks
- Subtask 1 (20 points): ; ; each
addinserts an absent value, and eachdelremoves a present value. - Subtask 2 (30 points): ; ; each
addinserts an absent value, and eachdelremoves a present value. - Subtask 3 (50 points): ; ; each
addinserts an absent value, and eachdelremoves a present value.
Examples
Input
6
add 4
add 5
add 1
add 2
add 3
sum
Output
3
Explanation
The sorted set is [1,2,3,4,5], so only the third element is included.