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})$。
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define N (1000005)
#define rhl (1000000007) using namespace std; ll sum2[N],sum4[N],sum6[N],n,m,lim,ans; il ll qpow(RG ll a,RG ll b){
RG ll ans=;
while (b){
if (b&) ans=ans*a%rhl;
if (b>>=) a=a*a%rhl;
}
return ans;
} int main(){
#ifndef ONLINE_JUDGE
freopen("cutout.in","r",stdin);
freopen("cutout.out","w",stdout);
#endif
cin>>n,m=n%rhl,lim=sqrt(n);
for (RG ll i=;i<=lim;++i){
sum2[i]=(sum2[i-]+i*i)%rhl;
sum4[i]=(sum4[i-]+qpow(i,))%rhl;
sum6[i]=(sum6[i-]+qpow(i,))%rhl;
}
for (RG ll x=-lim,y,x2,x4,x6,res;x<=lim;++x){
y=sqrt(n-x*x),x2=qpow(x,),x4=qpow(x,),x6=qpow(x,),res=;
(res+=m*(m+)%rhl*(m+)+*x6-*(m+)*x4+(*m+)*x2)%=rhl;
(ans+=*x4%rhl*sum2[y]+*x2%rhl*sum4[y]+*sum6[y])%=rhl;
(ans-=*(m+)%rhl*x2%rhl*sum2[y])%=rhl;
(ans-=*(m+)%rhl*sum4[y])%=rhl;
(ans+=*(*m+)*sum2[y]+res*(*y+))%=rhl;
}
cout<<(ans+rhl)*((rhl+)/)%rhl*((rhl+)/)%rhl; return ;
}
codeforces 933D A Creative Cutout的更多相关文章
- CF#462 div1 D:A Creative Cutout
CF#462 div1 D:A Creative Cutout 题目大意: 原网址戳我! 题目大意: 在网格上任选一个点作为圆中心,然后以其为圆心画\(m\)个圆. 其中第\(k\)个圆的半径为\(\ ...
- A Creative Cutout CodeForces - 933D (计数)
大意:给定$n$个圆, 圆心均在原点, 第$k$个圆半径为$\sqrt{k}$ 定义一个点的美丽值为所有包含这个点的圆的编号和 定义函数$f(n)$为只有$n$个圆时所有点的贡献,求$\sum_{k= ...
- Codeforces 1111C Creative Snap分治+贪心
Creative Snap C. Creative Snap time limit per test 1 second memory limit per test 256 megabytes inpu ...
- CodeCraft-19 and Codeforces Round #537 (Div. 2) C. Creative Snap 分治
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their bas ...
- 【CodeCraft-19 and Codeforces Round #537 (Div. 2) C】Creative Snap
[链接] 我是链接,点我呀:) [题意] 横坐标1..2^n对应着2^n个复仇者的基地,上面有k个复仇者(位置依次给出). 你是灭霸你要用以下方法消灭这k个复仇者: 一开始你获取整个区间[1..2^n ...
- Codeforces Round #537 C. Creative Snap
题面: 传送门 题目描述: 灭霸想要摧毁复仇者联盟的基地.基地的长度为2的n次方,基地可以看成是一个长度为2的n次方的数组.基地的每一个位置可以由很多个超级英雄,但是一个超级英雄只能站一个位置.灭霸想 ...
- 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/ ...
- Codeforces Round #322 (Div. 2) B. Luxurious Houses 水题
B. Luxurious Houses Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/pr ...
- Codeforces Beta Round #6 (Div. 2 Only) 单调队列
题目链接: http://codeforces.com/contest/6/problem/E E. Exposition time limit per test 1.5 secondsmemory ...
随机推荐
- @Resource和@Autowired区别
@Resource和@Autowired都是做bean的注入时使用 历史: @Autowired 属于Spring的注解 org.springframework.beans.facto ...
- JS 重写alert,使之能输出多个参数
windows._alert = windows.alert; windows.alert = function(){ _alert = (Array.prototype.slice(argument ...
- 前端(九):react生命周期
一.组件渲染 当组件的props或者state发生改变时,组件会自动调用render方法重新渲染.当父组件被重新渲染时,子组件也会被递归渲染.那么组件是如何渲染的呢? # 方案一 1.state数据 ...
- ZooKeeper 节点
ZNode zk 中的每一个数据节点称为 ZNode ,所有的 ZNode 按层次化结构进行组织,形成一棵树(与Linux文件系统相似).节点可以写入数据,也可以在节点下面创建子节点. 节点类型: 1 ...
- Java springmvc 统一异常处理的方案
前言:为什么要统一异常处理?经常在项目中需要统一处理异常,将异常封装转给前端.也有时需要在项目中统一处理异常后,记录异常日志,做一下统一处理. Springmvc 异常统一处理的方式有三种. 一.使用 ...
- MVC 导出Execl 的总结几种方式 (三)
第三种方式呢,就是借用第三方插件 NPOI 来实现Execl 导出 第一步:在NuGut包中下载NPOI 组件 第二步:编辑控制器代码 public FileResult ExcelNewKeyPro ...
- css中的线及vertical-align
行内元素格式化顺序: 相关概念: leading(行间距):指填充在两行文字间的铅条,等于line-height 和 font-size之差,其中一半leading加到文字上方,另一半leading ...
- html基础-a标签-img标签-绝对/相对路径(3)
美好的星期六,今天多写一点,争取早点写js这个有点小无聊. 一.先来讲点网页之间的跳转 (1).<a href=""></a> href="这里 ...
- python之迭代
1.何为迭代: 对于给定list或者tuple,通过for循环来遍历这个list或tuple,这种遍历我们称之为迭代(Iteration). 2.python中利用for...in语句来完成迭代语句: ...
- 手动解除联合的ArcGIS Server
ArcGIS Server可以通过和Portal联合,组建WebGIS系统. 假如已经联合的ArcGIS Server已经无法访问,例如服务器宕机了,或者网络断开了.需要手动解除联合的ArcGIS S ...