codeforces 933D A Creative Cutout

题目链接

正解:组合数学。

充满套路与细节的一道题。。

首先我们显然要考虑每个点的贡献(我就不信你能把$f$给筛出来

那么对于一个点$(x,y)$,我们设$L=x^{2}+y^{2}$,那么它的贡献就是$ans=\sum_{k=L}^{n}\sum_{j=L}^{k}j$

然后我们把后面那个$\sum$化成组合数的形式,即$ans=\sum_{k=L}^{n}\binom{k+1}{2}-\binom{L}{2}$(讲真连这一步我都没想到

注意一个等式$\sum_{i=L}^{R}\binom{i}{x}=\binom{R+1}{x+1}-\binom{L}{x+1}$,这个直接用杨辉三角的递推式即可证明。

把这个等式带进去,可得$ans=\binom{n+2}{3}-\binom{L+1}{3}-(n-L+1)\binom{L}{2}$

然后暴力拆开,可得$ans=\frac{1}{6}(n(n+1)(n+2)-L(L-1)(L+1)-3(n-L+1)(L-1)L)$

然后把$L=x^{2}+y^{2}$代入,可得$6ans=n(n+1)(n+2)+2x^{6}+6x^{4}y^{2}+6x^{2}y^{4}+2y^{6}-3(n+2)(x^{4}+2x^{2}y^{2}+y^{4})+(3n+4)(x^{2}+y^{2})$

枚举$x$,那么$y$的取值范围是一个区间。所以我们预处理出二次,三次和六次的幂和,直接算即可,复杂度$O(\sqrt{n})$。

 1 #include <bits/stdc++.h>
 2 #define il inline
 3 #define RG register
 4 #define ll long long
 5 #define N (1000005)
 6 #define rhl (1000000007)
 7
 8 using namespace std;
 9
10 ll sum2[N],sum4[N],sum6[N],n,m,lim,ans;
11
12 il ll qpow(RG ll a,RG ll b){
13   RG ll ans=1;
14   while (b){
15     if (b&1) ans=ans*a%rhl;
16     if (b>>=1) a=a*a%rhl;
17   }
18   return ans;
19 }
20
21 int main(){
22 #ifndef ONLINE_JUDGE
23   freopen("cutout.in","r",stdin);
24   freopen("cutout.out","w",stdout);
25 #endif
26   cin>>n,m=n%rhl,lim=sqrt(n);
27   for (RG ll i=1;i<=lim;++i){
28     sum2[i]=(sum2[i-1]+i*i)%rhl;
29     sum4[i]=(sum4[i-1]+qpow(i,4))%rhl;
30     sum6[i]=(sum6[i-1]+qpow(i,6))%rhl;
31   }
32   for (RG ll x=-lim,y,x2,x4,x6,res;x<=lim;++x){
33     y=sqrt(n-x*x),x2=qpow(x,2),x4=qpow(x,4),x6=qpow(x,6),res=0;
34     (res+=m*(m+1)%rhl*(m+2)+2*x6-3*(m+2)*x4+(3*m+4)*x2)%=rhl;
35     (ans+=12*x4%rhl*sum2[y]+12*x2%rhl*sum4[y]+4*sum6[y])%=rhl;
36     (ans-=12*(m+2)%rhl*x2%rhl*sum2[y])%=rhl;
37     (ans-=6*(m+2)%rhl*sum4[y])%=rhl;
38     (ans+=2*(3*m+4)*sum2[y]+res*(2*y+1))%=rhl;
39   }
40   cout<<(ans+rhl)*((rhl+1)/2)%rhl*((rhl+1)/3)%rhl; return 0;
41 }

原文地址:https://www.cnblogs.com/wfj2048/p/8721454.html

时间: 2024-08-30 04:08:24

codeforces 933D A Creative Cutout的相关文章

CF#462 div1 D:A Creative Cutout

CF#462 div1 D:A Creative Cutout 题目大意: 原网址戳我! 题目大意: 在网格上任选一个点作为圆中心,然后以其为圆心画\(m\)个圆. 其中第\(k\)个圆的半径为\(\sqrt{k}\),\(m\)个圆的编号依次为\(1\)~\(m\). 定义一个格点的美妙值\(g(x,y)\)为包含了它的所有圆的编号之和. 定义\(f(n)\)为:当画了\(n\)个圆时,\(f(n) = \sum_{i,j\in R} g(i,j)\). 现在非常变态的问你一个非常无聊的恶心问

组合计数训练

1, A Creative Cutout CodeForces - 933D 大意:给定$n$个圆, 圆心均在原点, 第$k$个圆半径为$\sqrt{k}$ 定义一个点的美丽值为所有包含这个点的圆的编号和 定义函数$f(n)$为只有$n$个圆时所有点的贡献,求$\sum_{k=1}^{n}{f(k)}$ 首先注意到每个圆上的点对答案的贡献是相同的 可以得到圆$x^2+y^2=c$上单个点的贡献 $$g(c)=\sum _{i=c}^n \sum _{j=c}^i j=\binom{n-c+2}{

Codeforces 1111C Creative Snap分治+贪心

Creative Snap C. Creative Snap time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base. Let we

【CodeCraft-19 and Codeforces Round #537 (Div. 2) C】Creative Snap

[链接] 我是链接,点我呀:) [题意] 横坐标1..2^n对应着2^n个复仇者的基地,上面有k个复仇者(位置依次给出). 你是灭霸你要用以下方法消灭这k个复仇者: 一开始你获取整个区间[1..2^n] 假设你当前获取的区间为[l,r] mid = (l+r)/2 那么你每次有两种选择 1.将整个区间全都毁掉,如果这个区间里没有复仇者,那么花费为A,否则花费为B复仇者个数区间长度 2.将区间分为[l,mid]和[mid+1,r]分开毁掉(即分别获取[l,mid]和[mid+1,r]这两个区间,然

解题报告 之 CodeForces 6E Exposition

解题报告 之 CodeForces 6E Exposition Description There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction

Codeforces Beta Round #6 (Div. 2 Only) E. Exposition multiset

E. Exposition Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/6/E Description There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library d

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th