-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyOfficialTemplate.cpp
137 lines (135 loc) · 2.71 KB
/
MyOfficialTemplate.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Created by Anushk Gautam on __/__/2021
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define ee cout << "\n"
#define sall(v) sort(v.begin(), v.end())
#define fo(i, n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define mpl map<ll, ll>
vector<ll> Tree;
void make_Tree(vector<ll> &v)
{
ll i;
ll N = v.size();
while (N & (N - 1))
N++;
v.resize(N);
Tree.resize(2 * N);
for (i = 0; i < N; i++)
{
Tree[N + i] = v[i];
}
for (i = N - 1; i >= 1; i--)
{
Tree[i] = Tree[2 * i] + Tree[2 * i + 1];
}
}
ll segment(ll node, ll node_left, ll node_right, ll query_left, ll query_right)
{
if (query_left <= node_left && node_right <= query_right)
{
return Tree[node];
}
if (query_right < node_left || node_right < query_left)
{
return 0;
}
ll last_left = (node_left + node_right) / 2;
return segment(2 * node, node_left, last_left, query_left, query_right) + segment(2 * node + 1, last_left + 1, node_right, query_left, query_right);
}
void update_Tree(ll Index, ll Val)
{
// 1base indexing
ll N = Tree.size() / 2;
ll Diff = Val - Tree[N + Index - 1];
for (ll i = N + Index - 1; i >= 1; i /= 2)
{
Tree[i] += Diff;
}
}
const ll maxN = 100001;
vector<ll> inF(maxN), F(maxN), isPrime(maxN), Ad[maxN];
mpl Vis;
void dfs(ll node)
{
if (Vis[node])
return;
Vis[node] = 1;
for (auto child : Ad[node])
{
dfs(child);
}
return;
}
ll pow1(ll n, ll k)
{
if (k == 0)
return 1;
if (k == 1)
return n;
ll X = 1;
if (k % 2 == 1)
X = n % MOD;
ll Y = pow1(n, k / 2) % MOD;
return (((Y * Y) % MOD) * X) % MOD;
}
void fact_compute()
{
ll N = maxN - 1;
F[0] = 1;
F[1] = 1;
for (ll i = 2; i <= N; i++)
{
F[i] = (F[i - 1] * (i)) % MOD;
}
inF[N] = pow1(F[N], MOD - 2) % MOD;
for (ll i = N - 1; i >= 0; i--)
{
inF[i] = (inF[i + 1] * (i + 1)) % MOD;
}
}
void sieve()
{
for (ll i = 2; i < maxN; i++)
{
isPrime[i] = 1;
}
for (ll i = 2; i < maxN; i++)
{
for (ll j = 2 * i; j < maxN; j += i)
{
isPrime[j] = 0;
}
}
}
ll gcd(ll n, ll m)
{
if (!m)
return n;
return gcd(m, n % m);
}
ll lcm(ll n, ll m)
{
return (n / gcd(n, m)) * m;
}
void set_io()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
void solve() {}
int main()
{
set_io();
ll totalTestCase = 1;
// cin >> totalTestCase;
for (ll testCase = 1; testCase <= totalTestCase; testCase++)
{
solve();
}
return 0;
}