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;
}

Codeforces #254 div1 B. DZY Loves FFT 暴力乱搞的更多相关文章

  1. [Codeforces Round #254 div1] C.DZY Loves Colors 【线段树】

    题目链接:CF Round #254 div1 C 题目分析 这道题目是要实现区间赋值的操作,同时还要根据区间中原先的值修改区间上的属性权值. 如果直接使用普通的线段树区间赋值的方法,当一个节点表示的 ...

  2. VIJOS1476 旅行规划(树形Dp + DFS暴力乱搞)

    题意: 给出一个树,树上每一条边的边权为 1,求树上所有最长链的点集并. 细节: 可能存在多条最长链!最长链!最长链!重要的事情说三遍 分析: 方法round 1:暴力乱搞Q A Q,边权为正-> ...

  3. codeforces#FF DIV2C题DZY Loves Sequences(DP)

    题目地址:http://codeforces.com/contest/447/problem/C C. DZY Loves Sequences time limit per test 1 second ...

  4. Codeforces Round #FF 446A DZY Loves Sequences

    预处理出每一个数字能够向后延伸多少,然后尝试将两段拼起来. C. DZY Loves Sequences time limit per test 1 second memory limit per t ...

  5. Codeforces Round #254 (Div. 2) DZY Loves Chemistry【并查集基础】

    一开始不知道题意是啥意思,迟放进去反应和后放进去反应有什么区别 对于第三组数据不是很懂,为啥312,132的组合是不行的 后来发现这是一道考察并查集的题目 QAQ 怒贴代码: #include < ...

  6. HDU 5648 DZY Loves Math 暴力打表

    题意:BC 76 div1 1003有中文题面 然后官方题解看不懂,我就不说了,然后看别人的题解 因为询问i,j最大都是15000,所以可以预处理,res[i][j]代表答案,然后显然这是开不下的,也 ...

  7. codeforces#FF(div2) D DZY Loves Modification

    首先要知道选择行列操作时顺序是无关的 用两个数组row[i],col[j]分别表示仅选择i行能得到的最大值和仅选择j列能得到的最大值 这个用优先队列维护,没选择一行(列)后将这行(列)的和减去对应的n ...

  8. Codeforces Gym 100203G Good elements 暴力乱搞

    原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf 题解 考虑暴力的复杂度是O(n^3),所以 ...

  9. Codeforces 245G Suggested Friends 暴力乱搞

    G. Suggested Friends time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

随机推荐

  1. Vagrant 无法校验手动下载的 Homestead Box 版本

    起因 4年前电脑,配置不太好了,现有的 Homestead 运行起来太吃内存.在修改了 Homestead.yaml 文件里 memory 选项的内存配置为 1024 后,应用最新配置重启失败. 索性 ...

  2. sqlite3 的insert记录项思路

    sqlite3 的insert记录项思路 1.组合一个insert的sql语句 2.判断是否需要立即执行,若不是立刻执行的语句,则插入到待处理的链表中,供后续事务处理时提交.必须有一个专门线程来对事务 ...

  3. 2018ICPC南京网络赛

    2018ICPC南京网络赛 A. An Olympian Math Problem 题目描述:求\(\sum_{i=1}^{n} i\times i! \%n\) solution \[(n-1) \ ...

  4. Robotium测试套管理测试用例

    前提:已写好测试用例 新建个测试套MyTestSuite管理你需要跑的测试用例,或者将相同功能的测试用例归纳到一个测试套中 package com.robotium.test.testsuite; i ...

  5. MyEclipse中点击Deploy MyEclipse J2EE Project to Server无响应解决方法

    问题: MyEclipse中点击Deploy MyEclipse J2EE Project to Server无响应 解决方法: 如果工作空间的问题,那么需要删除你工作空间的一个文件就可以解决了.这个 ...

  6. 栈应用之 背包问题(Python 版)

    栈应用之 背包问题 背包问题描述:一个背包里可以放入重量为weight的物品,现有n件物品的集合s,其中物品的重量为别为w0,w1,...,wn-1.问题是能否从中选出若干件物品,其重量之和正好等于w ...

  7. 漂亮的SVG时钟

    漂亮的SVG时钟 效果图: 代码如下,复制即可使用: <!DOCTYPE html> <html lang="en"> <head> <m ...

  8. 【oracle】入门学习(二)

    oracle登录身份有三种:normal 普通身份sysdba 系统管理员身份sysoper 系统操作员身份每种身份对应不同的权限 sysdba权限:●启动和关闭操作●更改数据库状态为打开/装载/备份 ...

  9. Django数据库数据表操作

    建立表单 django通过设置类来快速建表,打开models.py 例: from __future__ import unicode_literals from django.db import m ...

  10. wordpress 常用函数-wpdb类

    与数据库建立接口 WordPress为用户提供了一系列用于数据库操作的函数类——wpdb.Wpdb类建立在Justin Vincent编写并维护的ezSQL类的基础上. 使用须知 不可直接调用wpdb ...