小于x的赋值为1,否则为0

区间等于k的个数

求0~n连续的n+1个k?

N<=1e5?

FFT!

考虑卷积建模:用下标相加实现转移到位,数值相乘类比乘法原理!

法一:

分治,然后FFT没了

法二:

不分治也可以!区间查询->前缀相减

ans[j-i]=f[j]*f[i],f[i]表示数值为i的前缀和个数

减法怎么办?
reverse变成加法!

i->n-i

ans[j-i]=f[j]*f[i]=f[j]*f'[n-i]

FFT一下,n+j-i位置的值就是ans辣

#include<bits/stdc++.h>
#define reg register int
#define il inline
#define numb (ch^'0')
using namespace std;
typedef long long ll;
il void rd(int &x){
char ch;x=;bool fl=false;
while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
for(x=numb;isdigit(ch=getchar());x=x*+numb);
(fl==true)&&(x=-x);
}
namespace Miracle{
const double Pi=acos(-);
const int N=2e5+;
struct po{
double x,y;
po(){}
po(double xx,double yy){
x=xx;y=yy;
}
po friend operator +(po a,po b){
return po(a.x+b.x,a.y+b.y);
}
po friend operator -(po a,po b){
return po(a.x-b.x,a.y-b.y);
}
po friend operator *(po a,po b){
return po(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);
}
}a[*N],b[*N];
int c[N],s[N];
int n,x;
int rev[*N];
ll ans[N];
void fft(po *f,int c){
for(reg i=;i<n;++i){
if(i<rev[i]) swap(f[i],f[rev[i]]);
}
for(reg p=;p<=n;p<<=){
po gen;int len=p/;
gen=po(cos(Pi/len),c*sin(Pi/len));
for(reg l=;l<n;l+=p){
po buf=po(1.0,0.0);
for(reg k=l;k<l+len;++k){
po tmp=f[k+len]*buf;
f[k+len]=f[k]-tmp;
f[k]=f[k]+tmp;
buf=buf*gen;
}
}
}
}
int main(){
rd(n);rd(x);
int lp=n;
for(reg i=;i<=n;++i) {
rd(c[i]);c[i]=c[i]<x;
s[i]=s[i-]+c[i];
++a[s[i]].x;
}
++a[s[]].x;
for(reg i=;i<=n;++i){
b[i].x=a[n-i].x;
}
int m;
for(m=*n,n=;n<=m;n<<=);
for(reg i=;i<n;++i){
rev[i]=(rev[i>>]>>)|((i&)?(n>>):);
}
// for(reg i=1;i<=lp;++i){
// cout<<c[i]<<" ";
// }cout<<endl;
// for(reg i=0;i<n;++i){
// cout<<a[i].x<<" ";
// }cout<<endl;
// for(reg j=0;j<n;++j){
// cout<<b[j].x<<" ";
// }cout<<endl;
fft(a,);
fft(b,);
for(reg i=;i<n;++i) b[i]=a[i]*b[i];
fft(b,-);
for(reg i=;i<=lp;++i) ans[i]=round(b[lp-i].x/n);
//cout<<" ans[0] "<<ans[0]<<endl;
ans[]=(ans[]+(lp+))/-(lp+);
for(reg i=;i<=lp;++i){
printf("%lld ",ans[i]);
}
return ;
} }
signed main(){
Miracle::main();
return ;
} /*
Author: *Miracle*
Date: 2018/12/27 9:01:58
*/

reverse想法比较有意思!

值得注意!

