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.

  1. //x is 64-bit variable;
  2. function getNextX() {
  3. x = (x * 37 + 10007) % 1000000007;
  4. return x;
  5. }
  6. function initAB() {
  7. for(i = 0; i < n; i = i + 1){
  8. a[i] = i + 1;
  9. }
  10. for(i = 0; i < n; i = i + 1){
  11. swap(a[i], a[getNextX() % (i + 1)]);
  12. }
  13. for(i = 0; i < n; i = i + 1){
  14. if (i < d)
  15. b[i] = 1;
  16. else
  17. b[i] = 0;
  18. }
  19. for(i = 0; i < n; i = i + 1){
  20. swap(b[i], b[getNextX() % (i + 1)]);
  21. }
  22. }

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
  1. 3 1 1
output
  1. 1
  2. 3
  3. 2
input
  1. 5 4 2
output
  1. 2
  2. 2
  3. 4
  4. 5
  5. 5
input
  1. 5 4 3
output
  1. 5
  2. 5
  3. 5
  4. 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]中没有答案

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cstdlib>
  4. #include<algorithm>
  5. #include<functional>
  6. #include<iostream>
  7. #include<cmath>
  8. #include<cctype>
  9. #include<ctime>
  10. using namespace std;
  11. #define For(i,n) for(int i=1;i<=n;i++)
  12. #define Fork(i,k,n) for(int i=k;i<=n;i++)
  13. #define Rep(i,n) for(int i=0;i<n;i++)
  14. #define ForD(i,n) for(int i=n;i;i--)
  15. #define RepD(i,n) for(int i=n;i>=0;i--)
  16. #define Forp(x) for(int p=pre[x];p;p=next[p])
  17. #define Lson (x<<1)
  18. #define Rson ((x<<1)+1)
  19. #define MEM(a) memset(a,0,sizeof(a));
  20. #define MEMI(a) memset(a,127,sizeof(a));
  21. #define MEMi(a) memset(a,128,sizeof(a));
  22. #define INF (2139062143)
  23. #define F (100000007)
  24. #define MAXN (100000+10)
  25. #define MAXX (1000000006+1)
  26. #define N_MAXX (27777500)
  27. long long mul(long long a,long long b){return (a*b)%F;}
  28. long long add(long long a,long long b){return (a+b)%F;}
  29. long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
  30. typedef long long ll;
  31. ll n,d,x;
  32. int i,a[MAXN],b[MAXN];
  33. //x is 64-bit variable;
  34. ll getNextX() {
  35. x = (x * 37 + 10007) % 1000000007;
  36. return x;
  37. }
  38. void initAB() {
  39. for(i = 0; i < n; i = i + 1){
  40. a[i] = i + 1;
  41. }
  42. for(i = 0; i < n; i = i + 1){
  43. swap(a[i], a[getNextX() % (i + 1)]);
  44. }
  45. for(i = 0; i < n; i = i + 1){
  46. if (i < d)
  47. b[i] = 1;
  48. else
  49. b[i] = 0;
  50. }
  51. for(i = 0; i < n; i = i + 1){
  52. swap(b[i], b[getNextX() % (i + 1)]);
  53. }
  54. }
  55.  
  56. int q[MAXN]={0},h[MAXN]={0};
  57. int main()
  58. {
  59. // freopen("FFT.in","r",stdin);
  60. // freopen("FFT.out","w",stdout);
  61.  
  62. cin>>n>>d>>x;
  63. initAB();
  64.  
  65. Rep(i,n) if (b[i]) q[++q[0]]=i;
  66. Rep(i,n) h[a[i]]=i;
  67.  
  68. // Rep(i,n) cout<<a[i]<<' ';cout<<endl;
  69. // Rep(i,n) cout<<b[i]<<' ';cout<<endl;
  70.  
  71. Rep(i,n)
  72. {
  73. int s=30,ans=0;
  74. Rep(j,30)
  75. {
  76. if (n-j<=0) break;
  77. int t=h[n-j];
  78. if (t<=i&&b[i-t]) {ans=n-j; break;}
  79. }
  80. if (!ans)
  81. {
  82. For(j,q[0])
  83. {
  84. int t=q[j];
  85. if (t>i) break;
  86. ans=max(ans,a[i-t]*b[t]);
  87. }
  88. }
  89.  
  90. printf("%d\n",ans);
  91.  
  92. }
  93.  
  94. return 0;
  95. }

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

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. vs2008+opencv2.4.9 +win7X64位系统 2.

    小编用自身血淋淋的例子,来给大家做个参考,共耗时近2天时间,终于屈服于安装vs2010,然后配置成功了.但是在这个配置成功后,我终于发现了我08配置不成功的原因,写下心得,供各位参考 1.准备工具 v ...

  2. 风起看云涌,叶落品人生 - Google 搜索

    风起看云涌,叶落品人生 - Google 搜索 风起看云涌,叶落品人生

  3. Android模拟器设置竖屏

    使用Android模拟器測试自己开发的程序时,有时候会发现屏幕为横屏显示,查看效果非常不方便. 这里记录了一种禁止横屏的方法. 在文件  Mainfest.xml 中,在须要禁止横屏的 activit ...

  4. Jndi使用好处,与简单实例【Tomcat】

    JNDI学习总结(一)——JNDI数据源的配置 一.数据源的由来 在Java开发中,使用JDBC操作数据库的四个步骤如下:   ①加载数据库驱动程序(Class.forName("数据库驱动 ...

  5. Java调用摄像头截图

    使用webcam-capture替换JMF调用摄像头 最近有个需要通过java调用摄像头,并截图的需求,在网上找了下资料,大部分是用一个叫jmf的库,但是jmf已经几百年没有更新,用起来各种问题.后来 ...

  6. Hot Days Codeforces Round #132 (Div. 2) D(贪婪)

    Description The official capital and the cultural capital of Berland are connected by a single road ...

  7. BZOJ 3531: [Sdoi2014]旅游

    职务地址:http :// www . lydsy . com / JudgeOnline / problem . php ? id = 3531 标题效果:看到原来的标题. 算法讨论:树链拆分. 就 ...

  8. jdbc初步(转)

    1. Jdbc的六个编程步骤 1. 注册一个驱动 注册驱动程序有三种方式: 方式一:Class.forName(“oracle.jdbc.driver.OracleDriver”); JAVA 规范中 ...

  9. 数据库连接技术之OLE DB

    之前的博客介绍了ODBC和JDBC.这次简单的介绍一下OLE DB.ODBC的总结不知道是没贴到博客上还是不在这个博客上,我再找找,没有的话我再补充到时候.好了.開始吧. 回想 之前呢介绍过了ODBC ...

  10. 讨论asp.net通过机器cookie仿百度(google)实现搜索input搜索提示弹出框自己主动

    为实现自己主动弹出通过用户输入关键词相关的搜索结果,在这里,我举两个解决方案,对于两个不同的方案. 常用的方法是建立一个用户数据库中查找关系表.然后输入用户搜索框keyword异步调用数据表中的相关数 ...