Задачи
Деки на 6 мегабайтах
Была интересная задача. А теперь лимит памяти 256 Мб! Можно даже не думая сдать...
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
deque<int> deq[150001];
int m, n, x;
string o;
cin>>m;
for(int i = 0; i < m; i++){
cin>>o>>n;
if(o == "pushfront"){
cin>>x;
deq[n].push_front(x);
}
else if(o == "pushback"){
cin>>x;
deq[n].push_back(x);
}
else if(o == "popfront"){
cout<<deq[n].front()<<endl;
deq[n].pop_front();
}
else{
cout<<deq[n].back()<<endl;
deq[n].pop_back();
}
}
return 0;
}
include <iostream>
include <deque>
include <vector>
include <string>
using namespace std;
const int MAX_DEQUES = 150000;
int main() { ios::syncwithstdio(false); cin.tie(nullptr);
vector<deque<int>> deques(MAX_DEQUES + 1);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
string op;
int a, b;
cin >> op >> a;
if (op == "pushfront") {
cin >> b;
deques[a].push_front(b);
} else if (op == "pushback") {
cin >> b;
deques[a].push_back(b);
} else if (op == "popfront") {
cout << deques[a].front() << endl;
deques[a].pop_front();
} else if (op == "popback") {
cout << deques[a].back() << endl;
deques[a].pop_back();
}
}
return 0;
}