Created
August 19, 2017 11:40
-
-
Save Hunachi/3e469fc07da0ec36819985a7ba94391e to your computer and use it in GitHub Desktop.
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
static const int MAX_N = 200002; | |
struct Seg{ | |
int n; | |
int dat[MAX_N * 2]; | |
void init(int n_){ | |
init(n_ , INF); | |
} | |
void init(int n_, int d){ | |
n = 1; | |
while(n < n_)n *= 2; | |
fill(dat, dat + MAX_N * 2, d); | |
} | |
}; | |
struct Segment : Seg { | |
int Min(int s,int t){ | |
return Min(s,t,0,0,n); | |
} | |
int Min(int s, int t, int k, int l, int r){ | |
if(r <= s || t <= l) return INF; | |
if(s <= l && r <= t) return dat[k]; | |
int t1 = Min(s, t, k * 2 + 1, l, (l + r)/2); | |
int t2 = Min(s, t, k * 2 + 2, (l + r)/2, r); | |
return min(t1, t2); | |
} | |
void update(int k, int x){ | |
k += n - 1; | |
dat[k] = min(dat[k], x); | |
while(0 < k){ | |
k = (k - 1)/2; | |
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment