QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#93795#5746. DAG Generationmaomao90#AC ✓41ms6548kbC++171.8kb2023-04-02 16:06:512023-04-02 16:06:51

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-02 16:06:51]
  • 评测
  • 测评结果:AC
  • 用时:41ms
  • 内存:6548kb
  • [2023-04-02 16:06:51]
  • 提交

answer


// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 200005;
const int MOD = 1000000009;

ll fpow(ll b, ll p) {
    ll res = 1;
    while (p) {
        if (p & 1) {
            res = res * b % MOD;
        }
        b = b * b % MOD;
        p >>= 1;
    }
    return res;
}

int t;
int n;
ll dp[MAXN];
ll fact[MAXN];

int main() {
#ifndef DEBUG
    ios::sync_with_stdio(0), cin.tie(0);
#endif
    dp[0] = 1;
    ll pw = 2;
    REP (i, 1, MAXN) {
        dp[i] = dp[i - 1] * (pw - 1) % MOD;
        pw = pw * 2 % MOD;
    }
    fact[0] = 1;
    REP (i, 1, MAXN) {
        fact[i] = fact[i - 1] * i % MOD;
    }
    cin >> t;
    while (t--) {
        cin >> n;
        cerr << dp[n] << '\n';
        cerr << fact[n] << ' ' << fpow(2, (ll) n * (n - 1) / 2) << '\n';
        cout << (1 + MOD - dp[n] * fact[n] % MOD * fpow(fact[n] * fpow(2, (ll) n * (n - 1) / 2) % MOD, 2 * (MOD - 2)) % MOD) % MOD << '\n';
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 6548kb

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: 5ms
memory: 6488kb

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: 41ms
memory: 6496kb

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