410658: GYM104069 J Journey through time
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
J. Journey through timetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output
Noronha loves games and time travel, therefore, he created a game where you have to answer queries about the present and also about the past! He is a professional in this game and decided to play with you. Given a set initially empty, you must do one of the following operations:
- Add an element $$$x$$$ to the set;
- Say the biggest element in the set after operation $$$t$$$;
- Say the smallest element in the set after operation $$$t$$$;
- Say the sum of the elements in the set after operation $$$t$$$.
Since you are smart (and lazy), you decided to write a program that plays the game for you.
InputThe first line contains an integer $$$n$$$ $$$(1 \leq n \leq 10^5)$$$, the total number of operations.
The next $$$n$$$ lines describe the operations made. Each one of these lines represents an operation as follows
- "1 $$$x$$$" you have to add the element $$$x$$$ $$$(1 \leq x \leq 10^9)$$$ to the set;
- "2 $$$t$$$" you must say the biggest element in the set after operation $$$t$$$ $$$(1 \leq t \leq n-1)$$$;
- "3 $$$t$$$" you must say the smallest element in the set after operation $$$t$$$ $$$(1 \leq t \leq n-1)$$$;
- "4 $$$t$$$" you must say the sum of the elements in the set after operation $$$t$$$ $$$(1 \leq t \leq n-1)$$$.
For each operation of type $$$2$$$,$$$3$$$ or $$$4$$$, print the the operation's answer.
ExamplesInput7 1 10 2 1 2 2 3 2 4 2 1 5 2 6Output
10 10 10 10 10Input
2 1 3 4 1Output
3Input
6 1 1 1 10 2 2 3 3 4 4 4 1Output
10 1 11 1