标签:异或 pen ring row turn cto queue char 初始化
1.头文件
短的:
1 #include<bits/stdc++.h> 2 #define cl(a,b) memset(a,b,sizeof(a)) 3 #define debug(a) cerr<<#a<<"=="<<a<<endl 4 using namespace std; 5 typedef long long ll; 6 typedef pair<int,int> pii; 7 8 const int maxn=1e5+10; 9 10 int main() 11 { 12 13 return 0; 14 }/* 15 16 17 18 */
长的:
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cmath> 5 #include<cstring> 6 #include<string> 7 #include<ctime> 8 #include<map> 9 #include<set> 10 #include<vector> 11 #include<queue> 12 #include<cstdlib> 13 #include<cassert> 14 #include<sstream> 15 #include<stack> 16 #include<list> 17 #include<bitset> 18 #define cl(a,b) memset(a,b,sizeof(a)) 19 #define debug(x) cerr<<#x<<"=="<<(x)<<endl 20 using namespace std; 21 typedef long long ll; 22 typedef long double ldb; 23 typedef pair<int,int> pii; 24 25 const int inf=0x3f3f3f3f; 26 const int maxn=1e9+10; 27 const int mod=1e7+7; 28 const double eps=1e-8; 29 const double pi=acos(-1); 30 31 int dx[8]= {0,0,1,-1,1,-1,1,-1}; 32 int dy[8]= {1,-1,0,0,-1,1,1,-1}; 33 34 ll gcd(ll a,ll b){return a?gcd(b%a,a):b;} 35 ll powmod(ll a,ll x,ll mod){ll t=1;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;} 36 //---------------------------------------ヽ(^。^)丿 37 int main() 38 { 39 40 return 0; 41 } 42 /* 43 44 45 46 */
超神读入挂
1 namespace fastIO { 2 #define BUF_SIZE 100000 3 //fread -> read 4 bool IOerror = 0; 5 inline char nc() { 6 static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE; 7 if(p1 == pend) { 8 p1 = buf; 9 pend = buf + fread(buf, 1, BUF_SIZE, stdin); 10 if(pend == p1) { 11 IOerror = 1; 12 return -1; 13 } 14 } 15 return *p1++; 16 } 17 inline bool blank(char ch) { 18 return ch == ‘ ‘ || ch == ‘\n‘ || ch == ‘\r‘ || ch == ‘\t‘; 19 } 20 inline void read(int &x) { 21 char ch; 22 while(blank(ch = nc())); 23 if(IOerror) 24 return; 25 for(x = ch - ‘0‘; (ch = nc()) >= ‘0‘ && ch <= ‘9‘; x = x * 10 + ch - ‘0‘); 26 } 27 #undef BUF_SIZE 28 }; 29 using namespace fastIO; 30 31 int main() 32 { 33 while(read(n),!fastIO::IOerror) 34 { 35 36 } 37 return 0; 38 }
矩阵快速幂
1 struct matrix 2 { 3 ll a[maxn][maxn]; 4 int row,col; 5 matrix():row(maxn),col(maxn){cl(a,0);} 6 matrix(int x,int y):row(x),col(y){cl(a,0);} 7 void show() 8 { 9 for(int i=0; i<row; i++) 10 { 11 for(int j=0; j<col; j++) 12 { 13 printf("%d%c",a[i][j],j==col-1?‘\n‘:‘ ‘); 14 } 15 } 16 } 17 inline ll* operator [] (int x) 18 { 19 return a[x]; 20 } 21 inline matrix operator * (matrix x) 22 { 23 matrix tmp(row,col); 24 for (int i=0; i<row; i++) 25 for (int j=0; j<col; j++) 26 for (int k=0; k<row; k++) 27 tmp[i][j]=(tmp[i][j]+a[i][k]*x[k][j])%mod; 28 return tmp; 29 } 30 inline void operator *= (matrix x) 31 { 32 *this = *this * x; 33 } 34 matrix operator ^ (ll x) 35 { 36 matrix result(row,col),now=*this; 37 for(int i=0; i<row; i++) 38 { 39 result[i][i]=1; 40 } 41 while(x) 42 { 43 if(x%2) result*=now; 44 now*=now; 45 x/=2; 46 } 47 return result; 48 } 49 };
降维线段树
1 #define ls getid(l,l+r>>1) 2 #define rs getid((l+r>>1)+1,r) 3 #define lson l,m,ls 4 #define rson m+1,r,rs 5 6 typedef long long ll; 7 8 const int maxn = 1e5+10; 9 10 inline int getid(int x,int y) 11 { 12 return x+y|y!=x; 13 } 14 15 ll rm[maxn<<1],col[maxn<<1]; 16 17 void pushup(int l,int r,int rt) 18 { 19 rm[rt]=rm[ls]+rm[rs]; 20 } 21 22 void pushdown(int l,int r,int rt,int k) 23 { 24 if (col[rt]) 25 { 26 col[ls] += col[rt]; 27 col[rs] += col[rt]; 28 rm[ls] += col[rt]*(k-(k>>1)); 29 rm[rs] += col[rt]*(k>>1); 30 col[rt] = 0; 31 } 32 } 33 34 void build(int l,int r,int rt) 35 { 36 if(l == r) 37 { 38 scanf("%I64d",&rm[rt]); 39 return ; 40 } 41 int m=l+r>>1; 42 build(lson); 43 build(rson); 44 pushup(l,r,rt); 45 } 46 47 void update(int L,int R,int c,int l,int r,int rt) 48 {//区间更新 49 if(L<=l && r<=R) 50 { 51 col[rt]+=c; 52 rm[rt]+=c*(r-l+1); 53 return ; 54 } 55 pushdown(l,r,rt,r-l+1); 56 int m=l+r>>1; 57 if( L <= m ) update(L,R,c,lson); 58 if (R > m) update(L,R,c,rson); 59 pushup(l,r,rt); 60 } 61 62 void update(int p,int c,int l,int r,int rt) 63 {//单点更新 64 if(l==r) 65 { 66 rm[rt]+=c; 67 return ; 68 } 69 int m=l+r>>1; 70 if( p <= m ) update(p,c,lson); 71 else update(p,c,rson); 72 pushup(l,r,rt); 73 } 74 75 ll query(int L,int R,int l,int r,int rt) 76 { 77 if( L<=l && r<=R ) 78 { 79 return rm[rt]; 80 } 81 pushdown(l,r,rt, r-l+1); 82 int m=l+r>>1; 83 ll ret = 0; 84 if( L<=m ) ret += query(L,R,lson); 85 if( m<R ) ret += query(L,R,rson); 86 return ret; 87 } 88 89 int main() 90 { 91 int n,m; 92 scanf("%d%d",&n,&m); 93 char str[2]; 94 build(1,n,1); 95 while(m--) 96 { 97 int l,r,x; 98 scanf("%s",str); 99 if(str[0]==‘Q‘) 100 { 101 scanf("%d%d",&l,&r); 102 printf("%I64d\n",query(l,r,1,n,1)); 103 } 104 else 105 { 106 scanf("%d %d %d", &l, &r, &x); 107 update(l, r, x, 1, n, 1); 108 } 109 } 110 return 0; 111 }
字典树求异或值
1 typedef long long ll; 2 3 const int maxn=1e5+10; 4 5 struct t 6 { 7 ll tree[32*maxn][3];//字典树的树部分 8 ll val[32*maxn];//字典树的终止节点 9 ll cnt;//字典树的大小 10 void init() //初始化字典树 11 { 12 cl(tree,0); 13 cl(val,0); 14 cnt=1; 15 } 16 void add(ll a) 17 { 18 int x=0,now; 19 for(int i=32; i>=0; i--) 20 { 21 now=((a>>i)&1); //当前位数 22 if(tree[x][now]==0) //没有的这个节点的话 加入这个节点 23 { 24 cl(tree[cnt],0); 25 val[cnt]=0; 26 tree[x][now]=cnt++; 27 } 28 x=tree[x][now]; 29 } 30 val[x]=a; //结尾标记 31 } 32 ll Search(ll a) //查找字典树中和a异或起来最大的值 33 { 34 int x=0,now; 35 for(int i=32; i>=0; i--) 36 { 37 now=!((a>>i)&1); 38 if(tree[x][now]) //如果和当前位相反的这个节点存在 39 { 40 x=tree[x][now]; //那么继续找这个节点下的子树 41 } 42 else 43 { 44 x=tree[x][!now]; //不存在就找自己这个节点下的子树 45 } 46 } 47 return val[x]; //结尾标记就是这个数字 48 } 49 } Trie;
lucas定理
1 ll fac[maxn]; 2 3 ll quick_pow(ll a,ll n) 4 { 5 ll ans=1; 6 while(n) 7 { 8 if(n%2) ans=1ll*ans*a%mod; 9 a=1ll*a*a%mod; 10 n>>=1; 11 } 12 return ans; 13 } 14 15 ll inv(ll a) 16 { 17 return quick_pow(a,mod-2); 18 } 19 20 void init() 21 { 22 fac[0]=1; 23 for(int i=1;i<maxn;i++) 24 { 25 fac[i]=1ll*fac[i-1]*i%mod; 26 } 27 } 28 29 ll C(ll a,ll b) 30 { 31 ll ans=1; 32 if(a<b || b<0) return 0; 33 while(a&&b) 34 { 35 ll aa=a%mod,bb=b%mod; 36 if(aa<bb) return 0;; 37 ans = 1ll*ans*fac[aa]%mod * inv(1ll*fac[bb]*fac[aa-bb]%mod)%mod; 38 a/=mod,b/=mod; 39 } 40 return ans; 41 }
O(n)预处理Cm n
1 const int maxn=1e6+10; 2 const int mod=1e9+7; 3 ll fac[maxn],f[maxn],inv[maxn]; 4 5 void init() 6 { 7 fac[0]=fac[1]=f[0]=f[1]=inv[0]=inv[1]=1; 8 for(int i=2;i<maxn;i++) 9 { 10 fac[i]=fac[i-1]*i%mod; // n! 11 ll t=mod/i,k=mod%i; 12 f[i]=(mod-t)*f[k]%mod; // n的逆元 13 inv[i]=inv[i-1]*f[i]%mod; // n!的逆元 14 } 15 } 16 17 ll C(ll n,ll m) 18 { 19 if(n<m) return 0; 20 return fac[n]*inv[m]%mod*inv[n-m]%mod; 21 }
自适应simpson积分
1 double simpson(double a,double b) 2 { 3 double c=a+(b-a)/2; 4 return (f(a)+4*f(c)+f(b))*(b-a)/6; 5 } 6 7 double asr(double a,double b,double eps,double A) 8 { 9 double c=a+(b-a)/2; 10 double L=simpson(a,c); 11 double R=simpson(c,b); 12 if(fabs(L+R-A)<=15*eps) return L+R+(L+R-A)/15.0; 13 return asr(a,c,eps/2,L)+asr(c,b,eps/2,R); 14 } 15 16 double asr(double a,double b,double eps) 17 { 18 return asr(a,b,eps,simpson(a,b)); 19 }
日期公式
1 int zeller(int y,int m,int d) 2 {//计算星期几 3 if(m<=2) y--,m+=12; 4 int c=y/100;y%=100; 5 int w=((c>>2)-(c<<1)+y+(y>>2)+(13*(m+1)/5)+d-1)%7; 6 if(w<0) w+=7; return (w); 7 } 8 9 int getid(int y,int m,int d) 10 {//计算每个日期的id 可以计算两个日期之间的天数 11 if(m<3) {y--;m+=12;} 12 return 365*y+y/4-y/100+y/400+(153*m+2)/5+d; 13 }
标签:异或 pen ring row turn cto queue char 初始化
原文地址:http://www.cnblogs.com/general10/p/7502766.html