AtCoder Beginner Contest 132 F - Small Products

数 sqrt 缩小范围

整除分块

  1 #include <cstdio>
  2 #include <cstdlib>
  3 #include <cmath>
  4 #include <cstring>
  5 #include <string>
  6 #include <algorithm>
  7 #include <iostream>
  8 using namespace std;
  9 #define ll long long
 10
 11 const int maxn=1e5+10;
 12 const ll mod=1e9+7;
 13 const double eps=1e-8;
 14
 15 ll f[110][maxn],add[maxn],cnt[maxn];
 16
 17 /**
 18 大于sqrt(maxvalue)的x,
 19 肯定是其它数到x,到从x到其它数
 20
 21 计数 用 整除分块
 22 **/
 23
 24 int main()
 25 {
 26     ll n,siz,mid,mmid,l,r,i,j,g=0,sum=0;
 27     scanf("%lld%lld",&siz,&n);
 28     mmid=sqrt(siz+eps);
 29     mid=siz/(mmid+1);
 30     g=0;
 31     for (l=1;l<=siz;l=r+1)
 32     {
 33         ///[l,r]
 34         r=siz/(siz/l);
 35 //        printf("%lld %lld %lld\n",l,r,siz/l);
 36         if (siz/l<=mid)
 37             cnt[siz/l]=r-l+1;
 38     }
 39
 40     for (j=1;j<=mmid;j++)
 41         f[1][j]=1;
 42     for (i=2;i<=n;i++)
 43     {
 44         g=0;
 45         for (j=1;j<=mmid;j++)
 46             (g+=f[i-1][j])%=mod;
 47         for (j=1;j<=mmid;j++)
 48             f[i][j]=g;
 49
 50         for (l=1;l<=mid;l++)
 51             add[l]=(add[l-1]+f[i-2][l])%mod;
 52
 53         g=0;
 54         for (l=mid;l>=1;l--)
 55         {
 56             (g+=add[l]*cnt[l])%mod;
 57             (f[i][l]+=g)%=mod;
 58         }
 59     }
 60
 61
 62     for (j=1;j<=mmid;j++)
 63         (sum+=f[n][j])%mod;
 64     for (l=1;l<=mid;l++)
 65     {
 66         add[l]=(add[l-1]+f[n-1][l])%mod;
 67         (sum+=add[l]*cnt[l])%=mod;
 68     }
 69
 70     ///
 71     memset(f,0,sizeof(f));
 72     g=0;
 73     for (l=mid;l>=1;l--)
 74     {
 75         (g+=cnt[l])%mod;
 76         f[1][l]=g;
 77     }
 78     n--;
 79     for (i=2;i<=n;i++)
 80     {
 81         g=0;
 82         for (j=1;j<=mmid;j++)
 83             (g+=f[i-1][j])%=mod;
 84         for (j=1;j<=mmid;j++)
 85             f[i][j]=g;
 86
 87         for (l=1;l<=mid;l++)
 88             add[l]=(add[l-1]+f[i-2][l])%mod;
 89
 90         g=0;
 91         for (l=mid;l>=1;l--)
 92         {
 93             (g+=add[l]*cnt[l])%mod;
 94             (f[i][l]+=g)%=mod;
 95         }
 96     }
 97
 98     for (j=1;j<=mmid;j++)
 99         (sum+=f[n][j])%mod;
100     for (l=1;l<=mid;l++)
101     {
102         add[l]=(add[l-1]+f[n-1][l])%mod;
103         (sum+=add[l]*cnt[l])%=mod;
104     }
105
106
107     printf("%lld",sum);
108     return 0;
109 }
110 /*
111 special
112 100=10*10
113
114 100 3
115 1 1 100
116 2 2 50
117 3 3 33
118 4 4 25
119 5 5 20
120 6 6 16
121 7 7 14
122 8 8 12
123 9 9 11
124 10 10 10
125 ///
126 11 11 9
127 12 12 8
128 13 14 7
129 15 16 6
130 17 20 5
131 21 25 4
132 26 33 3
133 34 50 2
134 51 100 1
135
136
137 23 3
138 1 1 23
139 2 2 11
140 3 3 7
141 4 4 5
142 ///
143 5 5 4
144 6 7 3
145 8 11 2
146 12 23 1
147
148
149 31622*log(n) *100
150
151 10 5
152 1 1 10
153 2 2 5
154 3 3 3
155
156 4 5 2
157 6 10 1
158
159 */

