Page not loading? Try clicking here.
Placeholder

#8074

Tutorial : STL Queue 1s 512MB

Problems

This time, let's learn about STL Queue.

The way to declare a Queue is as follows.


#include <queue>
using namespace std;

queue <int> q;

In the code above, <int> refers to the data type to be stored in the queue, and q is the name of that queue. (The queue name can be set freely)

That is, in this example, q becomes a queue that stores int.

※ In actual problems, queues are often used to store structures.

In this problem, we will practice storing structures in a queue.

struct Data{
    int x, y, z;
};

queue <Data> qq;

Data is a structure that stores (x-coordinate, y-coordinate, z-coordinate), and qq is a queue that can store Data structures.

Now, let's take a serious look at the functions of STL Queue.


Function 1: empty()

Usage example: if ( qq.empty() == true )...

Just like STL Stack, STL Queue also has an empty() function.

It returns true if it's empty, and false if it's not.


Function 2: push()

Usage example: qq.push( { 1, 2, 4 } );

The push() function is a function that inserts an element at the very back of the queue.

If you put { 1, 2, 4 } into the push() function as in the code above, a Data structure with ( x = 1, y = 2, z = 4 ) is inserted into qq.

(Be sure to put it in { curly braces }, in the order of the variables declared in the structure!)


Function 3: pop()

Usage example: qq.pop();

The pop() function is a function that deletes the front element (front) of the queue.

It only deletes it and does not inform you of the deleted element.

Just like STL Stack, calling pop() when the queue is empty will result in a runtime error. (Be sure to check if it's empty first through the empty() function.)


Function 4: front()

Usage example: Data f = qq.front(); or if ( qq.front().y == 2 ) ...

The front() function is a function that tells you the value of the front element (front) of the queue. (It only tells the value and does not delete it.)

In the code above, qq was a queue containing Data structures.

Therefore, since qq.front() will return a Data structure, we declared Data f to store it.

You can find the x, y, and z values of f through f.x, f.y, and f.z.

Alternatively, you could use variable decomposition in auto syntax like

auto [x, y, z] = f.front();.

The front() function also causes a runtime error if called when the queue is empty. (Be sure to check if it's empty first through the empty() function.)


Function 5: size()

Usage example: if ( qq.size() == 0 ) ... or int s = qq.size();

The size() function, like STL Stack, tells you the number of elements in the queue.

If the queue is empty, the size() function will return 0.


Now, let's solve the problem below using the 5 functions above.

<Processing Conditions>

The given commands are the following 4 types.

Command 1: "i x y z" inserts the (x, y, z) structure into the queue. x, y, and z are all integers within the int range.

Command 2: "o" deletes the front structure of the queue and then outputs the x, y, and z values of that structure separated by spaces.

If the queue was empty, output "empty".

Command 3: "c" outputs the number of structures contained in the queue.

Command 4: "z a" outputs whether the z value of the front structure of the queue matches the integer a.

If it matches, output "yes"; if the queue was empty or it does not match, output "no".


Input

The first line contains N. N is the number of commands given. (1≤N≤10,000)

From the second line to the (N+1)-th line, N commands are given, one per line.


Output

Print the output values for commands that require output, one per line.

Cases where there is no output content will not be provided.


Example

18
o
z 36901969
c
i 42323453 57112519 4814100
i 4643856 67128971 42927065
z 4814100
c
z 4814100
o
z 75068631
c
z 42927065
z 93403458
z 30337753
i 14399968 2553408 64342658
o
i 4062724 80834965 31516244
c
empty
no
0
yes
2
yes
42323453 57112519 4814100
no
1
yes
no
no
4643856 67128971 42927065
2



Source

againalgo

You must sign in to write code.