B. DZY Loves FFT
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

DZY loves Fast Fourier Transformation, and he enjoys using it.

Fast Fourier Transformation is an algorithm used to calculate convolution. Specifically, if ab and c are
sequences with length n, which are indexed from 0 to n - 1,
and

We can calculate c fast using Fast Fourier Transformation.

DZY made a little change on this formula. Now

To make things easier, a is a permutation of integers from 1 to n,
and b is a sequence only containing 0 and 1.
Given a and b, DZY needs your help to calculate c.

Because he is naughty, DZY provides a special way to get a and b.
What you need is only three integers ndx.
After getting them, use the code below to generate a and b.

//x is 64-bit variable;
function getNextX() {
x = (x * 37 + 10007) % 1000000007;
return x;
}
function initAB() {
for(i = 0; i < n; i = i + 1){
a[i] = i + 1;
}
for(i = 0; i < n; i = i + 1){
swap(a[i], a[getNextX() % (i + 1)]);
}
for(i = 0; i < n; i = i + 1){
if (i < d)
b[i] = 1;
else
b[i] = 0;
}
for(i = 0; i < n; i = i + 1){
swap(b[i], b[getNextX() % (i + 1)]);
}
}

Operation x % y denotes remainder after division x by y.
Function swap(x, y) swaps two values x and y.

Input

The only line of input contains three space-separated integers n, d, x (1 ≤ d ≤ n ≤ 100000; 0 ≤ x ≤ 1000000006).
Because DZY is naughty, x can't be equal to 27777500.

Output

Output n lines, the i-th line should contain an integer ci - 1.

Sample test(s)
input
3 1 1
output
1
3
2
input
5 4 2
output
2
2
4
5
5
input
5 4 3
output
5
5
5
5
4
Note

In the first sample, a is [1 3 2], b is [1
0 0], so c0 = max(1·1) = 1, c1 = max(1·0, 3·1) = 3, c2 = max(1·0, 3·0, 2·1) = 2.

In the second sample, a is [2 1 4 5 3], b is [1
1 1 0 1].

In the third sample, a is [5 2 1 4 3], b is [1
1 1 1 0].

这题解法‘朴素’得难以置信

转载自http://codeforces.com/blog/entry/12959

Firstly, you should notice that AB are given randomly.

Then there're many ways to solve this problem, I just introduce one of them.

This algorithm can get Ci one
by one. Firstly, choose an s. Then check if Ci equals
to n, n - 1, n - 2... n - s + 1. If none of is the answer, just calculate Ci by
brute force.

The excepted time complexity to calculate Ci - 1 is
around

where .

Just choose an s to make the formula as small as possible. The worst excepted number of operations is around tens of million.

对于每次询问:

先暴力枚举,看看答案在不在[n-s+1,n]中

否则暴力。

复杂度=O(s+(tot'0'/i)^s*tot'1')

(tot'0'/i)^s表示[n,n-s+1]中没有答案

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (100000+10)
#define MAXX (1000000006+1)
#define N_MAXX (27777500)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
ll n,d,x;
int i,a[MAXN],b[MAXN];
//x is 64-bit variable;
ll getNextX() {
x = (x * 37 + 10007) % 1000000007;
return x;
}
void initAB() {
for(i = 0; i < n; i = i + 1){
a[i] = i + 1;
}
for(i = 0; i < n; i = i + 1){
swap(a[i], a[getNextX() % (i + 1)]);
}
for(i = 0; i < n; i = i + 1){
if (i < d)
b[i] = 1;
else
b[i] = 0;
}
for(i = 0; i < n; i = i + 1){
swap(b[i], b[getNextX() % (i + 1)]);
}
} int q[MAXN]={0},h[MAXN]={0};
int main()
{
// freopen("FFT.in","r",stdin);
// freopen("FFT.out","w",stdout); cin>>n>>d>>x;
initAB(); Rep(i,n) if (b[i]) q[++q[0]]=i;
Rep(i,n) h[a[i]]=i; // Rep(i,n) cout<<a[i]<<' ';cout<<endl;
// Rep(i,n) cout<<b[i]<<' ';cout<<endl; Rep(i,n)
{
int s=30,ans=0;
Rep(j,30)
{
if (n-j<=0) break;
int t=h[n-j];
if (t<=i&&b[i-t]) {ans=n-j; break;}
}
if (!ans)
{
For(j,q[0])
{
int t=q[j];
if (t>i) break;
ans=max(ans,a[i-t]*b[t]);
}
} printf("%d\n",ans); } return 0;
}