CF993E Nikita and Order Statistics的更多相关文章

  1. CF993E Nikita and Order Statistics 【fft】

    题目链接 CF993E 题解 我们记小于\(x\)的位置为\(1\),否则为\(0\) 区间由端点决定,转为两点前缀和相减 我们统计出每一种前缀和个数,记为\(A[i]\)表示值为\(i\)的位置出现 ...

  2. CF993E:Nikita and Order Statistics(FFT)

    Description 给你一个数组 $a_{1 \sim n}$,对于 $k = 0 \sim n$,求出有多少个数组上的区间满足:区间内恰好有 $k$ 个数比 $x$ 小.$x$ 为一个给定的数. ...

  3. CF993E Nikita and Order Statistics 多项式卷积 快速傅里叶变换

    题意: 给你一个数组a1~an,对于k=0~n,求出有多少个数组上的区间满足:区间内恰好有k个数比x小.x为一个给定的数.n<=10^5.值域没有意义. 分析: 大神们都说这道题是一个套路题,真 ...

  4. Codeforces 993E Nikita and Order Statistics [FFT]

    洛谷 Codeforces 思路 一开始想偏想到了DP,后来发现我SB了-- 考虑每个\(a_i<x\)的\(i\),记录它前一个和后一个到它的距离为\(L_i,R_i\),那么就有 \[ an ...

  5. [Codeforces 993E]Nikita and Order Statistics

    Description 题库链接 给你一个长度为 \(n\) 的序列 \(A\) ,和一个数 \(x\) ,对于每个 \(i= 0\sim n\) ,求有多少个非空子区间满足恰好有 \(i\) 个数 ...

  6. CLRS:median and order statistics

    //maximum and minimum     暴力遍历 O(n) //i-th element dicide and conquer random_selected_partition     ...

  7. Data Structure Binary Search Tree: Find k-th smallest element in BST (Order Statistics in BST)

    http://www.geeksforgeeks.org/find-k-th-smallest-element-in-bst-order-statistics-in-bst/ #include < ...

  8. cf22A Second Order Statistics(STL-UNIQUE的使用)

    题意: N个数,找出第二大的数.如果没有输出-1. 思路: UNIQUE的使用. 代码: int a[105]; int n; int main(){ cin>>n; rep(i,0,n- ...

  9. NOIWC前的交流题目汇总

    RT 2018.12.27 i207M:BZOJ 4695 最假女选手 以维护最大值为例,记录最大值和严格次大值和最大值的出现次数,然后取min的时候递归到小于最大值但大于次大值修改,这个就是最重要的 ...

随机推荐

  1. 通过 zxing 生成二维码

    二维码现在随处可见,在日常的开发中,也会经常涉及到二维码的生成,特别是开发一些活动或者推广方面的功能时,二维码甚至成为必备功能点.本文介绍通过 google 的 zxing 包生成带 logo 的二维 ...

  2. Linux命令应用大词典-第36章 密码和证书管理

    36.1 pwdhash:密码哈希生成器 36.2 mkpasswd:生成应用于用户的新密码 36.3 keytool:密钥和证书管理工具 36.4 certutil:证书服务器管理工具 36.5 v ...

  3. Python全栈 Web(概述、HTML基础语法)

    原文地址: https://yq.aliyun.com/articles/631222 ........................................................ ...

  4. JavaScript 作用域链范例

    函数在执行的过程中,先从自己内部找变量 如果找不到,再从创建当前函数所在的作用域去找,以此往上 注意找的是变量的当前状态 范例 例1 var a=1 function fn1() { function ...

  5. html常用小知识

    请求重定向:加载页面之后,除了用js做重定向之外,我们还可以直接用<meta>标签做重定向. <meta http-equiv="refresh" content ...

  6. 在linux下PHP和Mysql环境搞事情

    研发部门同事开发了一个接口管理辅助工具Shepherd,要求搭建在内网环境中,遇到点小问题记一下. 将开发的文件上传只web目录下,更改数据库ip,可以正常打开 登陆用户信息,此时需要连接数据库来验证 ...

  7. Line belt(三分镶嵌)

    In a two-dimensional plane there are two line belts, there are two segments AB and CD, lxhgww's spee ...

  8. HDU 3333 Turing Tree 线段树+离线处理

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3333 Turing Tree Time Limit: 6000/3000 MS (Java/Othe ...

  9. 《剑指offer》---顺时针打印矩阵

    本文算法使用python3实现 1. 问题1 1.1 题目描述:   输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 ...

  10. 关于CString总结

    前言:串操作是编程中最常用也最基本的操作之一. 做为VC程序员,无论是菜鸟或高手都曾用过CString.而且好像实际编程中很难离得开它(虽然它不是标准C++中的库).因为MFC中提供的这个类对 我们操 ...