-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.cpp
More file actions
executable file
·93 lines (78 loc) · 1.5 KB
/
Copy pathsol.cpp
File metadata and controls
executable file
·93 lines (78 loc) · 1.5 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <bits/stdc++.h>
using namespace std;
int SIZE = 1000000;
struct teque
{
list<int> L;
list<int>::iterator middle;
void push_front(int n)
{
L.push_front(n);
if (L.size() == 1)
middle = L.begin();
else
{
if (L.size() % 2 == 1)
middle++;
}
}
void push_back(int n)
{
L.push_back(n);
if (L.size() == 1)
middle = L.begin();
else
{
if (L.size() % 2 == 0)
middle--;
}
}
void push_middle(int n)
{
if (L.size() == 0)
{
L.push_front(n);
middle = L.begin();
}
else
{
middle = L.insert(middle, n);
if (L.size() % 2 == 1)
++middle;
}
}
int get(int i)
{
auto it = L.begin();
advance(it, i);
return *it;
}
};
ostream &operator<<(ostream &os, const list<int> &L)
{
for (auto each : L)
os << " " << each;
return os;
}
int main()
{
int n;
cin >> n;
teque T;
for (int i = 0; i < n; ++i)
{
string op;
int n;
cin >> op >> n;
if (op == "push_back")
T.push_back(n);
else if (op == "push_middle")
T.push_middle(n);
else if (op == "push_front")
T.push_front(n);
else
cout << T.get(n) << endl;
cout << T.L << endl;
}
return 0;
}