-
Notifications
You must be signed in to change notification settings - Fork 0
/
cau_truc_du_lieu_hang_doi_1.cpp
53 lines (53 loc) · 1.22 KB
/
cau_truc_du_lieu_hang_doi_1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
int n, x;
cin >> n;
deque<int> st;
while (n--)
{
cin >> x;
if (x == 1)
cout << st.size() << endl;
else if (x == 2)
{
if (st.empty())
cout << "YES" << endl;
else
cout << "NO" << endl;
}
else if (x == 3)
{
cin >> x;
st.push_back(x);
}
else if (x == 4)
{
if (st.size())
st.pop_front();
}
else if (x == 5)
{
if (st.size())
cout << st.front() << endl;
else
cout << -1 << endl;
}
else if (x == 6)
{
if (st.size())
cout << st.back() << endl;
else
cout << -1 << endl;
}
}
}
}