跳到正文

剪贴板

剪贴板 12d0l2f0

zhoujiefu
原文
剪贴板信息

剪贴板信息

发布
收录
更新

持续更新中

C++
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
template<typename T>
struct Queue{
	int head,tail;
	T a[N];
	Queue(){head=0,tail=0;}
	bool empty(){return head==tail;}
	int size(){return tail-head;}
	T front(){if(!empty())return a[head];else return -1;}
	T back(){return a[tail-1];}
	void push(T x){a[tail++]=x;}
	void pop(){if(!empty()) head++;else printf("ERR_CANNOT_POP\n");}
	void clear(){head=tail=0;}
};Queue<int>q;

template<typename T>
struct Deque{
	int head,tail;
	T a[N<<1];
	Deque(){head=N,tail=N;}
	bool empty(){return head==tail;}
	int size(){return tail-head;}
	T front(){return a[head];}
	T back(){return a[tail-1];}
	void push_back(T x){a[tail++]=x;}
	void push_front(T x){a[head--]=x;}
	void pop_back(){if(!empty())tail--;else printf("EMPTY back");}
	void pop_front(){if(!empty())head++;else printf("EMPTY front");}
	void clear(){head=tail=N;}
};Deque<int>dq;

template<typename T>
struct Stack{
	int t;
	T a[N];
	Stack(){t=0;}
	bool empty(){return t==0;}
	int size(){return t;}
	T top(){if(!empty())return a[t-1];else return -1;}
	void push(T x){a[t++]=x;}
	void pop(){if(!empty()) t--;else printf("Empty\n");}
	void clear(){t=0;}
};Stack<char>st;
template<typename T>
struct Heap{
	int siz;
	T a[N];
	Heap(){siz=0;}
	T top(){return a[1];}
	bool empty(){return siz==1;}
	int size(){return siz;}
	void push(T x){a[++siz]=x;int now=siz;while(now){int nxt=now>>1;if(a[nxt]>a[now])swap(a[nxt],a[now]);else break;now=nxt;}}
	void pop(){swap(a[siz],a[1]);siz--;int now=1;while((now<<1)<=siz){int nxt=now<<1;if(nxt+1<=siz&&a[nxt+1]<a[nxt])nxt++;if(a[nxt]<a[now])swap(a[now],a[nxt]);else break;now=nxt;}}
};Heap<int>pq;