Skip to content

Commit

Permalink
minor + dmst fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bqi343 committed Dec 27, 2019
1 parent 6cf6ac6 commit 4519de7
Show file tree
Hide file tree
Showing 34 changed files with 713 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* Description: computes a set of maximum size which is independent
* Description: Computes a set of maximum size which is independent
* in both graphic and colorful matroids, aka a spanning forest where
* no two edges are of the same color
* no two edges are of the same color. In general, construct the exchange
* graph and find a shortest path.
* Time: $O(GI^{1.5})$ calls to oracles, where $G$ is the size of the ground set
* and $I$ is the size of the independent set
* Source: https://codeforces.com/blog/entry/69287
Expand Down
2 changes: 2 additions & 0 deletions Implementations/content/combinatorial (11.2)/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@
* Min Weight Graphic + Colorful
* [NAIPC 2018 Sols](http://serjudging.vanb.org/?p=1165)
* [Arup Guha Sol](http://www.cs.ucf.edu/~dmarino/progcontests/mysols/northamerica/2018/g.java)
* [TST](https://dmoj.ca/problem/dmopc19c3p6)
* Partition into 3 MST's
2 changes: 1 addition & 1 deletion Implementations/content/contest/FastI.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Description: fast input for chinese contests
* Time: $\sim$300ms faster for $10^6$ long longs
* Time: $\sim$300ms faster for $10^6$ long longs on CF
* Source:
* https://codeforces.com/gym/102394/submission/64154785
* maybe also see https://codeforces.com/blog/entry/45835 ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Description: $N$-D range sum query with point update
* Source: https://codeforces.com/blog/entry/64914
* Verification: SPOJ matsum
* Usage: \texttt{BIT<int,10,10>} gives a 2D BIT
* Usage: BIT<int,10,10> -> 2D BIT
* Time: O((\log N)^D)
*/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* Description: 1D range update, range query
* Description: 1D range update and query. Set SZ to a power of 2.
* Source: USACO Counting Haybales
* Verification: SPOJ Horrible
*/

template<class T, int SZ> struct LazySeg { // set SZ to a power of 2
template<class T, int SZ> struct LazySeg {
T sum[2*SZ], lazy[2*SZ];
LazySeg() {
memset(sum,0,sizeof sum);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* Description: Persistent min segtree with lazy updates. Unlike typical
* Description: Persistent min segtree with lazy updates. Unlike other
* lazy segtree, assumes that \texttt{lazy[cur]} is included in
* \texttt{val[cur]} before propagating \texttt{cur.}
* Memory: O(N+Q\log N)
* Time: O(\log N)
* Source: CF, Franklyn Wang
* Verification: https://codeforces.com/contest/1090/problem/G
Expand All @@ -14,7 +15,7 @@ template<class T, int SZ> struct pseg {
//// HELPER
int copy(int cur) {
int x = nex++;
val[x] = val[cur], l[x] = l[cur], r[x] = r[cur], lazy[x] = lazy[cur];
val[x]=val[cur], l[x]=l[cur], r[x]=r[cur], lazy[x]=lazy[cur];
return x;
}
T comb(T a, T b) { return min(a,b); }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Description: 1D point update, range query. Change \texttt{comb}
* to any associative (not necessarily commutative) operation
* Description: 1D point update, range query. \texttt{comb}
* can be any associative operation.
* Time: O(\log N)
* Source:
* http://codeforces.com/blog/entry/18051
Expand All @@ -12,7 +12,7 @@ template<class T> struct Seg {
const T ID = 0; // comb(ID,b) must equal b
T comb(T a, T b) { return a+b; }
int n; vector<T> seg;
void init(int _n) { n = _n; seg.rsz(2*n); }
void init(int _n) { n = _n; seg.assign(2*n,ID); }
void pull(int p) { seg[p] = comb(seg[2*p],seg[2*p+1]); }
void upd(int p, T value) { // set value at position p
seg[p += n] = value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Description: supports modifications in the form \texttt{ckmin(a\_i,t)}
* for all $l\le i\le r$, range max and sum queries
* Description: Supports modifications in the form \texttt{ckmin(a\_i,t)}
* for all $l\le i\le r$, range max and sum queries. SZ should be a power of 2.
* Time: O(\log N)
* Source: http://codeforces.com/blog/entry/57319
* Verification: http://acm.hdu.edu.cn/showproblem.php?pid=5306
Expand Down Expand Up @@ -39,7 +39,7 @@ template<int SZ> struct SegTreeBeats {
mx[2*ind^i][0] = mx[ind][0];
}
}
void upd(int x, int y, int t, int ind = 1, int L = 0, int R = -1) {
void upd(int x, int y, int t, int ind=1, int L=0, int R=-1) {
if (R == -1) R += N;
if (R < x || y < L || mx[ind][0] <= t) return;
push(ind,L,R);
Expand All @@ -66,6 +66,6 @@ template<int SZ> struct SegTreeBeats {
push(ind,L,R);
if (x <= L && R <= y) return mx[ind][0];
int M = (L+R)/2;
return max(qmax(x,y,2*ind,L,M), qmax(x,y,2*ind+1,M+1,R));
return max(qmax(x,y,2*ind,L,M),qmax(x,y,2*ind+1,M+1,R));
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pair<pt,pt> splitsz(pt t, int sz) { // sz nodes go to left
auto p = splitsz(t->c[0],sz); t->c[0] = p.s;
return {p.f,calc(t)};
} else {
auto p = splitsz(t->c[1],sz-getsz(t->c[0])-1); t->c[1] = p.f;
auto p=splitsz(t->c[1],sz-getsz(t->c[0])-1); t->c[1]=p.f;
return {calc(t),p.s};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
/**
* Description: Segment tree on values instead of indices.
* Return $k$-th largest number in interval (lo,hi]
* Time: O(\log N)
* Returns $k$-th largest number in 0-indexed interval \texttt{[lo,hi)}.
* SZ should be a power of 2, and all values in $a$ must lie in \texttt{[0,SZ)}.
* Memory: O(N\log N)
* Time: O(\log N) query
* Source: http://rachitiitr.blogspot.com/2017/06
/wavelet-trees-wavelet-trees-editorial.html
* Verification: http://www.spoj.com/problems/MKTHNUM/
*/

template<int SZ> struct Wavelet {
vi mapl[2*SZ], mapr[2*SZ], val[2*SZ];
void build(vi& a, int ind = 1, int L = 0, int R = SZ-1) { // build a wavelet tree
if (ind == 1) { F0R(i,sz(a)) val[ind].pb(i); }
template<int SZ> struct Wavelet {
vi nexl[SZ], nexr[SZ];
void build(vi a, int ind = 1, int L = 0, int R = SZ-1) {
if (L == R) return;
int M = (L+R)/2;
trav(i,val[ind]) {
val[2*ind+(a[i] > M)].pb(i);
mapl[ind].pb(sz(val[2*ind])-1);
mapr[ind].pb(sz(val[2*ind+1])-1);
nexl[ind] = nexr[ind] = {0};
vi A[2]; int M = (L+R)/2;
trav(t,a) {
A[t>M].pb(t);
nexl[ind].pb(sz(A[0])), nexr[ind].pb(sz(A[1]));
}
build(a,2*ind,L,M); build(a,2*ind+1,M+1,R);
build(A[0],2*ind,L,M), build(A[1],2*ind+1,M+1,R);
}
int getl(int ind, int x) { return x < 0 ? -1 : mapl[ind][x]; }
int getr(int ind, int x) { return x < 0 ? -1 : mapr[ind][x]; }
int query(int lo, int hi, int k, int ind = 1, int L = 0, int R = SZ-1) {
int query(int lo,int hi,int k,int ind=1,int L=0,int R=SZ-1) {
if (L == R) return L;
int M = (L+R)/2, t = getl(ind,hi)-getl(ind,lo);
if (t >= k) return query(getl(ind,lo),getl(ind,hi),k,2*ind,L,M);
return query(getr(ind,lo),getr(ind,hi),k-t,2*ind+1,M+1,R);
int M = (L+R)/2, t = nexl[ind][hi]-nexl[ind][lo];
if (t >= k) return query(nexl[ind][lo],
nexl[ind][hi],k,2*ind,L,M);
return query(nexr[ind][lo],
nexr[ind][hi],k-t,2*ind+1,M+1,R);
}
};
3 changes: 2 additions & 1 deletion Implementations/content/data-structures/LCDeque.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Description: same as LineContainer but linear time given assumptions
* Description: LineContainer given assumptions
* Time: O(1)
* Source: Own
* Verification: http://acm.hdu.edu.cn/diy/contest_showproblem.php?cid=36005&pid=1009
*/
Expand Down
1 change: 1 addition & 0 deletions Implementations/content/data-structures/Range Queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

* [Wavelet Tree](http://codeforces.com/blog/entry/52854)
* [DMOJ](https://dmoj.ca/problem/globexcup19s4)
* [Easy Query](https://open.kattis.com/problems/easyquery)
* [Segment Tree Beats](http://codeforces.com/blog/entry/57319)
* Sqrt Tree (don't think this is useful for anything tho)
* [Pt 1](http://codeforces.com/blog/entry/57046)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* https://cses.fi/problemset/stats/1647/
* http://wcipeg.com/problem/ioi1223
* https://pastebin.com/ChpniVZL
* Time: $O(N\log N)$ build, $O(1)$ query
* Memory: O(N\log N)
* Time: O(1)
*/

template<class T> struct RMQ {
Expand Down
1 change: 1 addition & 0 deletions Implementations/content/data-structures/chapter.tex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ \section{1D Range Queries}
\kactlimport{1D Range Queries (9.2)/BIT (9.2).h}
\kactlimport{1D Range Queries (9.2)/BITrange.h}
\kactlimport{1D Range Queries (9.2)/SegTree (9.2).h}
\kactlimport{1D Range Queries (9.2)/Wavelet.h}
\kactlimport{1D Range Queries (9.2)/SegTreeBeats.h}
\kactlimport{1D Range Queries (9.2)/PSeg (15.2).h}
\kactlimport{1D Range Queries (9.2)/Treap (15.3).h}
Expand Down
4 changes: 2 additions & 2 deletions Implementations/content/graphs (12)/Flows (12.3)/GomoryHu.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Description: Returns edges of Gomory-Hu tree. Max flow between
* pair of vertices of undirected graph is given by min edge
* weight along tree path. Uses the lemma that for any $i,j,k,$
* weight along tree path. Uses the fact that for any $i,j,k,$
* $\lambda_{ik}\ge \min(\lambda_{ij},\lambda_{jk}),$
* where $\lambda_{ij}$ denotes the flow from $i$ to $j.$
* where $\lambda_{ij}$ denotes the flow between $i$ and $j.$
* Source: https://github.com/koosaga/DeobureoMinkyuParty/blob/master/teamnote.tex
* Time: $O(N)$ calls to Dinic
* Verification: https://codeforces.com/problemset/problem/343/E
Expand Down
2 changes: 1 addition & 1 deletion Implementations/content/graphs (12)/Flows (12.3)/MCMF.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ template<int SZ> struct MCMF {
pi pre[SZ]; // previous vertex, edge label on path
pair<C,F> cost[SZ]; // tot cost of path, amount of flow
C totCost, curCost; F totFlow;
bool spfa() { // find lowest cost path such that you can send flow through it
bool spfa() { // find lowest cost path to send flow through
F0R(i,N) cost[i] = {numeric_limits<C>::max(),0};
cost[s] = {0,numeric_limits<F>::max()};
pqg<pair<C,int>> todo; todo.push({0,s});
Expand Down
3 changes: 1 addition & 2 deletions Implementations/content/graphs (12)/Matching/DFSmatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ template<int SZ> struct MaxMatch {
}
void tri(int x) { vis.reset(); flow += dfs(x); }
void init(int _N) {
N = _N; FOR(i,1,N+1) if (!match[i]) tri(i);
}
N = _N; FOR(i,1,N+1) if (!match[i]) tri(i); }
};
Loading

0 comments on commit 4519de7

Please sign in to comment.