其他分享
首页 > 其他分享> > Solution -「多校联训」朝鲜时蔬

Solution -「多校联训」朝鲜时蔬

作者:互联网

\(\mathcal{Description}\)

  Link.

  破案了,朝鲜时蔬 = 超现实树!(指写得像那什么一样的题面。

  对于整数集 \(X\),定义其 好子集 为满足 \(Y\subseteq X\land\left(\sum_{y\in Y}y\right)\mid\left(\sum_{x\in X}x\right)\) 的任意 \(Y\)。求 \(S_n=[1,n]\cap\mathbb N\) 的所有 \(m\) 阶子集中,包含 \(k\) 阶 好子集 数量最多的子集数。答案模 \((10^9+7)\)。

  \(k\le m\le n\le10^{12}\),\(m\le4\)。

\(\mathcal{Solution}\)

\[\mathfrak{\text{Defining }\LaTeX\text{ macros...}}\newcommand{\vct}[1]{\boldsymbol{#1}}\newcommand{\stir}[2]{\genfrac{\{}{\}}{0pt}{}{#1}{#2}}\newcommand{\opn}[1]{\operatorname{#1}}\newcommand{\lcm}[0]{\opn{lcm}}\newcommand{\sg}[0]{\opn{sg}}\newcommand{\dist}[0]{\opn{dist}}\newcommand{\lca}[0]{\opn{lca}}\newcommand{\floor}[2]{\left\lfloor\frac{#1}{#2}\right\rfloor}\newcommand{\ceil}[2]{\left\lceil\frac{#1}{#2}\right\rceil} \]

  令 \(f_{m,k}(n)\) 表示一组 \((m,k,n)\) 的答案,讨论之。


  放三道傻瓜题的原因是让选手享受这题一个情况 \(10\) 分的快乐吗?(

\(\mathcal{Code}\)

/*~Rainybunny~*/

// Have you MODULED correctly?

#ifndef RYBY
#pragma GCC optimize( "Ofast" )
#endif

#include <bits/stdc++.h>

#define rep( i, l, r ) for ( int i = l, rep##i = r; i <= rep##i; ++i )
#define per( i, r, l ) for ( int i = r, per##i = l; i >= per##i; --i )

typedef long long LL;

const int MOD = 1e9 + 7, INV2 = 500000004, INV3 = 333333336, INV4 = 250000002;
LL n;
int m, k;

inline LL sqrs( const LL x ) {
	return x % MOD * ( ( x + 1 ) % MOD ) % MOD * ( ( 2 * x + 1 ) % MOD ) % MOD
	  * INV2 % MOD * INV3 % MOD;
}

inline void solve11() {
	printf( "%lld\n", n % MOD );
}

inline void solve21() {
	LL ans = 0;
	for ( LL l = 1, r; l <= n; l = r + 1 ) {
		r = n / ( n / l );
		ans = ( ans + ( r - l + 1 ) % MOD
		  * ( ( n / l - 1 ) % MOD ) % MOD ) % MOD;
	}
	printf( "%lld\n", ans );
}

inline void solve22() {
	printf( "%lld\n", n % MOD * ( ( n - 1 ) % MOD ) % MOD * INV2 % MOD );
}

inline void solve31() {
	printf( "%lld\n", n / 3 % MOD );
}

inline void solve32() {
	LL ans = 0;
	for ( LL l = 1, r; l <= n; l = r + 1 ) {
		r = n / ( n / l );
		if ( l + ( l & 1 ) <= r - ( r & 1 ) ) { // even.
			LL s = l + ( l & 1 ) - 1 >> 1, t = r - ( r & 1 ) - 1 >> 1;
			LL c = ( r - ( r & 1 ) - ( l + ( l & 1 ) ) >> 1 ) + 1;
			ans = ( ans + n / l % MOD * ( ( s + t ) % MOD ) % MOD
			  * ( c % MOD ) % MOD * INV2 % MOD ) % MOD;
		}
		if ( l + !( l & 1 ) <= r - !( r & 1 ) ) { // odd.
			LL s = l + !( l & 1 ) - 1 >> 1, t = r - !( r & 1 ) - 1 >> 1;
			LL c = ( r - !( r & 1 ) - ( l + !( l & 1 ) ) >> 1 ) + 1;
			ans = ( ans + n / l % MOD * ( ( s + t ) % MOD ) % MOD
			  * ( c % MOD ) % MOD * INV2 % MOD ) % MOD;
		}
	}
	printf( "%lld\n", ans );
}

inline void solve33() {
	printf( "%lld\n", n % MOD * ( ( n - 1 ) % MOD ) % MOD
	  * ( ( n - 2 ) % MOD ) % MOD * INV2 % MOD * INV3 % MOD );
}

inline void solve41() {
	if ( n <= 5 ) return void( puts( "1" ) );
	printf( "%lld\n", ( n / 6 + n / 9 + n / 10
	  + n / 12 + n / 15 + n / 21 ) % MOD );
}

inline void solve42() {
	static const int SMA[] = { 1, 1, 1, 3, 6, 9, 10 };
	if ( n <= 10 ) return void( printf( "%d\n", SMA[n - 4] ) );
	printf( "%lld\n", ( ( n / 11 ) + ( n / 29 ) ) % MOD );
}

inline void solve43() {
	if ( n == 4 ) return void( puts( "1" ) );
	if ( n == 5 ) return void( printf( "%lld\n", n % MOD ) );
	
	LL ans = 0; // (-MOD,MOD) !!!
	for ( LL l = 6, r; l <= n; l = r + 1 ) {
		r = n / ( n / l );
		LL a = ( sqrs( r - 1 ) - sqrs( l - 2 ) ) % MOD;
		LL b = ( l + r - 2 ) % MOD
		  * ( ( r - l + 1 ) % MOD ) % MOD * INV2 % MOD;
		LL c = 0;
		if ( l + ( l & 1 ) <= r - ( r & 1 ) ) { // even.
			LL s = l + ( l & 1 ) >> 1, t = r - ( r & 1 ) >> 1;
			LL k = ( r - ( r & 1 ) - ( l + ( l & 1 ) ) >> 1 ) + 1;
			c = ( c + ( s + t ) % MOD * ( k % MOD ) % MOD * INV2 % MOD ) % MOD;
		}
		if ( l + !( l & 1 ) <= r - !( r & 1 ) ) { // odd.
			LL s = l + !( l & 1 ) + 1 >> 1, t = r - !( r & 1 ) + 1 >> 1;
			LL k = ( r - !( r & 1 ) - ( l + !( l & 1 ) ) >> 1 ) + 1;
			c = ( c + ( s + t ) % MOD * ( k % MOD ) % MOD * INV2 % MOD ) % MOD;
		}
		ans = ( ans + ( n / l ) % MOD * ( ( a - b ) % MOD * INV2 % MOD
		  - ( 3 * c ) % MOD + 3 * ( r - l + 1 ) % MOD
		  + 2 * ( r / 3 - ( l - 1 ) / 3 ) % MOD ) % MOD
		  * INV2 % MOD * INV3 % MOD ) % MOD;
	}
	printf( "%lld\n", ( ans % MOD + MOD ) % MOD );
}

inline void solve44() {
	printf( "%lld\n", n % MOD * ( ( n - 1 ) % MOD ) % MOD
	  * ( ( n - 2 ) % MOD ) % MOD * ( ( n - 3 ) % MOD ) % MOD
	  * INV2 % MOD * INV3 % MOD * INV4 % MOD );
}

int main() {
	freopen( "vegetable.in", "r", stdin );
	freopen( "vegetable.out", "w", stdout );
	
	scanf( "%lld %d %d", &n, &m, &k );
	
	if ( m == 1 ) return solve11(), 0;
	if ( m == 2 ) {
		if ( k == 1 ) return solve21(), 0;
		if ( k == 2 ) return solve22(), 0;
	}
	if ( m == 3 ) {
		if ( k == 1 ) return solve31(), 0;
		if ( k == 2 ) return solve32(), 0;
		if ( k == 3 ) return solve33(), 0;
	}
	if ( m == 4 ) {
		if ( k == 1 ) return solve41(), 0;
		if ( k == 2 ) return solve42(), 0;
		if ( k == 3 ) return solve43(), 0;
		if ( k == 4 ) return solve44(), 0;
	}
	return 0;
}

标签:return,floor,LL,时蔬,Solution,INV2,联训,frac,MOD
来源: https://www.cnblogs.com/rainybunny/p/15376162.html