板子合集
程序员文章站
2022-05-29 09:02:57
...
个人偏好的宏定义:
#define MN 200005
#define LL long long
#define mp make_pair
#define fir first
#define sec second
#define pii pair<int,int>
inline void chkmax(int &a,int b){if(a<b)a=b;}
inline void chkmin(int &a,int b){if(a>b)a=b;}
快读:
inline int read(){
int a=0,fh=1;char c=getchar();
while(c>'9'||c<'0'){if(c=='-')fh=-1;c=getchar();}
while('0'<=c&&c<='9'){
a=a*10+c-48;
c=getchar();
}
return a*fh;
}
快速幂:
int ksm(int a,int x){
LL ans=1,w=a;
while(x){
if(x&1)ans=ans*w%Mod;
x>>=1;
w=w*w%Mod;
}
return ans;
}
组合数:
LL fac[MN],dfac[MN];
void C_init(int N){
fac[0]=1;for(int i=1;i<=N;++i)fac[i]=fac[i-1]*i%Mod;
dfac[n]=ksm(fac[n],Mod-2);for(int i=N-1;i>=0;--i)dfac[i]=dfac[i+1]*(i+1)%Mod;
}
int C(int n,int m){
if(m<n)return 0;
return fac[m]*dfac[n]%Mod*dfac[m-n]%Mod;
}
手打哈希表(不会封装.jpg
const int MD=(1<<18)-1,Mod=30007,Maxn=50005;
//maxn: 表里最多多少数
struct Hash{
int head[Mod],nex[Maxn];
LL val[Maxn];
int cnt;
vector<int>loc;
bool vis[Mod];
void ADD(int x,LL y){
cnt++;
nex[cnt]=head[x];
val[cnt]=y;
head[x]=cnt;
}
bool insert(LL a){
int v=(a&MD)%Mod;
for(int i=head[v];i;i=nex[i])
if(val[i]==a)return 0;
ADD(v,a);
if(!vis[v])loc.push_back(v),vis[v]=1;
return 1;
}
void clear(){
cnt=0;
for(int i=0;i<loc.size();++i)vis[loc[i]]=0,head[loc[i]]=0;
loc.clear();
}
}
刚开始搞,有些是手打的,出错概不负责/kel