report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
A lot of queries - FlandreOJ: Flandre Online Judge

A lot of queries

Time limit: 1000 ms
Memory limit: 256 MB
For an empty set $S$, given $q$ queries, where each query is an integer $x$: - `1 x a`: Insert $a$ elements with value $x$ into the set. - `2 x b`: Remove $b$ elements with value $x$ from the set. If the number of elements with value $x$ in the set is less than $b$, remove all elements with value $x$. - `3`: Find the minimum value in the set. - `4`: Find the maximum value in the set. - `5 y`: Let $x$ be the maximum value less than $y$ in the set, and $z$ be the minimum value greater than $y$ in the set. Calculate the sum of elements with values $x$ or $y$ or $z$. If there is no satisfied $x,y$ or $z$, you can ignore them. The set $S$ may contain multiple elements with the same value. ### Input - The first line contains an integer $q$. - The next $q$ lines, each containing a query in the specified format. ### Output - For each query of types $3,4,5$, print an integer as the answer. ### Constraints - $1 \le q \le 10^5$. - $1 \le x, a, b, y \le 10^6$. ### Example Input ``` 8 1 1 3 1 2 2 5 1 3 2 1 2 1 3 4 4 5 2 ``` Output: ``` 7 1 3 17 ```
Containers C++ in Standard Template Library (STL)
k-th element
Dynamic prefix sum
Unammed
k-th occurence
Set
Most frequent value
A lot of queries
Median
Houses
Picking flowers
Topic
STL
Rating 1100
Solution (0) Solution