C.cpp 527 B

123456789101112131415161718192021222324252627282930313233
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. ios::sync_with_stdio(false);
  5. deque<int> a;
  6. int q;
  7. cin >> q;
  8. while (q--) {
  9. int op;
  10. cin >> op;
  11. if (op == 0) {
  12. int d, x;
  13. cin >> d >> x;
  14. if (d == 0)
  15. a.push_front(x);
  16. else
  17. a.push_back(x);
  18. } else if (op == 1) {
  19. int p;
  20. cin >> p;
  21. cout << a[p] << endl;
  22. } else {
  23. int d;
  24. cin >> d;
  25. if (d == 0)
  26. a.pop_front();
  27. else
  28. a.pop_back();
  29. }
  30. }
  31. return 0;
  32. }