原文地址:https://www.cnblogs.com/cmyg/p/11108256.html

时间: 2024-11-06 18:54:08

AtCoder Beginner Contest 132 F - Small Products的相关文章

AtCoder Beginner Contest 152 - F - Tree and Constraints (容斥定理+树上路径的性质)

AtCoder Beginner Contest 152 - F - Tree and Constraints (容斥定理+树上路径的性质) We have a tree with NN vertices numbered 11 to NN. The ii-th edge in this tree connects Vertex aiai and Vertex bibi. Consider painting each of these edges white or black. There ar

AtCoder Beginner Contest 132 解题报告

前四题都好水.后面两道题好难. C Divide the Problems #include <cstdio> #include <algorithm> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (c

AtCoder Beginner Contest 132 E - Hopscotch Addict

bfs 位置+状态 just need to calculate min value(only it is useful), so O(1*x) 挺有趣的一道题... 1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <string> 6 #include <algorithm> 7 #include

AtCoder Beginner Contest 133 F - Colorful Tree

题意:给出一棵n个点的树,每条边有颜色和边长两个属性,n个询问,每次询问把颜色x的边的边长变为y问u到v的路径长度是多少,询问之间独立. 解法:这道题蛮有意思的.解法参考https://www.cnblogs.com/Tieechal/p/11185912.html这位大佬的,这里说下我的理解. 对于每组询问(x,y,u,v)答案比较显然就是dist(u,v)+(sumlen[x]-sumcnt[x]*y),但是这道题在线不好做我们考虑离线做.但是答案的式子是设计到两个点的,怎么才能离线做呢?这

AtCoder Beginner Contest 153 F - Silver Fox vs Monster

题目链接 https://atcoder.jp/contests/abc153/tasks/abc153_f 题意 : 在坐标轴上有一些怪兽,每个怪兽有对应的生命值hi,你可以对他们进行炮击,你的每次炮击可以队该点前后D范围内的怪兽造成A的伤害,问最少要炮击多少次. 我的最初的想法是先排序,扫到最左边的怪兽,先进行炮击,把他打死,然后记录炮击了多少次,然后把其后2d距离的怪兽都炮击一下发现超时 代码如下: inline ll read(){ ll s=0,w=1; char ch=getchar

AtCoder Beginner Contest 128 F - Frog Jump

题意 有一只青蛙,有\(0, 1, \cdots, N - 1\)个荷叶.每个荷叶上有权值\(s_i\). 选定\(A\), \(B\),初始分数为\(0\). 当前位置为\(x\): 对于\(y = x + A\): 如果\(y = N - 1\),游戏结束. 如果\(y \neq N - 1\),但是\(y\)这个荷叶存在,那么分数增加\(s_i\),并且这片荷叶消失. 如果\(y \neq N - 1\),但是\(y\)这个荷叶不存在,那么分数减去\(10^{100}\),游戏结束. 对于

AtCoder Beginner Contest 136

AtCoder Beginner Contest 136 Contest Duration : 2019-08-04(Sun) 20:00 ~ 2019-08-04(Sun) 21:40 Website: AtCoder BC-136 后面几题都挺考思考角度D. C - Build Stairs 题目描述: 有n座山从左到右排列,给定每一座山的高度\(Hi\),现在你可以对每座山进行如下操作至多一次:将这座山的高度降低1. 问是否有可能通过对一些山进行如上操作,使得最后从左至右,山的高度呈不下降

AtCoder Beginner Contest 154 题解

人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We have A balls with the string S written on each of them and B balls with the string T written on each of them. From these balls, Takahashi chooses one

AtCoder Beginner Contest 155 简要题解

AtCoder Beginner Contest 155 A:签到失败,WA一次. int main() { int a, b, c; cin >> a >> b >> c; if(a == b && b == c) cout << "No"; else if(a == b || a == c || b == c) cout << "Yes"; else cout << &quo