lyc的板子

弃用了(

欢迎大家使用 Template-Generator

线段树

结构体封装,支持区间加/区间求和/区间最值

struct Segment_Tree{
	const int INF=0x3f3f3f3f;
	struct node{
		int l,r,len;
		int add,v,mn;
	}st[MAXN*4];
	
	void build(int p,int l,int r){
		st[p].l=l;st[p].r=r;
		st[p].len=r-l+1;
		if (l==r){
			st[p].v=a[l];
			st[p].mn=a[l];
			return;
		}
		int mid=l+r>>1;
		build(p<<1,l,mid);
		build(p<<1|1,mid+1,r);
		st[p].v=st[p<<1].v+st[p<<1|1].v;
		st[p].mn=min(st[p<<1].mn,st[p<<1|1].mn);
	}

	void spread(int p){
		st[p<<1].v+=st[p].add*st[p<<1].len;
		st[p<<1|1].v+=st[p].add*st[p<<1|1].len;
		st[p<<1].add+=st[p].add;
		st[p<<1|1].add+=st[p].add;
		st[p<<1].mn+=st[p].add;
		st[p<<1|1].mn+=st[p].add;
		st[p].add=0;
	}

	void change(int p,int l,int r,int c){
		if (l<=st[p].l&&st[p].r<=r){
			st[p].v+=c*st[p].len;
			st[p].add+=c;
			st[p].mn+=c;
			return;
		}
		spread(p);
		int mid=st[p].l+st[p].r>>1;
		if (l<=mid) change(p<<1,l,r,c);
		if (r>mid) change(p<<1|1,l,r,c);
		st[p].v=st[p<<1].v+st[p<<1|1].v;
		st[p].mn=min(st[p<<1].mn,st[p<<1|1].mn);
	}

	int query_sum(int p,int l,int r){
		if (l<=st[p].l&&st[p].r<=r)
			return st[p].v;
		spread(p);
		int mid=st[p].l+st[p].r>>1,ans=0;
		if (l<=mid) ans+=query_sum(p<<1,l,r);
		if (r>mid) ans+=query_sum(p<<1|1,l,r);
		return ans;
	}

	int query_min(int p,int l,int r){
		if (l<=st[p].l && st[p].r<=r)
			return st[p].mn;
		spread(p);
		int mid=st[p].l+st[p].r>>1,ans=INF;
		if (l<=mid) ans=query_min(p<<1,l,r);
		if (r>mid) ans=min(ans,query_min(p<<1|1,l,r));
		return ans;
	}
};

Dinic

const int INF=1e9+7;
const int MAXN=10005;
const int MAXM=100005;
int n,m,s,t;
int Index=0;
int w[MAXM*2];
vector<int> v[MAXN];
int point[MAXM*2];
int label[MAXN];
int cur[MAXN*2];

void add_edge(int x,int y,int f){
	v[x].push_back((++Index)*2);
	v[y].push_back(Index*2+1);
	w[Index*2]=f;
	w[Index*2+1]=0;
	point[Index*2]=y;
	point[Index*2+1]=x;
}

bool bfs(){
	memset(label,0,sizeof(label));
	memset(cur,0,sizeof(cur));
	queue<int> q;
	q.push(s);
	label[s]=1;
	while (!q.empty()){
		int now=q.front();
		q.pop();
		for (int i=0;i<v[now].size();i++){
			int edge=v[now][i];
			int u=point[edge];
			if (!label[u] && w[edge]){
				label[u]=label[now]+1;
				q.push(u);
			}
		}
	}

	return label[t]!=0;
}

int dfs(int p,int limit){
	if (limit==0||p==t) return limit;

	int used=0;
	for (int i=cur[p];i<v[p].size();i++){
		cur[p]=i;
		int edge=v[p][i];
		int u=point[edge];
		if (w[edge] && label[p]+1==label[u]){
			int flow=dfs(u,min(limit-used,w[edge]));
			used+=flow;
			w[edge]-=flow;
			w[edge^1]+=flow;
			if (used==limit) break;
		}
	}

	return used;
}

int dinic(){
	int ans=0;
	while (bfs())
		ans+=dfs(s,INF);
	return ans;
}

快速幂

int ksm(int x,int y){
    int ans=1;
    while (y>0){
        if (y%2==0){
            y/=2;
            x*=x;
        }
        ans*=x;
        y--;
    }
    return ans;
}

树状数组

结构体封装,支持单点修改,区间查询

struct BIT{
	int tree[MAXN];

	inline int lowbit(int x){
	    return x&(-x);
	}

	inline void add(int x,int c){
		while (x<=n+1){
			tree[x]+=c;
			x+=lowbit(x);
		}
	}

	inline int query1(int x){
		int ans=0;
		while (x>0){
			ans+=tree[x];
			x-=lowbit(x);
		}
		return ans;
	}

	inline int query2(int l,int r){
		return query1(r)-query1(l-1);
	}
};

对拍

批处理脚本,使用方法 duipai.bat [你的代码的文件名] [std代码文件名] [数据生成器文件名]

@echo off
del mine.exe
del std.exe
del datamaker.exe
g++ -o mine.exe %1
g++ -o std.exe %2
g++ -o datamaker.exe %3
echo OK
pause
:start
	datamaker.exe>data.txt
	mine.exe<data.txt>mine.txt
	std.exe<data.txt>std.txt
	fc std.txt mine.txt
if not errorlevel 1 goto start
pause

快读

int read(){
    int x=0,f=1;
    char ch;
    while(ch<'0'||ch>'9')  {if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return f*x;
}