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

B. DZY Loves FFT

题目连接:

http://codeforces.com/contest/444/problem/B

Description

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.

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 Input

3 1 1

Sample Output

1
3
2

题意

类似于卷积的定义,c[i]=max a[j]b[i-j]

a[i]是1-n的排列,b[i]是01串

让你输出所有的c[i]

题解:

瞎JB暴力……

A数组我从大到小暴力就好了,如果算过了,那么就把这个点的位置删去。

这样数肯定越来越少的。

至于这个复杂度是多少,我也不知道……

反正过了,太谐了

代码

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

const int maxn = 100000 + 15;

int n , d , a[maxn] , b[maxn] , c[maxn] , sum[maxn];
long long x;
pair < int , int > p[maxn];
vector < int > vi;
tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbt;
tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> :: iterator it ;

long long getNextX(  ) {
 x = (x * 37 + 10007) % 1000000007;
 return x;
}


void initAB() {
int i;
 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 main( int argc,char *argv[] ){
    cin >> n >> d >> x;
	initAB();
	//for(int i = 0 ; i < n ; ++ i) cout << a[i] << " ";cout << endl;
	//for(int i = 0 ; i < n ; ++ i) cout << b[i] << " ";cout << endl;
	for(int i = 0 ; i < n ; ++ i) p[i].first = a[i] , p[i].second = i;
	sort( p , p + n );
	for(int i = 0 ; i < n ; ++ i) if( b[i] ) vi.push_back( i );
	sum[0] = b[0];
    for(int i = 1 ; i < n ; ++ i) sum[i] = sum[ i - 1 ] + b[i];
	for(int i = 0 ; i < n ; ++ i) rbt.insert( i );
	for(int i = n - 1 ; i >= 0 ; -- i){
		int idx = p[i].second;
		int num1 = sum[n - idx];
		int num2 = rbt.size() - rbt.order_of_key( idx );
		if( d <= 500 && num1 < num2 ){
			for(auto it : vi){
				if( it + idx > n ) break;
				c[it + idx] = max( c[it + idx] , p[i].first );
			}
		}else{
			it = rbt.lower_bound( idx );
			while( it != rbt.end() ){
				int pos = *it;
				int dis = pos - idx;
				if( b[dis] ){
					c[pos] = max( c[pos] , p[i].first);
					it = rbt.erase( it );
				}else ++ it;
			}
		}
	}
	for(int i = 0 ; i < n ; ++ i) printf("%d\n" , c[i]);
	return 0;
}
posted @ 2016-05-07 16:42  qscqesze  阅读(443)  评论(0编辑  收藏  举报