- 博客(119)
- 收藏
- 关注
原创 二维前缀和
记录矩阵:(x1,y1),(x2,y2) a[x1][y1]++,a[x1][y2+1]--,a[x2+1][y1]--,a[x2+1][y2+1]++;读取矩阵:a[x2][y2]-a[x2][y1-1]-a[x1-1][y1]+a[x1][y1]。读取矩阵:a[x2][y2]-a[x2][y1-1]-a[x1-1][y1]+a[x1][y1]遍历一遍数组:使a[i][j]表示x在(1,i),y在(1,j)的子矩阵和。遍历一边数组,使a[i][j]表示x=i,y=j时的值。记录点:a[i][j]++;
2024-06-05 02:25:14
144
原创 Hash Function(fft)
系数大于0,说明存在a=ai-aj+50000这样的数存在,让a-50000,存到一个数组中。然后从n枚举到500000,枚举n的倍数,如果数组中没有n的倍数,答案就取n;题意:给定一个序列,求使得任意两数的hash值不同的最小模数;如果暴力求解,o(n2),会超时,可以用fft来优化。,但次方不可<0,所以让所有次方加上500000,让。也就是说seed不能是任意两数差的因子。分析:a=b(mod seed)让两序列进行fft,得到序列如果。序列为当以a1>0时,我们就让。对于另一个序列,本应该是。
2024-05-06 00:10:32
715
原创 两球体积交
#include<bits/stdc++.h>using namespace std;#define LL long longconst int N = 2e6;const long long inf = 1e9;const long long mod = 998244353;const double PI = acos(-1);struct Point{ long double x, y, z;}p[6];struct Ball{ Point o; lon
2024-05-05 23:15:48
388
原创 求和(第二斯特林数+ntt)
思路:#define _CRT_SECURE_NO_WARNINGSLL ans = 1;while (b)b >>= 1;return ans;h[0] = 1;i <= n;i++)g[1] = -1;i <= n;i++)g[i] = x;i < tot;i++)m <= tot;m <<= 1)i < tot;i += m)
2024-03-09 22:51:37
830
原创 P9238 [蓝桥杯 2023 省 A] 翻转硬币(杜教筛+莫比乌斯)
题目:https://www.luogu.com.cn/problem/P9238
2024-03-09 19:34:49
1841
原创 P3768 简单的数学题(莫比乌斯反演+杜教筛)
题目:P3768 简单的数学题 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)思路:代码:#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<string>#include<cstring>#include<cmath>#include<ctime>#include<algorithm>#include<utility
2024-03-08 20:49:19
689
原创 杜教筛模板
LL n;i < N;i++)if (!j++)break;i < N;i++)l <= n;l = r + 1)elsereturn ans;LL ans = 1;l <= n;l = r + 1)elsereturn ans;init();int T;cin >> T;
2024-03-08 00:04:17
341
原创 P4859 已经没有什么好害怕的了(二项式反演+dp)
题录:P4859 已经没有什么好害怕的了 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
2024-02-28 16:21:37
531
原创 快乘模板(long double 或者二进制)
a*b%p,当a*b可能会超过 long long 范围,我们可以用long double 优化;时间复杂度为O ( 1 ) ,适合用于卡常数的题目。与快速幂类似,将b二进制分解;
2024-02-01 16:55:12
137
原创 任意模数多项式乘法(洛谷4245)
代码:#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include<string>#include<cstring>#include<cmath>#include<ctime>#include<algorithm>#include<utility>#include<stack>#include<queue>#include&
2024-02-01 16:39:07
339
原创 多项式乘法逆(p4238 NTT)
代码:int rel[N];LL gi = 0;LL ans = 1;while (b)b = b >> 1;return ans;i < tot;m <= tot;m <<= 1)i < tot;i += m)LL gk = 1;j < m / 2;j++)return;bit = 0;i <len;i <tot;
2024-01-26 17:35:29
541
原创 分治NTT(洛谷P4721)
对于区间(l,r),当我们算出f[l]-f[mid](mid=(l+r)>>1),我们可以算出(l,mid)对后边区间贡献,再算(mid+1,r)内的f值。可以发现,i<j,f[i]会对f[j]有贡献,而f[j]对f[i]没有贡献,考虑分治。如果用NTT一个一个求时间复杂度是O(n^2)。
2024-01-26 02:49:59
546
原创 acwing2241 礼物( FFT)
int n, m;int rel[N];i < tot;i++)m <= tot;m *= 2)i < tot;i+=m)j < m / 2;j++)LL bb = 0;i <n;i++)i < n;i++)i <= n - 1;i++)n--;i < tot。
2024-01-24 20:55:29
796
原创 P2257 YY的GCD(莫比乌斯)
给定 N,M,求 1≤x≤N,1≤y≤M 且 gcd(x,y) 为质数的(x,y) 有多少对。神犇 YY 虐完数论后给傻× kAc 出了一题。T 行,每行一个整数表示第 i 组数据的结果。接下来 T 行,每行两个正整数,N,M。第一行一个整数 T 表述数据组数。
2024-01-17 15:51:55
346
原创 P3704数字表格(莫比乌斯反演)
第 i 行第 j 列的格子中的数是 gcd(i,j),其中gcd(i,j) 表示 i,j 的最大公约数。Doris 刚刚学习了 fibonacci 数列。用 fi 表示数列的第 i 项,那么。Doris 的表格中共有 n×m 个数,她想知道这些数的乘积是多少。Doris 用老师的超级计算机生成了一个 n×m 的表格,接下来 T 行,每行两个整数 n,m,表示一组数据。输入的第一行是一个整数 T,表示测试数据的组数。对于每组数据,输出一行一个整数表示答案。答案对 109+7 取模。
2024-01-05 09:27:18
827
原创 洛谷p1829(莫比乌斯反演)
思路:#define _CRT_SECURE_NO_WARNINGSint n,cn,m;LL mu[N];mu[1] = 1;i <= N;i++)if (!j++)i <= N;i++)LL res = 0;l <= n;l = r + 1)return res;int main()into();LL ans = 0;l <= n;
2024-01-04 21:43:14
397
原创 莫比乌斯反演(acwing2702)
对于给出的 n� 个询问,每次求有多少个数对 (x,y)(�,�),满足 a≤x≤b,c≤y≤d�≤�≤�,�≤�≤�,且 gcd(x,y)=kgcd(�,�)=�,gcd(x,y)gcd(�,�) 函数为 x� 和 y� 的最大公约数。
2024-01-04 14:50:18
1412
原创 破阵子(三分+凸包旋转卡壳)
输入一个正整数T(T<=10),表示有T组数据,每组数据包括一个n(n<=10000),表示有n个点,每行包括每个点的坐标 (x,y) (-100000<=x,y<=100000),速度向量 (vx,vy) (-1000<=vx,vy<=1000)他们每个点的位置和每个点的速度向量,现在求在哪个时刻的时候,他们的special dis 最小,并输出这个距离。平面上有n个点,每个点有各自的速度向量,现在给出0时刻,在同一时刻,平面点的最远距离叫做special dis。但发现dis不一定随时间增大而增大,
2023-12-06 20:01:38
67
原创 梦回吹角连营(2)(快速幂&快乘)
给定f(n)=(a+1)*n^a+(a+2)*n^(a+1)+...+b*n^(b-1)输入一个正整数T(T<=10),表示有T组数据,每组数据包括三个整数a,b,n。输出 f(n)%10000000033 的结果。注意:这题数非常大,两数相乘用快乘模板。得到 S(a),S(b),用快速幂模板。求f(n)%10000000033。
2023-12-05 21:41:11
113
原创 Period of an Infinite Binary Expansion(分析+欧拉)
我们设第一次进入循环的位置是i,第一次循环结束后,再次进入循环的位置是j;我们可以便利phi(q1)因子,找到最小满足方程的因子k,那么j-i=k;对于一个小于1的数,化为二进制,找第一次进入循环的位置和最小循环周期。由于p,q互素,得2^i(2^(j-i)-1)=0(mod q);移位得:p*2^i(2^(j-i)-1)=0(mod q)根据欧拉函数phi(q1)为方程一个解,但不一定是最小;由i,j定义可得p*2^i=p*2^j(mod q)i=q能整除2最多次数(i取最小)
2023-12-01 20:05:07
79
原创 C - GCD(因子分解+欧拉函数)
/防止i*i==n时算两遍。枚举因子i(1,n),对于每个因子i(i>=m),求有多少个x(1,n)使得gcd(x,n)=i。gcd(x,n)=i <=> gcd(x/i,n/i)=1 <=> 求n/i的欧拉函数的值。
2023-12-01 18:06:22
64
原创 The Euler function(线性筛求1-n的欧拉值)
i<=b;i++)i>=b;i--)phi[1] = 1;i <= N;i++)if (!vis[i])j++)vis[m] = 1;break;elseint main()into();=EOF)LL ans = 0;i <= b;i++)return 0;
2023-12-01 17:42:25
37
原创 五十弦翻塞外声(素数筛+素因子分解)
输入一个正整数T(T<=10000),表示有T组数据,每组数据包括一个整数n(1<=n<=1e12)如果先用素数筛筛出1e6内的素因子,大概是1e4*1e4.如果直接质因子分解,1e4*1e6,会超时。
2023-11-27 18:13:06
43
原创 D - Grandpa‘s Estate(稳定凸包)
Being the only living descendant of his grandfather, Kamran the Believer inherited all of the grandpa's belongings. The most valuable one was a piece of convex polygon shaped farm in the grandpa's birth village. The farm was originally separated from the n
2023-11-26 01:01:29
200
原创 C - The Fortified Forest(凸包)
Once upon a time, in a faraway land, there lived a king. This king owned a small collection of rare and valuable trees, which had been gathered by his ancestors on their travels. To protect his trees from thieves, the king ordered that a high fence be buil
2023-11-25 21:21:16
243
原创 B - Scrambled Polygon(极角排序)
A closed polygon is a figure bounded by a finite number of line segments. The intersections of the bounding line segments are called the vertices of the polygon. When one starts at any vertex of a closed polygon and traverses each bounding line segment exa
2023-11-23 23:02:43
412
原创 A - Wall(凸包Andrew模板)
Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's castle. The King was so greedy, that he would not listen to his Architect's proposals to build a beautiful brick wall with a perfect shape and nice t
2023-11-23 21:54:13
73
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人