# | Problem | Pass Rate (passed user / total user) |
---|---|---|
14253 | 2024_IDS_Spring_Assignment1_Undo_Calculator |
|
14255 | 2024_IDS_Spring_Assignment1_Game |
|
14256 | 2024_IDS_Spring_Assignment1_Baganono Tuple |
|
Description
You have a magical calculator that can undo operations you don't want. This calculator supports the following three operations:
- + x: Add x to the current result.
- - x: Subtract x from the current result.
- Undo: Undo the previous addition or subtraction operation. If there was no previous addition or subtraction, no action is taken.
please ouput the result of the calculator after n operation.
The calculator starts the calculation from 0.
Input
the first line contain one integer n.
the next n lines, each line contain one of the 3 operations.
- 1 ≤ n ≤ 2 * 106
- 1 ≤ x ≤ 100
Output
Output the result of the calculator.
Remember to print a ‘\n’ at the end of the output.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
TA Penguin07 wants to play a game with N people. Initially, these N people are lined up and numbered from 1 to N.
TA Penguin07 will issue K commands, commands i is represented as a pair of integers (Ti, Ai, Bi), and is the following operation:
- If Ti = 1, the person with number Ai have to kill min(C, Bi) people behind them. Here, C represents the number of people remaining behind them at the moment of the command.
- If Ti = 2, the person with number Ai have to kill min(C, Bi) people in front of them. In this case, C represents the number of people remaining in front of them at the moment of the command.
However, Penguin07 has poor eyesight and cannot clearly see who has been killed from the long line. So, after each command issued by Penguin07, you need to tell Penguin07 who was killed.
If the command is invalid (that person has already been killed or there is no one been killed), you should output "Penguin07 QQ" (with no quotes).
Input
The first line contains two positive integers, N and K.
The following K lines, each line represents a command in the format of three integers: (Ti, Ai, Bi).
Constraints
- Testcases 1 ~ 4: Ti = 1, Bi = 1
- Testcases 5 ~ 6: satisfy no additional constraints.
- For all test cases: 1 ≤ N, K ≤ 2 * 106, 1 ≤ Ti ≤ 2, 1 ≤ Bi ≤ 109, 1 ≤ Ai ≤ N
Output
Remember to print a ‘\n’ at the end of the output.
Do not include any spaces at the end of line.
Hint
The test data for this problem is quite large, so if you're using C++ to solve it should include IO optimization in your program.
IO Optimization usage
remember to replace endl with '\n'.
#include<iostream>
...
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
/* write your code here*/
}
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Input
The first line contains an integer n, being the size of array. The second line contains n integer a1, a2, ... , an, being the elements of array a.
Constraints
- For testcases 1 to 3, 1 ≤ n ≤ 100
- For testcase 4 to 6, 1 ≤ n ≤ 3000
- For testcases 7 to 10, 1 ≤ n ≤ 106
- For all the testcases, 1 ≤ ai ≤ n, ∀ 1 ≤ i ≤ n, and all the elements in a are distinct
Output
Output the total number of tuple described in the description.
Remember to print a ‘\n’ at the end of the output.