UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202392#3537. 序列smallstone100454ms15288kbC++112.1kb2024-02-15 11:45:532024-02-15 12:37:30

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
//using LL = __int128
#define N 400010
#define mod 1000000007ll
ll n, a[N], bu[N], ans[N], fac[N] = {1}, inv[N], sum[N], p[N] = {1};
ll bigmul(ll a, ll b, ll m) {
	return a * b % m;
}
ll qpow(ll x, ll y) {
	ll ans = 1, res = x % mod ;
	while(y) {
		if(y & 1)
			ans = bigmul(ans, res, mod);
		res = bigmul(res, res, mod);
		y >>= 1 ;
	}
	return ans;
}
ll c(ll x, ll y) {
	if(x < y)
		return 0;
	//cout << "c(" << x << ", " << y << ") = " << fac[x] << "-" << inv[y] << "-" << inv[x - y] << "\n";
	return fac[x] * inv[y] % mod * inv[x - y] % mod;
}
int main() {
	//freopen("ex_seq3.out", "w", stdin);
	for(ll i = 1 ; i <= N - 10 ; i++)
		p[i] = p[i - 1] * 2 % mod;
	scanf("%lld", &n);
	for(ll i = 1 ; i <= n ; i++) {
		scanf("%lld", a + i);
		bu[a[i]]++;
	}
	for(ll i = 1 ; i <= N - 10 ; i++)
		fac[i] = fac[i - 1] * i % mod;
	//*
	inv[N - 10] = qpow(fac[N - 10], mod - 2);
	//cout << inv[n] << "\n";
	for(ll i = N - 11 ; i >= 0 ; i--) {
		inv[i] = (i + 1) * inv[i + 1] % mod;
		//cout << inv[i] << " " << inv[i] * fac[i] % mod << "\n";
		//cout << inv[i] - qpow(fac[i], mod - 2) << "\n";
	}
	//*/
	bool bj = true;
	for(int i = 1 ; i <= n ; i++) {
		if(!bu[i])
			bj = false;
		//bu[i] += bu[i - 1];
		//sum[i] = bu[i] + sum[i - 1];
	}
	//*
	if(bj){
		ll ans = 0;
		for(ll i = n, t = 1 ; i ; i--, t = (t * 2) % mod){
			ans += t;
			ans %= mod;
		}
		printf("%lld", ans);
		exit(0);
	}
	/*
	for(int i = 1 ; i <= n ; i++)
		for(int j = i ; j <= sum[i] ; j++)
			for(int x = 0 ; x <= bu[i] ; x++){
				f[i][j] += (f[i - 1][j - x] + (j - x <= i && i <= j)) * c(bu[i], x);
				f[i][j] %= mod;
			}
	for(int k = 1 ; k <= n ; k++)
		for(int i = 1 ; i <= sum[k] ; i++){
			cout << f[k][i] << " \n"[i == sum[k]];
		}
	//*/
	sort(a + 1, a + 1 + n);
	for(ll i = 1 ; i <= n ; i++) {
		ans[i] = c(i - 1, a[i] - 1) * p[n - i] % mod;
		//cout << i << " " << ans[i] << "\n";
	}
	ll ans1 = 0;
	for(int i = 1 ; i <= n ; i++)
		ans1 = (ans1 + ans[i]) % mod;
	printf("%lld", ans1);
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 5
Accepted
time: 4ms
memory: 10596kb

input:

15 8 6 14 11 4 9 15 14 15 9 14 12 3 6 13

output:

1

result:

ok single line: '1'

Test #2:

score: 5
Accepted
time: 12ms
memory: 10596kb

input:

15 10 9 3 3 2 4 10 10 14 13 14 3 10 1 10

output:

46732

result:

ok single line: '46732'

Test #3:

score: 5
Accepted
time: 0ms
memory: 10600kb

input:

15 3 4 2 13 8 15 8 13 11 6 3 2 9 9 3

output:

32999

result:

ok single line: '32999'

Test #4:

score: 5
Accepted
time: 10ms
memory: 10596kb

input:

15 9 9 10 12 8 8 11 14 6 5 6 13 9 11 6

output:

288

result:

ok single line: '288'

Test #5:

score: 5
Accepted
time: 7ms
memory: 10596kb

input:

15 3 2 15 6 12 1 15 12 5 10 13 4 5 9 6

output:

38637

result:

ok single line: '38637'

Test #6:

score: 5
Accepted
time: 9ms
memory: 10648kb

input:

2000 25 484 1870 583 668 1298 1198 1838 1248 567 1864 1118 1554 564 1303 1047 1053 960 1729 1932 196...

output:

385129497

result:

ok single line: '385129497'

Test #7:

score: 5
Accepted
time: 14ms
memory: 10644kb

input:

2000 34 1417 31 1345 46 1660 875 1911 518 1609 41 1402 1088 1120 1649 1214 1927 1602 645 589 162 161...

output:

44472341

result:

ok single line: '44472341'

Test #8:

score: 5
Accepted
time: 9ms
memory: 10644kb

input:

2000 1024 1019 1146 1656 1906 411 258 1698 1376 1730 998 806 1959 1347 1797 1035 1464 216 179 1618 1...

output:

477127421

result:

ok single line: '477127421'

Test #9:

score: 5
Accepted
time: 13ms
memory: 10648kb

input:

2000 904 1371 1577 708 325 661 1064 1928 1337 1980 1275 583 1688 1560 257 1281 789 1589 787 1875 176...

output:

409666345

result:

ok single line: '409666345'

Test #10:

score: 5
Accepted
time: 9ms
memory: 10644kb

input:

2000 736 1091 1058 755 653 1211 205 1131 1494 1153 1816 35 1455 1411 663 874 1851 510 494 1962 1668 ...

output:

962962192

result:

ok single line: '962962192'

Test #11:

score: 5
Accepted
time: 28ms
memory: 13712kb

input:

200000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ...

output:

175895281

result:

ok single line: '175895281'

Test #12:

score: 5
Accepted
time: 33ms
memory: 13712kb

input:

200000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ...

output:

175895281

result:

ok single line: '175895281'

Test #13:

score: 5
Accepted
time: 32ms
memory: 13712kb

input:

200000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ...

output:

175895281

result:

ok single line: '175895281'

Test #14:

score: 5
Accepted
time: 32ms
memory: 13712kb

input:

200000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ...

output:

175895281

result:

ok single line: '175895281'

Test #15:

score: 5
Accepted
time: 28ms
memory: 13712kb

input:

200000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ...

output:

175895281

result:

ok single line: '175895281'

Test #16:

score: 5
Accepted
time: 40ms
memory: 15284kb

input:

200000 166590 20849 126411 133366 36333 18332 172547 57470 145664 110620 37556 113908 123961 195783 ...

output:

426667668

result:

ok single line: '426667668'

Test #17:

score: 5
Accepted
time: 41ms
memory: 15284kb

input:

200000 169672 89425 34124 104143 93288 70493 61048 192113 292 79680 52311 52428 142153 144390 91082 ...

output:

462091315

result:

ok single line: '462091315'

Test #18:

score: 5
Accepted
time: 38ms
memory: 15284kb

input:

200000 184655 166160 76584 90054 51931 198051 58297 90616 113758 140994 13505 93311 4251 53203 31173...

output:

697086497

result:

ok single line: '697086497'

Test #19:

score: 5
Accepted
time: 48ms
memory: 15288kb

input:

200000 80079 124181 170434 31758 99420 136529 30673 145269 111549 163488 37324 132314 122035 39583 1...

output:

512465333

result:

ok single line: '512465333'

Test #20:

score: 5
Accepted
time: 47ms
memory: 15284kb

input:

200000 83684 149238 26953 164914 50552 195667 72114 83448 182923 88943 196844 92388 134484 105724 63...

output:

335807702

result:

ok single line: '335807702'

Extra Test:

score: 0
Extra Test Passed