随笔分类 - 御用模板
摘要:int a[100010]; int st1[100010][25];//st表 int st2[100010][25];//st表 void init(int n){ for (int i = 0; i < n; i++){ st1[i][0] = a[i + 1]; st2[i][0] = a[
阅读全文
摘要:01矩阵求最大全1的矩形和正方形 #include<bits/stdc++.h> using namespace std; const int N = 2020; int l[N][N],r[N][N],u[N][N]; bool a[N][N]; int main(){ int n,m; cin
阅读全文
摘要:struct Flow { static constexpr int INF = 1e9; int n; struct Edge { int to, cap; Edge(int to, int cap) : to(to), cap(cap) {} }; std::vector<Edge> e; st
阅读全文
摘要:const int S=8;//随机算法判定次数一般8~10就够了 //计算 ret=(a*b)%c a,b,c<2^63 ll mult_mod(ll a,ll b,ll c) { a%=c; b%=c; ll ret=0; ll tmp=a; while(b) { if(b&1) { ret+=
阅读全文
摘要:int n;const int N=4e5;const int LOGN=22; namespace ST{ const int M=N*LOGN; int son[M][2],ct[M]; int node_count; int new_node(int ls,int rs,int cnt){ i
阅读全文
摘要:num = sqrt(n); for (int i = 1; i <= num; i++) st[i] = n / num * (i - 1) + 1, ed[i] = n / num * i; ed[num] = n; for (int i = 1; i <= num; i++) { for (i
阅读全文
摘要:使用两个multiset,使得前一个里面存放最小的一半,后一个里面存放最大的一半。每次插入先插入到前一个里面。如果大于后一个的最小,移动即可。 #include <bits/stdc++.h> using namespace std; multiset<int> S,T; // Always S.s
阅读全文
摘要:int BitCount5(unsigned int n) { unsigned int tmp = n - ((n >>1) &033333333333) - ((n >>2) &011111111111); return ((tmp + (tmp >>3)) &030707070707) %63
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; const int inf=1000000007; struct edg{int y,nxt,v;}e[41000]; int lk[210],ltp=1; int n,m,o,a[210]; int s,t;
阅读全文
摘要:所谓矩阵快速幂就是把快速幂中的乘运算替换为矩阵乘。 解决 fab时 f(n)=f(n-1)+f(n-2) 则可得到 1*f(n-1)+1*f(n-2)=f(n);1*f(n-1)+0*f(n-2)=f(n-1); 给一些简单的递推式1.f(n)=a*f(n-1)+b*f(n-2)+c;(a,b,c是
阅读全文
摘要:#include <iostream> using namespace std ; #define rd(x) (rand()%(x)) typedef unsigned long long ll; ll pow_mod(ll a,ll b,ll r){ ll ans=1,buff=a; while
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 typedef long long ll; const int maxn=1e6+10; ll tree[ma
阅读全文
摘要:找i节点的第k个父亲 int father(int i,int k) { for(int x=0;x<=int(log2(k));x++) if((1<<x)&k) //(1<<x)&k可以判断k的二进制表示中,第(x-1)位上是否为1 i=fa[i][x]; //把i往上提 return i; }
阅读全文
摘要:本质是带优化的双指针,对全部区间进行√n个块的分块操作,然后进行排序。第一关键字为查询的左端点块号,第二关键字为查询的右端点本身的位置。 这里放一个洛谷例题 P3901 数列找不同 附上代码 #pragma GCC optimize("O3") #include <bits/stdc++.h> #d
阅读全文
摘要:void rmq_init() { for(int i=1;i<=N;i++) dp[i][0]=arr[i];//初始化 for(int j=1;(1<<j)<=N;j++) for(int i=1;i+(1<<j)-1<=N;i++) dp[i][j]=min(dp[i][j-1],dp[i+(
阅读全文
摘要:'可以用到整除分块的形式,大致是这样的: 对于每一个 ⌊n/i⌋ 我们可以通过打表可以发现:有许多 ⌊n/i⌋ 的值是一样的,而且它们呈一个块状分布;再通过打表之类的各种方法,我们惊喜的发现对于每一个值相同的块,它的最后一个数就是n/(n/i)。 for(int l=1,r;l<=n;l=r+1)
阅读全文
摘要:#include<bits/stdc++.h> #define reg register using namespace std; typedef long long ll; const int MN=60; ll a[61],tmp[61]; bool flag; void ins(ll x) {
阅读全文
摘要:#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int mx=250501;//n*m+m<=250500 inline int Read(){
阅读全文
摘要://最小覆盖球 #include <iostream> #include <string.h> #include <stdio.h> #include <math.h> #define N 150 #define eps 1e-8 #define T 100 #define delta 0.98 #
阅读全文
摘要://Suplex #include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <cmath> #define N 100000 using namespace std; const in
阅读全文

浙公网安备 33010602011771号