QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#120391#5746. DAG GenerationUrgantTeam#AC ✓40ms4692kbC++231.4kb2023-07-06 17:35:022023-07-06 17:35:05

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 17:35:05]
  • 评测
  • 测评结果:AC
  • 用时:40ms
  • 内存:4692kb
  • [2023-07-06 17:35:02]
  • 提交

answer

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long double ld;
typedef long long ll;

const int MOD = (int) 1e9 + 9;
const int MAXN = 100000;

int fact[MAXN + 5], revfact[MAXN + 5], dp[MAXN + 5];

int binpow(int x, ll step)
{
 	int res = 1;
 	while (step > 0)
 	{
 	 	if (step & 1) res = (ll) res * x % MOD;
 	 	x = (ll) x * x % MOD;
 	 	step /= 2;
 	}
 	return res;
}

int rev(int x)
{
 	return binpow(x, MOD - 2);
}

int main()
{
 	//freopen("input.txt", "r", stdin);
 	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0); cin.tie(0);

	int test;
	cin >> test;

	fact[0] = 1;
	for (int i = 1; i <= MAXN; i++) fact[i] = (ll) fact[i - 1] * i % MOD;
	revfact[MAXN] = rev(fact[MAXN]);
	for (int i = MAXN - 1; i >= 0; i--) revfact[i] = (ll) revfact[i + 1] * (i + 1) % MOD;

	int mn = 1;
	int zn = rev(2);

	dp[0] = 1;
	for (int i = 1; i <= MAXN; i++)
	{
	 	mn = (ll) mn * zn % MOD;
	 	int sk = (1 - mn + MOD) % MOD;
	 	dp[i] = (ll) 2 * dp[i - 1] * sk % MOD;
	}

	for (int rep = 1; rep <= test; rep++)
	{
		int n;
		cin >> n;
		
		int zn = revfact[n];
		int ch2 = binpow(2, (ll) n * (n - 1) / 2);
		int zn2 = rev(ch2);

		int vc = (ll) zn * zn2 % MOD * dp[n] % MOD;
		int ans = (1 - vc + MOD) % MOD;
		cout << ans << '\n';
	}	

	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 4652kb

input:

4
1
2
3
100

output:

0
375000004
117187502
778748905

result:

ok 4 number(s): "0 375000004 117187502 778748905"

Test #2:

score: 0
Accepted
time: 3ms
memory: 4692kb

input:

5
1
2
3
4
5

output:

0
375000004
117187502
213897708
995024095

result:

ok 5 number(s): "0 375000004 117187502 213897708 995024095"

Test #3:

score: 0
Accepted
time: 40ms
memory: 4544kb

input:

100000
64268
66535
9758
42907
84212
83488
27748
86198
80658
11614
93419
2528
96160
79473
83517
43109
37111
46603
93665
54540
84236
62717
24719
57225
8333
15728
40821
31719
13096
75018
76890
46244
75863
59618
67460
10326
84775
11276
83363
72071
9353
94316
9469
3969
78568
53071
96835
50125
2728
46756
...

output:

517835222
425525315
415451955
804144524
465143750
248034271
13166687
703325946
341000020
13797696
905521918
608927142
591090671
501585335
146368913
172358003
116621710
241875456
448868678
155749600
350155635
599343092
400133403
78229211
452768218
582618783
811512224
912730301
470660521
250329917
370...

result:

ok 100000 numbers