123456789101112131415161718192021222324252627282930313233 |
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios::sync_with_stdio(false);
- deque<int> a;
- int q;
- cin >> q;
- while (q--) {
- int op;
- cin >> op;
- if (op == 0) {
- int d, x;
- cin >> d >> x;
- if (d == 0)
- a.push_front(x);
- else
- a.push_back(x);
- } else if (op == 1) {
- int p;
- cin >> p;
- cout << a[p] << endl;
- } else {
- int d;
- cin >> d;
- if (d == 0)
- a.pop_front();
- else
- a.pop_back();
- }
- }
- return 0;
- }
|