[BZOJ4731][UOJ#267]-魔法小程序-分治（FWT）思想

（卡常失败蹲墙角

题目

题目大意

a的长度不超过1e4；b,c的长度不超过1e6；保证1e9内有解

下面是自带大常数的代码

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;

int N , M , ws , remN ;
long long a[10005] , c[2000005] ;

void preWork(){
int tmp = M + 1 ; M = 0 ;
for( int i = 1 ; i <= tmp ; i ++ )
if( a[i] > 1 ) a[++M] = a[i] ;
int t = N ; ws = 1 ;
while( true ){
if( t < a[ws] ) break ;
else t /= a[ws] , ws ++ ;
} N = a[ws] = t + 1 ;
for( int i = 1 ; i < ws ; i ++ ) N *= a[i] ;
}

void dfs( int lf , int rg , int w ){
int siz = ( rg - lf + 1 ) / a[w] , i , j , ed ;
for( i = a[w] - 1 , ed = rg ; i >= 0 ; i -- , ed -= siz ){
if( i ) for( j = 0 ; j < siz ; j ++ )
c[ed-j] -= c[ed-j-siz] ;
if( w > 1 ) dfs( ed - siz + 1 , ed , w - 1 ) ;
}
}

void solve(){
dfs( 0 , N - 1 , ws ) ;
printf( "%d\n" , remN ) ;
for( int i = 0 ; i < remN ; i ++ ) printf( "%lld " , c[i] ) ;
}

template< typename T >
inline void read_( T &x ) {
int fix = 1 ;
x = 0 ; char ch = getchar() ;
while( ch < '0' || ch > '9' ){
if( ch == '-' ) fix = -1 ;
ch = getchar() ;
} while( ch >= '0' && ch <= '9' ) x = (x<<1) + (x<<3) + ch - '0' , ch = getchar() ;
x *= fix ;
}

int main(){
read_( M ) , printf( "%d\n" , M ) ;
a[M+1] = 100000000 ;
for( int i = 1 ; i <= M ; i ++ )
read_( a[i] ) , printf( "%lld " , a[i] ) ;
puts( "" ) ;
read_( N ) , remN = N ;
for( int i = 0 ; i < N ; i ++ ) read_( c[i] ) ;
preWork() ; solve() ;
}