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
//Bitset | |
#include <iostream> | |
using namespace std; | |
struct Bitset{ | |
long long m; | |
Bitset(int x = 0){m = x;} | |
const static long long empty_set = 0; | |
bool Find(int in){return m&(1LL<<in);} | |
void Erase(int in){ m &= ~in;} |
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
///Soluciones | |
1. hacer una función que bote -1 en caso que un entero sea negativo y 0 en otro caso. | |
rpta: | |
int neg(int x){return -(x < 0);} | |
2. intercambie dos enteros x e y, se entiende que ahora x sera y e y tendra el valor inicial de x. | |
rpta: |
- Segment Trees / let us code
- segment tree and lazy propagation / se7so
- generalizing segment trees
- Dynamic Segment Trees
- Modular Segment Tree with Lazy Propagation
- persistent segment tree / iq opengenus
- persistent segment trees explained with spoj problems / anudeep
- mit / persistent
- persistent segment tree / lyzqm
- [persistent segment tree / secmem](http://www.secm
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
//fenwick_tree.cpp | |
//complexity: | |
// update - O(log n) | |
// query - O(log n) | |
// sum_range - O(log n) | |
// binary_fenwick - O(log n) | |
const int maxN = 100002; | |
int ft[maxN]; |
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
//sparse_table | |
//complexity: | |
// min_range - O(1) | |
// build - O(n * log n) | |
const int N = 100002; | |
const int LogN = 18; | |
int st[N][LogN]; | |
int n; |
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
//segment tree | |
//complexity: | |
// merge - O(1) | |
// shift - O(1) | |
// upd - O(1) | |
// build - O(n) | |
// update - O(log n) | |
// query - O(log n) | |
const int maxN = 100002; |
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
//sqrt descomposition | |
//complexity: | |
// build - O(n) | |
// query - O(sqrt n) | |
// update - O(1) | |
const int N = 100005; | |
int block[350], a[N]; | |
int n, nb; |
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
const int N = 50002; | |
int len, n, q; | |
int vis[N], ans[N]; | |
int a[N], ans_mo; | |
struct Query{int l, r, in;} Q[N]; | |
bool cmp(const Query& p, const Query& q){ | |
return p.r/len < q.r/len or p.r/len == q.r/len and p.l > q.l; | |
} |
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
int times = 0; | |
int L[N], R[N], sz[N]; | |
bool S1[N], S2[N]; | |
int ans[N], p[N]; | |
void dfs(int x, int p){ | |
L[x] = times++; | |
for(int v : adj[x]) | |
if(v != p) dfs(v, x); | |
R[x] = times++; |
OlderNewer