Faucets
Time limit2sMemory limit1024 MB
Each operation changes one faucet's flow or open state, and the task asks for the total open flow after the start and after every operation.
- Level
Easy2 of 10
- Topics
- Implementation, Simulation
- Solved
- No attempts yet
Problem
A water tank is connected to faucets. Each faucet has a screw and a toggle button. Turning the screw adjusts how much water flows out, and pressing the toggle button opens or closes the faucet. The amount of water that enters the tank in one minute is the sum of the water flowing out of the open faucets.
Specifically, you can perform the following operations on a faucet.
- Turn the screw so that the faucet, while open, releases liters of water per minute.
- Press the toggle button. If the faucet is open, it closes. If it is closed, it opens.
At the start, every faucet is open, and the -th faucet releases liters of water per minute. You will perform operations on these faucets. Compute the amount of water that enters the tank in one minute at the start and after each operation.
Input
The first line contains the number of faucets .
The second line contains , the amounts of water released by the faucets at the start, separated by spaces.
The third line contains the number of operations .
From the fourth line, each of the next lines contains one operation in one of the following forms.
1 i xmeans the screw of the -th faucet was turned so that it releases liters of water per minute. ,2 imeans the toggle button of the -th faucet was pressed.
All numbers in the input are integers.
Output
Print lines. The first line is the amount of water that enters the tank in one minute when no operation has been performed, in liters. The -th of the next lines is the amount of water that enters the tank in one minute after the first operations have been performed, in liters.
Hint
Because the input and output are large, using fast I/O is recommended.