MLE 求助
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
int n, a, x;
string s;
deque<int> q[N];
int main() {
scanf("%d", &n);
while(n--) {
cin >> s;
scanf("%d", &a);
if(s == "push_back") {
scanf("%d", &x);
q[a].push_back(x);
} else if(s == "pop_back") {
if(q[a].empty()) continue;
q[a].pop_back();
} else if(s == "push_front") {
scanf("%d", &x);
q[a].push_front(x);
} else if(s == "pop_front") {
if(q[a].empty()) continue;
q[a].pop_front();
} else if(s == "size") {
printf("%d\n", q[a].size());
} else if(s == "front") {
if(q[a].empty()) continue;
printf("%d\n", q[a].front());
} else {
if(q[a].empty()) continue;
printf("%d\n", q[a].back());
}
}
return 0;
}