| Contests - ACM Student Chapter - PSUT |
|---|
| Private |
| Spectator |
| PSUT Programming Contest 2026 |
|---|
| Finished |
Kilani gave Moon his least favorite data structure: a stack with a maximum capacity of $$$L$$$. Moon can perform the following two operations:
You are given a sequence of $$$n$$$ operations, each of which is either type $$$1$$$ (Push) or type $$$2$$$ (Pop).
Then, you are given $$$q$$$ queries. In each query, you are given three integers $$$l$$$, $$$i$$$, and $$$k$$$.
For each query, consider a stack with capacity $$$l$$$, and apply only the first $$$i$$$ operations from the given sequence. After performing these operations, determine the value of the $$$k$$$th element in the stack (counted from the bottom, i.e., the bottom element is the first element).
If $$$k$$$ is greater than the current number of elements in the stack, print $$$-1$$$.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
For each test case:
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$, and the sum of $$$q$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.
For each test case, output $$$q$$$ lines.
For each query, print a single integer — the value of the $$$k$$$th element in the stack after applying the first $$$i$$$ operations on a stack with capacity limit $$$l$$$.
If the stack contains fewer than $$$k$$$ elements after these operations, print $$$-1$$$.
15 2push 5push 2poppush 4pop1 5 12 5 1
-15
| Name |
|---|

