[JZOJ4203] Tree

Description

这里写图片描述
这里写图片描述

注意:本题空间限制为7168KB

Solution

我们按照每层操作涉及的区间长度来考虑,以包含1的区间为例,[1,1],[1,2],[1,4],[1,8]…..
可以发现这很像FFT中的蝴蝶变换
前半段转移是or,后半段转移是and

于是只需要开一个 2n 2 n 的数组,类似FFT的过程写出来,最后变换到顶层每个位置就是所对应的i
直接累加答案即可
复杂度 O(n2n) O ( n 2 n )

Code

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define LL unsigned long long
using namespace std;
const LL mo=4294967296;
unsigned int a[1048576],n,x,y,z,M;
int main()
{
    cin>>n>>a[0]>>x>>y>>z;
    M=1<<n;
    fo(i,1,M-1) a[i]=((LL)a[i-1]*(LL)x+(LL)y)%mo;
    int half=1;
    for(int m=2;m<=M;half=m,m<<=1)
    {
        fo(i,0,half-1)
        {
            for(int j=i;j<M;j+=m)
            {
                unsigned int v=a[j+half];
                a[j+half]=a[j]&v;
                a[j]=a[j]|v;
            }
        }
    }
    LL s=0,c1=1;
    fo(i,0,M-1)
    {
        s=(s+(LL)a[i]*c1%mo)%mo;
        c1=(LL)c1*(LL)z%mo;
    }
    printf("%llu\n",s);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值