ACM 赛制目前常用板子
Bronya18C
·
·
个人记录
快读快写(非fread)
inline int read(){
int x = 0, t = 1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
t=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*t;
}
inline void write(int x)
{
if(x<0){
putchar('-');
x=-x;
}
if(x>9)
write(x/10);
putchar(x%10+'0');
}
关闭同步流
ios::sync_with_stdio(false);
输出运行时间
fprintf(stderr, "%d ms\n", int(1e3 * clock() / CLOCKS_PER_SEC));
组合计数板子
const int mo=1000000007;
const int N=1000000;
int fact[N+5],ifact[N+5];
int fast_pow(int a,int p){
int sum=1;
while(p){
if(p&1)sum=1ll*sum*a%mo;
a=1ll*a*a%mo;
p>>=1;
}
return sum;
}
int add(int u,int v){
return (u+v>=mo?u+v-mo:u+v);
}
int C(int u,int v){
if(u<v)return 0;
return 1ll*fact[u]*ifact[v]%mo*1ll*ifact[u-v]%mo;
}
void Init(){
fact[0]=1;
for(int i=1;i<=N;i++)fact[i]=1ll*fact[i-1]*i%mo;
ifact[N]=fast_pow(fact[N],mo-2);
for(int i=N-1;i>=0;i--)ifact[i]=ifact[i+1]*1ll*(i+1)%mo;
}
SAM
struct SAM{
int last;
int son[26];
int siz;
int cnt;
}t[2000005];
int g,now;
void Insert(int u,int c){
int v=++g;
t[v].siz=t[u].siz+1;t[v].cnt=1;
now=v;
int p=u;
while(p!=-1 && !t[p].son[c]){
t[p].son[c]=v;
p=t[p].last;
}
if(p==-1)t[v].last=0;
else {
int q=t[p].son[c];
if(t[p].siz+1==t[q].siz){
t[v].last=q;
}
else {
int copy=++g;
t[copy].siz=t[p].siz+1;
for(int i=0;i<26;i++)t[copy].son[i]=t[q].son[i];
t[copy].last=t[q].last;
while(p!=-1 && t[p].son[c]==q){
t[p].son[c]=copy;
p=t[p].last;
}
t[q].last=t[v].last=copy;
}
}
}
void Init(){
for(int i=0;i<=g;i++){
for(int j=0;j<26;j++)
t[i].son[j]=0;
t[i].cnt=0;
}
t[0].last=-1;now=0;g=0;
}
超快的 O(\sqrt{n})-O(1) 分块(by yaoxi)
namespace bs {
int bn, blk, st[505], ed[505], bel[200005];
struct blocking {
long long sum[200005], bsum[505];
void init() {
fill(sum + 1, sum + n + 1, 0);
fill(bsum + 1, bsum + bn + 1, 0);
}
void update(int p, long long v) {
if (p > n) return;
for (int i = p; i <= ed[bel[p]]; ++i) sum[i] += v;
for (int i = bel[p]; i <= bn; ++i) bsum[i] += v;
}
long long query(int p) const {
if (!p) return 0;
return sum[p] + bsum[bel[p] - 1];
}
} b1, b2;
void init() {
blk = sqrt(n) + 1, bn = 0;
for (int l = 1; l <= n; l += blk) {
int r = min(n, l + blk - 1);
++bn, st[bn] = l, ed[bn] = r;
fill(bel + l, bel + r + 1, bn);
}
b1.init(), b2.init();
}
void update(int p, long long v) {
b1.update(p, v), b2.update(p, p * v);
}
void update(int l, int r, long long v) {
update(l, v), update(r + 1, -v);
}
long long query(int p) {
return (p + 1) * b1.query(p) - b2.query(p);
}
long long query(int l, int r) {
return query(r) - query(l - 1);
}
}
Hash
#include<bits/stdc++.h>
using namespace std;
const int N=2000000;
const int mo=998244353,mo2=1000000007;
const int bas=19260817;
pair<int,int> pw[N+5];
pair<int,int> add(pair<int,int>A,pair<int,int>B){
return make_pair((A.first+B.first)%mo,(A.second+B.second)%mo2);
}
pair<int,int> del(pair<int,int>A,pair<int,int>B){
return make_pair((A.first-B.first+mo)%mo,(A.second-B.second+mo2)%mo2);
}
pair<int,int> mul(pair<int,int>A,pair<int,int> B){
return make_pair(1ll*A.first*B.first%mo,1ll*A.second*B.second%mo2);
}
void Init(){
pw[0]=make_pair(1,1);
for(int i=1;i<=N;i++)pw[i]=mul(pw[i-1],make_pair(bas,bas));
}
int main(){
return 0;
}