QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#670486 | #5746. DAG Generation | propane | AC ✓ | 35ms | 6752kb | C++20 | 3.2kb | 2024-10-23 21:53:47 | 2024-10-23 21:53:48 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<stdint.h>
using namespace std;
using LL = long long;
const int maxn = 2e5 + 5, mod = 1e9 + 9;
template<const int T>
struct ModInt {
const static int mod = T;
int x;
ModInt(int x = 0) : x(x % mod) {}
ModInt(long long x) : x(int(x % mod)) {}
int val() { return x; }
ModInt operator + (const ModInt &a) const { int x0 = x + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
ModInt operator - (const ModInt &a) const { int x0 = x - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
ModInt operator * (const ModInt &a) const { return ModInt(1LL * x * a.x % mod); }
ModInt operator / (const ModInt &a) const { return *this * a.inv(); }
bool operator == (const ModInt &a) const { return x == a.x; };
bool operator != (const ModInt &a) const { return x != a.x; };
void operator += (const ModInt &a) { x += a.x; if (x >= mod) x -= mod; }
void operator -= (const ModInt &a) { x -= a.x; if (x < 0) x += mod; }
void operator *= (const ModInt &a) { x = 1LL * x * a.x % mod; }
void operator /= (const ModInt &a) { *this = *this / a; }
friend ModInt operator + (int y, const ModInt &a){ int x0 = y + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
friend ModInt operator - (int y, const ModInt &a){ int x0 = y - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
friend ModInt operator * (int y, const ModInt &a){ return ModInt(1LL * y * a.x % mod);}
friend ModInt operator / (int y, const ModInt &a){ return ModInt(y) / a;}
friend ostream &operator<<(ostream &os, const ModInt &a) { return os << a.x;}
friend istream &operator>>(istream &is, ModInt &t){return is >> t.x;}
ModInt pow(int64_t n) const {
ModInt res(1), mul(x);
while(n){
if (n & 1) res *= mul;
mul *= mul;
n >>= 1;
}
return res;
}
ModInt inv() const {
int a = x, b = mod, u = 1, v = 0;
while (b) {
int t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
if (u < 0) u += mod;
return u;
}
};
using mint = ModInt<mod>;
mint fact[maxn], invfact[maxn];
mint pow2[maxn], pre[maxn];
void init(){
fact[0] = invfact[0] = 1;
for(int i = 1; i < maxn; i++) fact[i] = fact[i - 1] * i;
invfact[maxn - 1] = fact[maxn - 1].inv();
for(int i = maxn - 2; i; i--)
invfact[i] = invfact[i + 1] * (i + 1);
pow2[0] = 1;
for(int i = 1; i < maxn; i++) pow2[i] = pow2[i - 1] * 2;
pre[0] = 1;
for(int i = 1; i < maxn; i++) pre[i] = pre[i - 1] * (pow2[i] - 1);
}
inline mint C(int a, int b){
if (a < 0 || b < 0 || a < b) return 0;
return fact[a] * invfact[b] * invfact[a - b];
}
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
init();
int T;
cin >> T;
while(T--){
int n;
cin >> n;
mint t = pre[n] / mint(2).pow(1LL * n * (n - 1)) * invfact[n];
cout << 1 - t << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 6744kb
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: 6752kb
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: 35ms
memory: 6748kb
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