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 ...
随机推荐
- [整理]EF6.X更新了什么(版本历史中文版)
下定决心以后用EF6.x版本了.想看看有什么更新特性,结果去人家github老巢一看,EF7 for vnext,顿时蛋疼了起来.想想国内这种技术氛围,有多少还在用ASP的,有多少还在用ADO.NET ...
- VisualVM监控远程阿里云主机
一.前言 使用VisualVM监控远程主机,主要是要在远程主机上部署JMX服务和jstat服务,jstat服务的部署花了我半天的时间,而且,网上的资基本都是缺胳膊少腿的,没有一篇是一个整体(行得通的) ...
- GitHub fork的使用
我的GitHub账号是lanshanxiao,fork的账号是king1ko1king,再此说明! fork的项目是:Class-for-Everyone-Java-Server- 作者源项目地址是: ...
- js小练习
1.题目:某班的成绩出来了,现在老师要把班级的成绩打印出来. 效果如下:xxx年xx月x日 星期x--班级总分为:81 格式要求:1.显示打印的日期.格式为类似“xxxx年xx月xx日 星期x”的当 ...
- Leet Palindrome Partitioning II
class Solution { public: int minCut(string s) { int len = s.length(); ]; char* s_dp = new char[len * ...
- xamarin.Android SQLite存储
在可移植类库 新建: using SQLite.Net.Interop; using System; using System.Collections.Generic; using System.Li ...
- LOJ#6035. 「雅礼集训 2017 Day4」洗衣服
传送门 先处理出每一件衣服最早什么时候洗完,堆+贪心即可 然后同样处理出每件衣服最早什么时候烘干 然后倒序相加取最大值 # include <bits/stdc++.h> using na ...
- 用js获取当前月份的天数
在获取每月天数的时候,一般都是存储到一个数组中进行获取,但是如果是二月份的话就需要首先判断是否闰年,再确定是28还是29了. js可以通过Date对象很方便的获取到每月的天数,在初始化Date对象时, ...
- leaflet 整合 esri
此 demo 通过 proj4js 将 leaflet 与 esri 整合起来,同时添加了 ClusteredFeatureLayer 的支持. 下载 <html> <head> ...
- WPF ListView 分组 Grouping
在Resource里定义数据源和分组字段: <CollectionViewSource x:Key="listData" Source="{Binding Cate ...