7K12 blog

猫でも分かる何か

複合コンテナ CompoundContainer

#include <bits/stdc++.h>
using namespace std;

namespace LIB {
	template<class T>class UnSeDeque {
		using ll=long long;
	public:
		deque<T> d;
		unordered_set<T> s;
		UnSeDeque(initializer_list<T> il) { for(auto&e: il) push_back(e); }
		T back() { return d.back(); }
		deque<T>::iterator begin() { return d.begin(); }
		ll size() { return (ll)d.size(); }
		bool find(T x) { return s.find(x)!=s.end(); }
		void insert(deque<T>::iterator p, T x) { d.insert(p,x),s.insert(x); }
		T pop_back() { T t=d.back(); d.pop_back(),s.erase(t); return t; }
		T pop_front() { T t=d.front(); d.pop_front(),s.erase(t); return t; }
		void push_back(T x) { d.push_back(x),s.insert(x); }
		void push_front(T x) { d.push_front(x),s.insert(x); }
		T& operator[](ll i) { return d[i]; }
		T operator[](ll i) const { return d[i]; }
	};
}