Created
October 26, 2012 22:43
-
-
Save alculquicondor/3961992 to your computer and use it in GitHub Desktop.
Union Range
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 C[MAXN], next[MAXN]; | |
inline int findSet(int i) { | |
return (C[i] == i) ? i : (C[i] = findSet(C[i])); | |
} | |
inline int findNext(int i) { | |
return (next[i] == i) ? i : (next[i] = findNext(next[i])); | |
} | |
inline void unionSet(int i, int j) { | |
C[findSet(i)] = findSet(j); | |
} | |
inline void unionRange(int i, int j) { | |
if(j<i) | |
return; | |
int g = findNext(i), last = findNext(j); | |
next[i] = last; | |
while(g<j) { | |
next[g] = last; | |
unionSet(g, g+1); | |
g = findNext(g+1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment