Under construction

Still being built. Things may change

Bank Queue

Interview

Time limit2sMemory limit1024 MB

Summary
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, nn 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 ii-th person as a non-negative integer aia_i. A person is in a good mood if their mood is at least xx, 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 nn and xx (1≤n≤100 0001 \le n \le 100\,000, 0≤x≤1090 \le x \le 10^9): the initial number of people in the queue and the lower bound for a good mood.

The second line contains nn integers aia_i (0≤ai≤1090 \le a_i \le 10^9), the moods of the people in the queue.

The third line contains mm (1≤m≤100 0001 \le m \le 100\,000), the number of events. Each of the next mm lines is one of the following:

1 aa (0≤a≤1090 \le a \le 10^9): a person with mood aa 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 ii: Scrooge asks how many people in good mood stand in front of the person who has exactly ii 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, ii 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.

Examples2

  1. Example 1

    Input
    1 2
    3
    5
    1 2
    1 1
    3 0
    3 1
    3 2
    
    Expected output
    0
    1
    2
    
  2. Example 2

    Input
    2 2
    1 2
    7
    3 0
    3 1
    2
    3 0
    1 3
    3 0
    3 1
    
    Expected output
    0
    0
    0
    0
    1