-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cd37e2d
Showing
17 changed files
with
1,779 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
struct FenwickTree { | ||
vector<int> bit; // binary indexed tree | ||
int n; | ||
|
||
FenwickTree(int n) { | ||
this->n = n; | ||
bit.assign(n, 0); | ||
} | ||
|
||
FenwickTree(vector<int> a) : FenwickTree(a.size()) { | ||
for (size_t i = 0; i < a.size(); i++) | ||
add(i, a[i]); | ||
} | ||
|
||
int sum(int r) { | ||
int ret = 0; | ||
for (; r >= 0; r = (r & (r + 1)) - 1) | ||
ret += bit[r]; | ||
return ret; | ||
} | ||
|
||
int sum(int l, int r) { | ||
return sum(r) - sum(l - 1); | ||
} | ||
|
||
void add(int idx, int delta) { | ||
for (; idx < n; idx = idx | (idx + 1)) | ||
bit[idx] += delta; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* Press F to pay respects */ | ||
#define _CRT_SECURE_NO_DEPRECATE | ||
#pragma GCC optimize("O3") | ||
#pragma GCC target("sse4") | ||
#include<bits/stdc++.h> | ||
#include<sstream> | ||
//#include <ext/pb_ds/assoc_container.hpp> | ||
//#include <ext/pb_ds/tree_policy.hpp> | ||
//using namespace __gnu_pbds; | ||
using namespace std; | ||
#define int long long int | ||
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); | ||
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); | ||
typedef long double ld; | ||
typedef pair<int,int> ii; | ||
typedef pair<int,ii> iii; | ||
typedef vector<int> vi; | ||
typedef vector<ii> vii; | ||
//typedef tree<int, null_type, less<int>, rb_tree_tag, | ||
// tree_order_statistics_node_update> | ||
// data_set; | ||
#define rep(i,l,r) for(int i=(l);i<(r);i++) | ||
#define deb(x) cout << (#x) << " is " << (x) << endl | ||
#define dbg(x) cout << x << ' ' | ||
#define here cout << " Hey baitch!!\n"; | ||
#define pb push_back | ||
#define F first | ||
#define S second | ||
#define all(v) (v).begin(),(v).end() | ||
#define sz(a) (int)((a).size()) | ||
#define sq(x) ((x)*(x)) | ||
const int MOD = 1e9+7; | ||
const int MOD1 = 998244353; | ||
const int N = 2e5+5; | ||
const int INF = 1000111000111000111LL; | ||
const ld PI = 3.1415926535898; | ||
|
||
struct seg_tree | ||
{ | ||
|
||
vector<int> bit; | ||
vector<int> a; | ||
vector<int> lazy; | ||
int n; | ||
seg_tree(int n) { | ||
this-> n = n; | ||
bit.assign(4*n+5,0); | ||
lazy.assign(4*n+5,0); | ||
} | ||
seg_tree(vector<int> a) : seg_tree(a.size()) | ||
{ | ||
this-> a = a; | ||
build(0,0,(int)a.size()-1); | ||
} | ||
int merge(int x, int y) { | ||
// Function to return | ||
return min(x,y); | ||
} | ||
void build(int node, int start, int end) | ||
{ | ||
if(start == end) | ||
{ | ||
bit[node] = a[start]; | ||
return; | ||
} | ||
int lch = 2*node+1; //Left Child | ||
int rch = 2*node+2; //Right Child | ||
int mid = (start+end)/2; | ||
build(lch,start,mid); | ||
build(rch,mid+1,end); | ||
bit[node] = merge(bit[lch],bit[rch]); | ||
return; | ||
} | ||
// Adding on segtree and query for max/min | ||
void push(int v) { | ||
bit[v*2+1] += lazy[v]; | ||
lazy[v*2+1] += lazy[v]; | ||
bit[v*2+2] += lazy[v]; | ||
lazy[v*2+2] += lazy[v]; | ||
lazy[v] = 0; | ||
} | ||
|
||
void update(int v, int tl, int tr, int l, int r, int addend) { | ||
if (l > r) | ||
return; | ||
if (l == tl && tr == r) { | ||
bit[v] += addend; | ||
lazy[v] += addend; | ||
} else { | ||
push(v); | ||
int tm = (tl + tr) / 2; | ||
update(v*2+1, tl, tm, l, min(r, tm), addend); | ||
update(v*2+2, tm+1, tr, max(l, tm+1), r, addend); | ||
bit[v] = merge(bit[v*2+1], bit[v*2+2]); | ||
} | ||
} | ||
|
||
int query(int v, int tl, int tr, int l, int r) { | ||
if (l > r) | ||
return INF; | ||
if (l <= tl && tr <= r) | ||
return bit[v]; | ||
push(v); | ||
int tm = (tl + tr) / 2; | ||
return merge(query(v*2+1, tl, tm, l, min(r, tm)), | ||
query(v*2+2, tm+1, tr, max(l, tm+1), r)); | ||
} | ||
|
||
}; | ||
|
||
int32_t main() | ||
{ | ||
SYNC | ||
int n; cin >> n; | ||
vi v(n); | ||
for(auto &it : v) cin >> it; | ||
seg_tree sg(v); | ||
int Q; cin >> Q; | ||
cin.ignore(); | ||
while(Q--) | ||
{ | ||
string s; | ||
getline(cin,s); | ||
stringstream ss(s); | ||
int l,r,val; | ||
ss >> l >> r; | ||
if(ss >> val) | ||
{ | ||
if(r >= l) | ||
sg.update(0,0,n-1,l,r,val); | ||
else | ||
sg.update(0,0,n-1,l,n-1,val),sg.update(0,0,n-1,0,r,val); | ||
}else | ||
{ | ||
if(r >= l) | ||
cout << sg.query(0,0,n-1,l,r) << '\n'; | ||
else | ||
cout << min(sg.query(0,0,n-1,l,n-1),sg.query(0,0,n-1,0,r)) << '\n'; | ||
} | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#define _CRT_SECURE_NO_DEPRECATE | ||
#pragma GCC optimize("O3") | ||
#pragma GCC target("sse4") | ||
#include<bits/stdc++.h> | ||
//#include <ext/pb_ds/assoc_container.hpp> | ||
//#include <ext/pb_ds/tree_policy.hpp> | ||
//using namespace __gnu_pbds; | ||
using namespace std; | ||
#define int long long int | ||
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); | ||
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); | ||
typedef long double ld; | ||
typedef pair<int,int> ii; | ||
typedef pair<int,ii> iii; | ||
typedef vector<int> vi; | ||
typedef vector<ii> vii; | ||
//typedef tree<int, null_type, less<int>, rb_tree_tag, | ||
// tree_order_statistics_node_update> | ||
// data_set; | ||
#define rep(i,l,r) for(int i=(l);i<(r);i++) | ||
#define deb(x) cout << (#x) << " is " << (x) << endl | ||
#define dbg(x) cout << x << ' ' | ||
#define here cout << " Hey baitch!!\n"; | ||
#define pb push_back | ||
#define F first | ||
#define S second | ||
#define all(v) (v).begin(),(v).end() | ||
#define sz(a) (int)((a).size()) | ||
#define sq(x) ((x)*(x)) | ||
const int MOD = 1e9+7; | ||
const int MOD1 = 998244353; | ||
const int N = 2e5+5; | ||
const int INF = 1000111000111000111LL; | ||
const ld PI = 3.1415926535898; | ||
int n,lg; | ||
vector<int> g[N]; | ||
int timer = 0; | ||
vector<int> tin,tout,depth; | ||
vector<vector<int>> up; | ||
void dfs(int node, int par) | ||
{ | ||
tin[node] = ++timer; | ||
up[node][0] = par; | ||
for(int i = 1; i <= lg; i++) { | ||
up[node][i] = up[up[node][i-1]][i-1]; | ||
} | ||
for(auto to : g[node]) { | ||
if(to != par) | ||
depth[to] = depth[node] + 1, | ||
dfs(to,node); | ||
|
||
} | ||
tout[node] = ++timer; | ||
return; | ||
} | ||
bool is_ancestor(int u, int v) { | ||
return tin[u] <= tin[v] && tout[u] >= tout[v]; | ||
} | ||
int lca(int u, int v) { | ||
if(is_ancestor(u,v)) return u; | ||
if(is_ancestor(v,u)) return v; | ||
for(int i = lg; i >= 0; i--) { | ||
if(!is_ancestor(up[u][i],v)) { | ||
u = up[u][i]; | ||
} | ||
} | ||
return up[u][0]; | ||
} | ||
int dist(int u, int v) { | ||
int anc = lca(u,v); | ||
return depth[u] + depth[v] - 2*depth[anc]; | ||
} | ||
void pre_process(int root) { | ||
tin.resize(n); | ||
tout.resize(n); | ||
depth.resize(n); | ||
timer = 0; | ||
lg = ceil(log2(n)); | ||
up.assign(n, vector<int>(lg+1)); | ||
depth[root] = 0; | ||
dfs(root,root); | ||
} | ||
int32_t main() | ||
{ | ||
SYNC | ||
cin >> n; | ||
for(int i = 0; i < n-1; i++) { | ||
int u,v; cin >> u >> v; | ||
u--,v--; | ||
g[u].pb(v); | ||
g[v].pb(u); | ||
} | ||
pre_process(0); | ||
int q; cin >> q; | ||
while(q--) | ||
{ | ||
|
||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* Press F to pay respects */ | ||
#define _CRT_SECURE_NO_DEPRECATE | ||
#pragma GCC optimize("O3") | ||
#pragma GCC target("sse4") | ||
#include<bits/stdc++.h> | ||
//#include <ext/pb_ds/assoc_container.hpp> | ||
//#include <ext/pb_ds/tree_policy.hpp> | ||
//using namespace __gnu_pbds; | ||
using namespace std; | ||
#define int long long int | ||
#define SYNC std::ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); | ||
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); | ||
typedef long double ld; | ||
typedef pair<int,int> ii; | ||
typedef pair<int,ii> iii; | ||
typedef vector<int> vi; | ||
typedef vector<ii> vii; | ||
//typedef tree<int, null_type, less<int>, rb_tree_tag, | ||
// tree_order_statistics_node_update> | ||
// data_set; | ||
#define rep(i,l,r) for(int i=(l);i<(r);i++) | ||
#define deb(x) cout << (#x) << " is " << (x) << endl | ||
#define dbg(x) cout << x << ' ' | ||
#define here cout << " Hey baitch!!\n"; | ||
#define pb push_back | ||
#define F first | ||
#define S second | ||
#define all(v) (v).begin(),(v).end() | ||
#define sz(a) (int)((a).size()) | ||
#define sq(x) ((x)*(x)) | ||
const int MOD = 1e9+7; | ||
const int MOD1 = 998244353; | ||
const int N = 2e5+5; | ||
const int INF = 1000111000111000111LL; | ||
const ld PI = 3.1415926535898; | ||
typedef vector< vi > vvi; | ||
int modular_exp(int base,int exp,int mod) | ||
{ | ||
int ans =1; | ||
while(exp) | ||
{ | ||
if(exp%2) ans = ans%mod*base%mod; | ||
base = (base%mod*base%mod)%mod; | ||
exp/=2; | ||
ans%=mod; | ||
} | ||
return ans; | ||
} | ||
int inverse_modulo(int base,int mod) | ||
{ | ||
return modular_exp(base,mod-2,mod); | ||
} | ||
vvi multiply(vvi a, vvi b, int mod = MOD) | ||
{ | ||
int n = sz(a); | ||
vvi res; | ||
res.resize(n); | ||
for(int i = 0; i < n; i++) | ||
{ | ||
res[i].resize(n); | ||
for(int j = 0; j < n; j++) | ||
{ | ||
int cnt = 0; | ||
for(int k = 0; k < n; k++) | ||
{ | ||
cnt += a[i][k]*b[k][j]; | ||
cnt %= mod; | ||
} | ||
res[i][j] = cnt; | ||
} | ||
} | ||
return res; | ||
} | ||
int32_t main() | ||
{ | ||
SYNC | ||
int n,f1,f2,f3,c; | ||
cin >> n >> f1 >> f2 >> f3 >> c; | ||
vvi fib,res; | ||
f1 *= c; f1 %= MOD; | ||
f2 *= modular_exp(c,2,MOD); f2 %= MOD; | ||
f3 *= modular_exp(c,3,MOD); f3 %= MOD; | ||
res.resize(3); | ||
fib.resize(3); | ||
res[0] = res[1] = res[2] = {0,0,0}; | ||
res[0][0] = res[1][1] = res[2][2] = 1; | ||
fib[0] = {1,1,1}, fib[1] = {1,0,0}, fib[2] = {0,1,0}; | ||
int ans = 1; | ||
int exp = n-3; | ||
while(exp) | ||
{ | ||
if(exp%2) | ||
res = multiply(res,fib,MOD-1); | ||
fib = multiply(fib,fib,MOD-1); | ||
exp/=2; | ||
} | ||
ans *= modular_exp(f3,res[0][0],MOD);ans %= MOD; | ||
ans *= modular_exp(f2,res[0][1],MOD);ans %= MOD; | ||
ans *= modular_exp(f1,res[0][2],MOD);ans %= MOD; | ||
ans *= inverse_modulo(modular_exp(c,n,MOD),MOD); | ||
ans %= MOD; | ||
cout << ans; | ||
|
||
return 0; | ||
} |
Oops, something went wrong.