Bank Queue
InterviewTime limit2sMemory limit1024 MB
Given a queue with joins, front departures, and queries, count the people in good mood (mood at least x) standing in front of a given person.
- Level
Medium4 of 10
- Topics
- Array, Prefix sum
- Solved
- No attempts yet
Statement
Scrooge recently took a job as a guard at a bank. The work is dull, so he started watching the queue. At the start, people stand in line. Scrooge spent several years as a psychologist, so he can judge each person's mood quite accurately. He numbers people from the front starting at 0, so a person's number equals the count of people standing in front of them. He writes the mood of the -th person as a non-negative integer . A person is in a good mood if their mood is at least , and in a bad mood otherwise.
People join the queue and leave it. When a new person joins, Scrooge judges their mood right away, and it does not change over time.
Scrooge has a new hobby. At certain moments he picks one person in the queue and counts how many people in good mood stand in front of that person. He finds this interesting and wants to automate it. Scrooge is not strong at programming, so he asked you for help. Help him!
Input
The first line contains two integers and (, ): the initial number of people in the queue and the lower bound for a good mood.
The second line contains integers (), the moods of the people in the queue.
The third line contains (), the number of events. Each of the next lines is one of the following:
1 (): a person with mood joins the end of the queue.
2: the person at the front, who has no one in front of them (number 0), leaves. Afterwards Scrooge decreases everyone's number by 1.
3 : Scrooge asks how many people in good mood stand in front of the person who has exactly people in front of them at this moment.
All queries are valid. If the queue is empty, event 2 is not performed. In a type 3 query, is always less than the current size of the queue.
Output
For each query of type 3, print one line with the number of people in good mood who stand in front of the person with the given number.