带翻转标记的双端队列
(听说双端队列用stl的话容易被卡常,还是记一下手写的比较好)
const int MAXN=1e5+10;
struct deQue
{
int buffer[MAXN*2];
int head=MAXN,tail=MAXN-1;
bool rev; //翻转标记
bool empty()
{
return tail<head;
}
int size()
{
return tail-head+1;
}
int front()
{
return rev?buffer[tail]:buffer[head];
}
int back()
{
return rev?buffer[head]:buffer[tail];
}
void push_front(int x)
{
rev?buffer[++tail]=x:buffer[--head]=x;
}
void push_back(int x)
{
rev?buffer[--head]=x:buffer[++tail]=x;
}
void pop_back()
{
rev?head++:tail--;
}
void pop_front()
{
rev?tail--:head++;
}
void reverse()
{
rev^=1;
}
}q;