【JZOJ4970】B 题解
来源:互联网 发布:正在准备windows请不要 编辑:程序博客网 时间:2024/05/20 07:15
题目出自C_SUNSHINE、Newnode
题目大意
题解
代码
#include<cmath>#include<cstdio>#include<algorithm>#define fo(i,a,b) for(int i=a;i<=b;i++)using namespace std;typedef long long LL;const int maxn=3e5+5, maxlen=6e5+5;const double pi=acos(-1), eps=1e-3;struct Z{ double x,y; Z(double X=0, double Y=0) {x=X, y=Y;}};Z operator +(const Z &a,const Z &b) {return Z(a.x+b.x,a.y+b.y);}Z operator -(const Z &a,const Z &b) {return Z(a.x-b.x,a.y-b.y);}Z operator *(const Z &a,const Z &b) {return Z(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);}int n,m,k,a[maxn][5],b[maxn];LL c[maxn];int len,rv[maxlen];Z W[maxlen],B[maxlen],A[maxlen],tp[maxlen];void DFT(Z *a,int sig){ fo(i,0,len-1) tp[rv[i]]=a[i]; for(int m=2; m<=len; m<<=1) { int hal=m>>1; fo(j,0,hal-1) { Z w=W[(j*(len/m)*sig+len)%len]; for(int k=j; k<len; k+=m) { Z u=tp[k], v=tp[k+hal]*w; tp[k]=u+v; tp[k+hal]=u-v; } } } fo(i,0,len-1) a[i]=tp[i];}void FFT(Z *a,Z *b){ DFT(a,1), DFT(b,1); fo(i,0,len-1) a[i]=a[i]*b[i]; DFT(a,-1); fo(i,0,len-1) a[i].x/=len;}int G[22]={5,127,509,2039,8191,32749,65521,131071,249989,249973,249971,2,3,2,7,17,2,17,3,2,5,6};int gx[maxn];void Pre(){ int g; fo(i,0,10) if (G[i]==n) {g=G[i+11]; break;} //本题加上样例共11个数据,每个n已列出 gx[0]=1; fo(i,1,n) gx[i]=gx[i-1]*g%n; for(len=1; len<2*n; len<<=1); for(int i=0, j, k, l; i<len; rv[k]=i++) { W[i]=Z(cos(i*2*pi/len),sin(i*2*pi/len)); for(j=i, k=0, l=1; l<len; j>>=1, l<<=1) k=(k<<1)+(j&1); }}int main(){ scanf("%d %d %d",&n,&m,&k); fo(j,0,m-1) fo(i,0,n-1) scanf("%d",&a[i][j]); fo(i,0,n-1) scanf("%d",&b[i]); Pre(); fo(i,0,n-1) c[i]+=a[0][b[0]]; fo(j,1,n-1) c[0]+=a[j][b[0]]; fo(i,0,m-1) { fo(j,0,len-1) A[j]=B[j]=Z(0,0); fo(j,1,n-1) { A[j-1]=Z(a[gx[n-j]][i],0); B[j]=(b[gx[j]]==i) ?Z(1,0) :Z(0,0) ; } FFT(A,B); fo(j,0,len-1) c[gx[j%(n-1)]]+=(LL)(A[j].x+0.5); } sort(c,c+n); printf("%lld\n",c[n-k]);}
0 0
- 【JZOJ4970】B 题解
- JZOJ4970. B
- 【题解】B-number
- A+B Problem 题解综述
- TCO13 Round 1B 题解
- 趣题 CodeForces 111B题解
- Codeforces B. Taxi 算法题解
- 题解 cf div2 193B
- 2016蓝桥杯省赛B组题解
- codeforces-158B-Taxi题解
- 2017 蓝桥杯B组省赛题解
- Codeforces 707B Bakery 题解
- Codeforces 298B Sail 题解
- CodeM资格赛B 锦标赛 题解
- Codeforces #521B: Cubes 题解
- a+b问题 题解 c++
- SER2016 DIV1 B, K 题解
- 17.10.21B组题解
- Sublime Text搭建PlantUML生成环境
- leetcode [Add Two Numbers]
- C++ 类访问控制(public/protected/private)
- spark | 做基本计算和批量提交
- linux进程间通信机制(消息队列,信号量,共享内存)
- 【JZOJ4970】B 题解
- where do i belong
- 理解RemoteViews
- 深度学习基础之 - 行人检测SSD
- Linux基本操作
- AOE网关键路径之白话解析
- 关于Mysql数据库的优化
- jdm分布式架构框架
- ICPCCamp2017 Day 4 A The Catcher in the Rye(二分+光的折射定律)