-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfact.cpp
More file actions
75 lines (62 loc) · 1.72 KB
/
Copy pathfact.cpp
File metadata and controls
75 lines (62 loc) · 1.72 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <bits/stdc++.h>
using i64 = long long;
constexpr int MAXN = 1e6 + 10, mod = 1e9 + 7;
int nums[MAXN], n;
using pt = std::pair<int, int>;
i64 qpow(i64 x, i64 p) {
i64 ret = 1;
while (p) {
if (p & 1)ret = ret * x % mod;
p >>= 1;
x = x * x % mod;
}
return ret;
}
#define inv(x) qpow(x,mod-2)
std::vector<int> fact(1, 1);
std::vector<int> inv_fact(1, 1);
auto get_fact(int x, bool inv = 0) {
while ((int)fact.size() < x + 1) {
fact.push_back(1ll * fact.back() * fact.size() % mod);
inv_fact.push_back(inv(fact.back()));
}
return (inv ? inv_fact[x] : fact[x]);
}
auto get_inv_fact(int x) { return get_fact(x, 1); }
i64 C(int n, int k) {
if (k<0 || k>n)return 0;
return 1ll * get_fact(n) * get_inv_fact(k) % mod * get_inv_fact(n - k) % mod;
}
i64 A(int n, int k) {
return 1ll * get_fact(n) * get_inv_fact(n - k) % mod;
}
i64 F(int n) { return get_fact(n); }
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0), std::cout.tie(0);
std::cout << inv(10);
return 0;
}
std::vector<int> adj[MAXN];
int depth[MAXN], lg[MAXN], p[MAXN][30];
int lca(int x, int y) {
if (depth[x] < depth[y])std::swap(x, y);
while (depth[x] > depth[y])
x = p[x][lg[depth[x] - depth[y]] - 1];
if (x == y)return x;
for (int k = lg[depth[x]] - 1;k >= 0;--k)
if (p[x][k] != p[y][k])
x = p[x][k], y = p[y][k];
return p[x][0];
}
void dfs(int x, int par) {
p[x][0] = par;
depth[x] = depth[par] + 1;
for (int i = 1;i <= lg[depth[x]];++i)
p[x][i] = p[p[x][i - 1]][i - 1];
for (int nxt : adj[x])if (nxt != par)dfs(nxt, x);
}
void init() {
for (int i = 1;i <= n;++i)
lg[i] = lg[i >> 1] + 1;
}