版权声明:本文博主原创文章。博客,未经同意不得转载。

CF 444B(DZY Loves FFT-时间复杂度)的更多相关文章

  1. Codeforces #254 div1 B. DZY Loves FFT 暴力乱搞

    B. DZY Loves FFT 题目连接: http://codeforces.com/contest/444/problem/B Description DZY loves Fast Fourie ...

  2. CF 444C DZY Loves Physics(图论结论题)

    题目链接: 传送门 DZY Loves Chemistry time limit per test1 second     memory limit per test256 megabytes Des ...

  3. CF 445B DZY Loves Chemistry(并查集)

    题目链接: 传送门 DZY Loves Chemistry time limit per test:1 second     memory limit per test:256 megabytes D ...

  4. CF 444A(DZY Loves Physics-低密度脂蛋白诱导子图)

    A. DZY Loves Physics time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Cf 444C DZY Loves Colors(段树)

    DZY loves colors, and he enjoys painting. On a colorful day, DZY gets a colorful ribbon, which consi ...

  6. CF A. DZY Loves Hash

    A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  7. CF 445A(DZY Loves Chessboard-BW填充)

    A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...

  8. (CF)Codeforces445A DZY Loves Chessboard(纯实现题)

    转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接:http://codeforces.com/problemset/pro ...

  9. CF 445B(DZY Loves Chemistry-求连通块)

    B. DZY Loves Chemistry time limit per test 1 second memory limit per test 256 megabytes input standa ...

随机推荐

  1. IOS 与ANDROID框架及应用开发模式对照一

    IOS 和ANDROID操作系统都是眼下流行的移动操作系统,被移动终端和智能设备大量採用,两者都採用了先进的软件技术进行设计,为了方便应用开发两者都採用了先进的设计模式. 两者在框架设计上都採用了什么 ...

  2. 全栈JavaScript之路(十八)HTML5 自己定义数据属性

    HTML5 规范规定,用户能够为元素 自己定义非标准属性, 可是要加入 data- 前缀. 目的是为元素提供与页面渲染无关的信息.或者语义信息.这些属性名能够任意加入,仅仅要带上前缀 data- 开头 ...

  3. Linux如何查找大文件或目录总结及在全部目录中查找

    在Windows系统中,我们可以使用TreeSize工具查找一些大文件或文件夹,非常的方便高效,在Linux系统中,如何去搜索一些比较大的文件呢?下面我整理了一下在Linux系统中如何查找大文件或文件 ...

  4. visual studio 2013常用快捷键 VS2013快捷键大全

    visual studio 2013常用快捷键 VS2013快捷键大全   Visual Studio 2013 是一个基本完整的开发工具集,它包括了整个软件生命周期中所需要的大部分工具,如UML工具 ...

  5. HDU 4380 Farmer Greedy 计算几何+bitset

    枚举直线,对于直线的某个点在直线的左端还是右端,能够状压出一个数.用bitset记录. 然后三角形就是3个bitset&一下 #include <cstdio> #include ...

  6. ALV DataChange EVENT

    在CX项目中,根据需求,自定义一个表,维护供应商的银行账号信息,当输入供应商编号时,自动在供应商名称列里自动填写供应商名称,用到了ALV  DataChange 事件 ,下面是源代码: *&- ...

  7. 使用javascript开发2048

    嗯,团队队友开发了一个简单的2048...哈哈,没办法,这游戏那么疯狂,必须搞搞啦,大家能够直接粘贴代码到一个html文件,直接执行就可以 依赖文件:jquery,假设乜有,大家能够自己下载一份 &l ...

  8. PDO进行sql报表编制结果集介绍及操作(两)

    <span style="font-size:18px;">一个:运行准备好的语句和绑定参数insert try { $pdo=new PDO("mysql: ...

  9. 对于Hadoop的MapReduce编程makefile

    根据近期需要hadoop的MapReduce程序集成到一个大的应用C/C++书面框架.在需求make当自己主动MapReduce编译和打包的应用. 在这里,一个简单的WordCount1一个例子详细的 ...

  10. 加入指数(IOS开发)

    该指数是用来协助查询. 原则上: - 索引的标题是不完全一样的标题显示: - 指数应该具有一定的代表性,它可表示一组数据: - 假设索引列表视图.在一般情况下不再使用扩展视图. (easy指向) 会又 ...