跳到正文

剪贴板

剪贴板 fp8wjbrg

原文
剪贴板信息

剪贴板信息

收录
更新

模版合集

基本

C++
#include <bits/stdc++.h>
#define crazy ""
//#define int long long
using namespace std;
int n;
//long long lty = 998244353;
signed main(){
   scanf("%d",&n);
   return 0;
}

快速幂

C++
long long qp(long long x,long long y){
	long long r = 1;
	while(y){
		if(y & 1) r = r * x % lty;
		x = x * x % lty;
		y >>= 1;
	}
	return r;
}

链式前向星

C++
struct e{
	int nx;
	int to;
} es[100005];
int h[100005];
int cnt;
inline void insert(int x,int y){
	cnt++;
	es[cnt].to = y;
	es[cnt].nx = h[x];
	h[x] = cnt;
}
inline void ins(int x,int y){
	insert(x,y);
	insert(y,x);
}

矩阵快速幂

C++
int n;
long long lty = 1000000007;
long long res[105][105];
long long r[105][105];
void mul(long long x[105][105],long long y[105][105]){
	memset(res,0,sizeof(res));
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			for(int k = 1;k <= n;k++){
				res[i][k] += x[i][j] * y[j][k] % lty;
				res[i][k] %= lty;
			}
		}
	}
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			x[i][j] = res[i][j];
		}
	}
}
void qp(long long x[105][105],long long y){
	for(int i = 1;i <= n;i++) r[i][i] = 1;
	while(y){
		if(y & 1) mul(r,x);
		mul(x,x);
		y >>= 1;
	}
}

左偏树

C++
#include <bits/stdc++.h>
using namespace std;
int lc[100005];
int rc[100005];
bool vis[100005];
struct lty{
	int v,id;
	bool operator< (lty x) const{
		if(x.v != v) return v < x.v;
		return id < x.id;
	}
} a[100005];
int ds[100005];
int sz[100005];
int fa[100005];
int fd(int x){
	if(x == fa[x]) return x;
	return fa[x] = fd(fa[x]);
}
int n,m;
int mg(int x,int y){
	if(!x) return y;
	if(!y) return x;
	if(a[y] < a[x]) swap(x,y);
	rc[x] = mg(rc[x],y);
	if(!lc[x] || ds[lc[x]] < ds[rc[x]]) swap(lc[x],rc[x]);
	ds[x] = ds[rc[x]] + 1;
	return x;
}