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 ...
随机推荐
- 二十一、curator recipes之TreeCache
简介 curator的TreeCache允许对某个路径的数据和路径变更以及其下所有子孙节点的数据和路径变更进行监听. 官方文档:http://curator.apache.org/curator-re ...
- 浅谈FIle协议与Http协议及区别
背景 先看三段代码: index.html: <!DOCTYPE html> <html lang="en"> <head> <meta ...
- redis安装以及php扩展
启动安装: http://elain.blog.51cto.com/3339379/705846 redis下载: https://github.com/nicolasff/phpredis/do ...
- SQL Server 2017搭建主从备份
SQL Server 2017搭建主从¶ 关于日志传输¶ 和Oracle DG,Mysql主从一样,SQL Server也支持主从的高可用.进一步提高数据的安全性和业务的高可用.通过将主库上的日志传输 ...
- Visualizing MNIST with t-SNE, MDS, Sammon’s Mapping and Nearest neighbor graph
MNIST 可视化 Visualizing MNIST: An Exploration of Dimensionality Reduction At some fundamental level, n ...
- needPrint 不显示打印按钮
客户问题: 客户用的是needPrint 来显示打印按钮,现在访问不能显示后台提示有错误 打开控制台显示: java.security.AccessControlException: ...
- redis介绍(4)实战场景
redis我主要在两方面说明: 集群下的session的管理 Tomcat 与 DB之间缓存
- 探索ORM ————iBati(一)
ibatis iBATIS一词来源于“internet”和“abatis”的组合,是一个由Clinton Begin在2001年发起的开放源代码项目.最初侧重于密码软件的开发,现在是一个基于Jav ...
- Angular-学习。
今天刚学了点关于Angular的知识,就迫不及待的想跟大家来分享. 1.angular.extend ( )方法可以把一个或多个对象中的方法和属性扩展到一个目的对象中. <script typ ...
- 3.Spring MVC return url问题总结
一.return "cartSuccess" 和 return "redirect:/cart/cart.html" 的区别 二.return modelAnd ...