406102: GYM102267 G Diet

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. Diettime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Dr. Diet has a special process. He has $$$n$$$ rooms in each room he has a patient. Each patient can be characterized by two numbers $$$a_i$$$ and $$$b_i$$$. Each day a stupid robot carrying food goes through the rooms starting from the first room. At the room of the $$$i_{th}$$$ patient if the value $$$a_i$$$ is greater than the amount of available food then the robot stops and returns to the charging mount, otherwise, the robot gives the patient $$$a_i$$$ food and continues on to the next patient. If the patient sees more than $$$b_i$$$ food with the robot after taking $$$a_i$$$ food he gets a stroke and dies.

At the end of the day the doctor checks on the patients and reports how many didn't get food and how many died.

He then updates the robot so that it stops giving food to the rooms with dead patients. The doctor is getting old so he came to you to ask for your help.

He needs you to answer two queries:

1) $$$1 $$$ $$$x $$$ the robot was given $$$x$$$ food you need to tell him how many patients died and how many didn't receive food.

2) $$$2$$$ $$$a$$$ $$$b$$$ $$$c $$$ the doctor got a new patient with values $$$a$$$ and $$$b$$$ the patient is given room $$$c$$$. If the room contains a dead patient then he gets thrown out and the new one gets the room otherwise, the old patient gets released and the new patient takes his place.

Input

The first line contains a single integer $$$n $$$ $$$(1 \le n \le 10^5)$$$, the number of rooms.

Each of the next $$$n$$$ lines contains two integers $$$a_i $$$ and $$$b_i $$$ $$$(1\le a_i\le 10^9,1\le b_i\le 10^{18})$$$, the amount of food the patients demands and the amount he can see without getting a stroke,respectively.

The next line contains a single integer $$$q $$$ $$$(1\le q\le 10^5)$$$, the number of queries;

The next $$$q$$$ lines contain the description of the queries:

1) $$$1 $$$ $$$x $$$ $$$(1\le x\le 10^{18}) $$$, $$$1 $$$ represents the first query and $$$x $$$ represents the amount of food the robot carries.

2) $$$2 $$$ $$$a $$$ $$$b $$$ $$$c $$$ $$$(1\le a\le 10^9,1\le b\le 10^{18},1\le c\le n)$$$, $$$2 $$$ represents the second query the values $$$a,b,c$$$ describe the new patient where $$$a$$$ is the amount of food the patient requires, $$$b$$$ is the amount of food the patient can see safely and finally $$$c$$$ is the index of the room the patient is going to use.

Output

For each query of the first type print two integers $$$a$$$ and $$$b$$$. Where $$$a$$$ is the number of patients who died and $$$b$$$ is the number of patients who didn't receive food.

ExamplesInput
5
1 10
5 12
103 70
1 1
5 3
4
1 400
2 3 13 3
2 5 3 1
1 3
Output
5 0
0 2
Input
3
1 2
2 3
3 4
5
1 6
1 13
2 1 1 1
2 2 4 2
1 20
Output
1 0
2 0
2 0

加入题单

上一题 下一题 算法标签: