Lowest Common Ancestor


//<O(N logN, O(logN)> #define mx 10010 #define logmx ceil(log(mx)) #define pii pair < int, int > //#define i64 __int64 #define inf 2147483647 int L[mx], T[mx], P[mx][logmx]; const int root = 1; bool color[mx]; long long d[mx]; vector < pii > G[mx]; void preprocess(int n){ int...

RMQ with Segment Tree


#define mx 1000010 #define tmx 2000020 int a[mx]; int t[tmx]; void init(int node, int i, int j){ if(i==j){ t[node] = a[i]; return; } int mid = (i+j)>> 1; init(2*node, i, mid); init((2*node)+1, mid+1, j); t[node] = max(t[2*node], t[(2*node)+1]); } int query(int...

Binary Indexed Tree


#define i64 long long i64 BIT[mx]; int n; //1-D BIT i64 read(int idx){ i64 sum = 0; while (idx > 0){ sum += BIT[idx]; idx -= (idx & -idx); } return sum; } void update(int idx, i64 val){ while (idx <= m){ BIT[idx] += val; idx += (idx &...

Bipartite Matching (Hopcroft-Karp)


//Complexity: O(e√v) //n: number of nodes in left side n=[1,n] //m: number of nodes in right side m=[n+1,n+m] //G: NIL U G1[G[1,n]] U G2[G[n+1,n+m]] #define mx 100010 #define inf (1<<28) vector < int > G[mx]; int match[mx], dist[mx]; const int NIL = 0; bool bfs(int n){ int i,u,v,sz; ...

MAKEFILE (at a glance)


Sample code project1: data.o main.o io.o         cc data.o main.o io.o -o project1 data.o: data.c data.h         cc -c data.c main.o: data.h io.h main.c         cc -c main.c io.o: io.h io.c         cc -c io.c #this is...

Windows 7 Command Prompt Commands


Append: It can be used by programs to open files in another directory as if they were located in the current directory. Arp: It is used to display or change entries in the ARP cache.. Assoc: The assoc command is used to display or change the file type associated with a particular file extension.. At: The...

vi/vim cheat sheet


My vi/vim cheatsheet Cursor movement h - move left j - move down k - move up l - move right w - jump by start of words (punctuation considered words) W - jump by words (spaces separate words) e - jump to end of words (punctuation considered words) E - jump to end of words (no punctuation) b...

C++ String references with example


C++ String Examples body{color:#000051;position:relative;top:157; scrollbar-face-color:#FFFFFF; scrollbar-arrow-color:#000051; scrollbar-track-color:#FFFFFF;} .blue{color:red;font-weight:bold;} .green{color:green;} constructors 1. #include <iostream> #include...