提交时间:2026-06-17 06:34:53

运行 ID: 91810

#include <iostream> #include <deque> using namespace std; int main() { // 加速cin、cout,处理大量数据更快 ios::sync_with_stdio(false); cin.tie(0); int Q; cin >> Q; deque<int> cards; for (int i = 0; i < Q; ++i) { int t, x; cin >> t >> x; if (t == 1) { // 放到最上面 = 队头插入 cards.push_front(x); } else if (t == 2) { // 放到最下面 = 队尾插入 cards.push_back(x); } else if (t == 3) { // 从上第x张,下标x-1 cout << cards[x - 1] << '\n'; } } return 0; }