CF 444B(DZY Loves FFT-时间复杂度)
1 second
256 megabytes
standard input
standard output
DZY loves Fast Fourier Transformation, and he enjoys using it.
Fast Fourier Transformation is an algorithm used to calculate convolution. Specifically, if a, b 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 n, d, x.
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.
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 n lines, the i-th line should contain an integer ci - 1.
- 3 1 1
- 1
- 3
- 2
- 5 4 2
- 2
- 2
- 4
- 5
- 5
- 5 4 3
- 5
- 5
- 5
- 5
- 4
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 A, B 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-时间复杂度)的更多相关文章
- Codeforces #254 div1 B. DZY Loves FFT 暴力乱搞
B. DZY Loves FFT 题目连接: http://codeforces.com/contest/444/problem/B Description DZY loves Fast Fourie ...
- CF 444C DZY Loves Physics(图论结论题)
题目链接: 传送门 DZY Loves Chemistry time limit per test1 second memory limit per test256 megabytes Des ...
- CF 445B DZY Loves Chemistry(并查集)
题目链接: 传送门 DZY Loves Chemistry time limit per test:1 second memory limit per test:256 megabytes D ...
- CF 444A(DZY Loves Physics-低密度脂蛋白诱导子图)
A. DZY Loves Physics time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Cf 444C DZY Loves Colors(段树)
DZY loves colors, and he enjoys painting. On a colorful day, DZY gets a colorful ribbon, which consi ...
- CF A. DZY Loves Hash
A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- CF 445A(DZY Loves Chessboard-BW填充)
A. DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input stand ...
- (CF)Codeforces445A DZY Loves Chessboard(纯实现题)
转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接:http://codeforces.com/problemset/pro ...
- CF 445B(DZY Loves Chemistry-求连通块)
B. DZY Loves Chemistry time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- vs2008+opencv2.4.9 +win7X64位系统 2.
小编用自身血淋淋的例子,来给大家做个参考,共耗时近2天时间,终于屈服于安装vs2010,然后配置成功了.但是在这个配置成功后,我终于发现了我08配置不成功的原因,写下心得,供各位参考 1.准备工具 v ...
- 风起看云涌,叶落品人生 - Google 搜索
风起看云涌,叶落品人生 - Google 搜索 风起看云涌,叶落品人生
- Android模拟器设置竖屏
使用Android模拟器測试自己开发的程序时,有时候会发现屏幕为横屏显示,查看效果非常不方便. 这里记录了一种禁止横屏的方法. 在文件 Mainfest.xml 中,在须要禁止横屏的 activit ...
- Jndi使用好处,与简单实例【Tomcat】
JNDI学习总结(一)——JNDI数据源的配置 一.数据源的由来 在Java开发中,使用JDBC操作数据库的四个步骤如下: ①加载数据库驱动程序(Class.forName("数据库驱动 ...
- Java调用摄像头截图
使用webcam-capture替换JMF调用摄像头 最近有个需要通过java调用摄像头,并截图的需求,在网上找了下资料,大部分是用一个叫jmf的库,但是jmf已经几百年没有更新,用起来各种问题.后来 ...
- Hot Days Codeforces Round #132 (Div. 2) D(贪婪)
Description The official capital and the cultural capital of Berland are connected by a single road ...
- BZOJ 3531: [Sdoi2014]旅游
职务地址:http :// www . lydsy . com / JudgeOnline / problem . php ? id = 3531 标题效果:看到原来的标题. 算法讨论:树链拆分. 就 ...
- jdbc初步(转)
1. Jdbc的六个编程步骤 1. 注册一个驱动 注册驱动程序有三种方式: 方式一:Class.forName(“oracle.jdbc.driver.OracleDriver”); JAVA 规范中 ...
- 数据库连接技术之OLE DB
之前的博客介绍了ODBC和JDBC.这次简单的介绍一下OLE DB.ODBC的总结不知道是没贴到博客上还是不在这个博客上,我再找找,没有的话我再补充到时候.好了.開始吧. 回想 之前呢介绍过了ODBC ...
- 讨论asp.net通过机器cookie仿百度(google)实现搜索input搜索提示弹出框自己主动
为实现自己主动弹出通过用户输入关键词相关的搜索结果,在这里,我举两个解决方案,对于两个不同的方案. 常用的方法是建立一个用户数据库中查找关系表.然后输入用户搜索框keyword异步调用数据表中的相关数 ...