设一种方案里三角形上三个点的坐标分别为$(0,0),(-a,b),(c,d)$,则得到的平行四边形的面积为$ac+bd$。

设$d(n)$为$n$的约数个数,$D$为$d$的生成函数,则答案的生成函数$=D^2$。

先用线性筛$O(n)$求出$d$,再用FFT在$O(n\log n)$的时间内预处理出所有答案即可。

#include<cstdio>
#include<cmath>
#include<algorithm>
#define N 1048576
using namespace std;
typedef long long ll;
int n=500000,d[N],g[N],i,j,p[N],tot,T,l,r,ans;bool v[N>>1];ll f[N];
struct comp{
double r,i;comp(double _r=0,double _i=0){r=_r;i=_i;}
comp operator+(const comp x){return comp(r+x.r,i+x.i);}
comp operator-(const comp x){return comp(r-x.r,i-x.i);}
comp operator*(const comp x){return comp(r*x.r-i*x.i,r*x.i+i*x.r);}
}a[N];
const double pi=acos(-1.0);
void FFT(comp a[],int n,int t){
for(int i=1,j=0;i<n-1;i++){
for(int s=n;j^=s>>=1,~j&s;);
if(i<j)swap(a[i],a[j]);
}
for(int d=0;(1<<d)<n;d++){
int m=1<<d,m2=m<<1;
double o=pi/m*t;comp _w(cos(o),sin(o));
for(int i=0;i<n;i+=m2){
comp w(1,0);
for(int j=0;j<m;j++){
comp &A=a[i+j+m],&B=a[i+j],t=w*A;
A=B-t;B=B+t;w=w*_w;
}
}
}
if(t==-1)for(int i=0;i<n;i++)a[i].r/=n;
}
int main(){
for(d[1]=1,i=2;i<=n;i++){
if(!v[i])p[tot++]=i,d[i]=2,g[i]=1;
for(j=0;i*p[j]<=n&&j<tot;j++){
v[i*p[j]]=1;
if(i%p[j]){
d[i*p[j]]=d[i]*2;
g[i*p[j]]=1;
}else{
d[i*p[j]]=d[i]/(g[i]+1)*(g[i]+2);
g[i*p[j]]=g[i]+1;
break;
}
}
}
for(i=1;i<=n;i++)a[i].r=d[i];
FFT(a,N,1);
for(i=0;i<N;i++)a[i]=a[i]*a[i];
FFT(a,N,-1);
for(i=1;i<=n;i++)f[i]=(ll)(a[i].r+0.5);
for(scanf("%d",&T);T--;printf("%d %lld\n",ans,f[ans])){
scanf("%d%d",&l,&r);
for(ans=l;l<=r;l++)if(f[l]>f[ans])ans=l;
}
return 0;
}

  

BZOJ4115 : [Wf2015]Tile Cutting的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. bzoj4109: [Wf2015]Cutting Cheese

    Description 给定一个100*100*100(单位:毫米)的奶酪方块,这个奶酪含有n个球形小孔.现在要求将这个奶酪切成s片使得每片质量相等. Input 第一行包含两个整数n,s,表示奶酪有 ...

  3. Vector Tile

    Mapbox Vector Tile Specification A specification for encoding tiled vector data. <?XML:NAMESPACE ...

  4. OpenGL Insights 阅读有感 - Tile Based架构下的性能调校 翻译

    Performance Tunning for Tile-Based Architecture Tile-Based架构下的性能调校 by Bruce Merry GameKnife译 译序 在大概1 ...

  5. geotrellis使用(十八)导入多波段Tiff、读取多波段Tile

    Geotrellis系列文章链接地址http://www.cnblogs.com/shoufengwei/p/5619419.html 目录 前言 多波段数据导入 读取多波段瓦片 提取单波段 总结 一 ...

  6. [Python学习] python 科学计算库NumPy—tile函数

    在学习knn分类算法的过程中用到了tile函数,有诸多的不理解,记录下来此函数的用法.   函数原型:numpy.tile(A,reps) #简单理解是此函数将A进行重复输出 其中A和reps都是ar ...

  7. Python-Numpy函数-tile函数

    tile函数位于python模块 numpy.lib.shape_base中,他的功能是重复某个数组.比如tile(A,n),功能是将数组A重复n次,构成一个新的数组,我们还是使用具体的例子来说明问题 ...

  8. 百度地图TILE算法

    Creating primary keyvar LLBAND2 = [75, 60, 45, 30, 15, 0]; var LL2MC2 = [[-.0015702102444, 111320.70 ...

  9. How to tile small texture image onto page as its background

    You don’t need to set a big size image as the background of pages if the image is texture or uniform ...

随机推荐

  1. python---django请求-响应的生命周期(FBV和CBV含义)

    Django请求的生命周期是指:当用户在访问该url路径是,在服务器Django后台都发生了什么. 客户端发送Http请求给服务端,Http请求是一堆字符串,其内容是: 访问:http://crm.o ...

  2. Google-403-Forbidden

    Author:KillerLegend Date:2014.8.14 From:http://www.cnblogs.com/killerlegend/p/3913554.html www.googl ...

  3. bzoj千题计划268:bzoj3131: [Sdoi2013]淘金

    http://www.lydsy.com/JudgeOnline/problem.php?id=3131 如果已知 s[i]=j 表示有j个<=n数的数码乘积=i 那么就会有 s[a1]*s[a ...

  4. ASP.NET MVC学习(三)之过滤器Filter

    http://www.cnblogs.com/yaopengfei/p/7910763.html

  5. html5 canvas loading(这可怕的编辑器,自动把我的canvas转义了)---以前收藏的整理了一下

    /* super inefficient right now, could be improved */ var c = document.getElementById('canvasload'), ...

  6. 怎样提高WebService的性能

    服务器端WebService程序: using System.Runtime.Serialization.Formatters.Binary; using System.IO; using Syste ...

  7. Apache的对象复制详解

    BeanUtils.copyProperties 和 PropertyUtils.copyProperties 两个工具类都是对两个bean之前存在name相同的属性进行处理,无论是源bean或者目标 ...

  8. linux命令中which、whereis、locate有什么区别?

    1.find find是最常用和最强大的查找命令.它能做到实时查找,精确查找,但速度慢. find的使用格式如下: #find [指定目录] [指定条件] [指定动作] 指定目录:是指所要搜索的目录和 ...

  9. perl6: Proc::Async (new)

    # command with arguments my $proc = Proc::Async.new('whoami'); # subscribe to new output from out an ...

  10. How to become a successful bug bounty hunter

    出处:https://www.hackerone.com/blog/become-a-successful-bug-bounty-hunter 如果你梦想成为赏金猎人,你的梦想就会成真 - 不要把你的 ...