こもりん No title
No License Rust
2020年09月17日
Copy Clone
// estisさんのやつがベース
struct<T> SegmentTree {
    e: u64,
    size: usize,
    tree: Vec<u64>,
    cmpfn: T,
}
impl<T> SegmentTree<T> where T: Fn(u64, u64) -> u64 {
    /// 値の初期化
    pub fn new(n: usize, e: u64, arr: &[u64], cmpfn: fn(u64, u64) -> u64) -> SegmentTree {
        let mut size: usize = 1;
        while size < n  {
            size <<= 1;
        }
        let mut tree: Vec<u64> = Vec::<u64>::with_capacity(2*size);
        for _ in 0..2*size {
            tree.push(e);
        }
        for (i, val) in arr.iter().enumerate() {
            tree[size + i] = *val;
        }

        for i in (1..size).map(|x| size-x) {
            tree[i] = cmpfn(tree[2*i], tree[2*i+1]);
        }

        SegmentTree{
            e,
            size,
            tree,
            cmpfn,
        }
    }

    /// indexの値をnumで更新する.
    pub fn update_number(&mut self, mut index: usize, num: u64) {
        self.tree[index + self.size] = num;
        index = (index + self.size) / 2;
        while index > 0 {
            self.tree[index] = (self.cmpfn)(self.tree[2*index], self.tree[2*index+1]);
            index >>= 1;
        }
    }

    /// [l, r)での範囲の答えを得る.
    pub fn get(&self, l: usize, r:usize) -> u64 {
        // println!("{}, {}, {}", self.size, l, r);
        self.rec(0,self.size,l,r)
    }

    fn rec(&self, min: usize, max: usize, l: usize, r:usize) -> u64 {
        let mid = (min + max)/2;
        if l == min && r == max {
            return self.tree[self.size/(r-l) + l/(r-l)];
        }

        if l < mid && mid < r{
            (self.cmpfn)(self.rec(min, mid, l, mid) , self.rec(mid, max, mid, r))
        }else if mid <= l {
            self.rec(mid, max, l, r)
        }else if r <= mid {
            self.rec(min, mid, l, r)
        }else{
            0
        }
    }

    fn debug(&self){
        println!("{:?}", self.tree);
    }
}
// estisさんのやつがベース
struct<T> SegmentTree {
    e: u64,
    size: usize,
    tree: Vec<u64>,
    cmpfn: T,
}
impl<T> SegmentTree<T> where T: Fn(u64, u64) -> u64 {
    /// 値の初期化
    pub fn new(n: usize, e: u64, arr: &[u64], cmpfn: fn(u64, u64) -> u64) -> SegmentTree {
        let mut size: usize = 1;
        while size < n  {
            size <<= 1;
        }
        let mut tree: Vec<u64> = Vec::<u64>::with_capacity(2*size);
        for _ in 0..2*size {
            tree.push(e);
        }
        for (i, val) in arr.iter().enumerate() {
            tree[size + i] = *val;
        }

        for i in (1..size).map(|x| size-x) {
            tree[i] = cmpfn(tree[2*i], tree[2*i+1]);
        }

        SegmentTree{
            e,
            size,
            tree,
            cmpfn,
        }
    }

    /// indexの値をnumで更新する.
    pub fn update_number(&mut self, mut index: usize, num: u64) {
        self.tree[index + self.size] = num;
        index = (index + self.size) / 2;
        while index > 0 {
            self.tree[index] = (self.cmpfn)(self.tree[2*index], self.tree[2*index+1]);
            index >>= 1;
        }
    }

    /// [l, r)での範囲の答えを得る.
    pub fn get(&self, l: usize, r:usize) -> u64 {
        // println!("{}, {}, {}", self.size, l, r);
        self.rec(0,self.size,l,r)
    }

    fn rec(&self, min: usize, max: usize, l: usize, r:usize) -> u64 {
        let mid = (min + max)/2;
        if l == min && r == max {
            return self.tree[self.size/(r-l) + l/(r-l)];
        }

        if l < mid && mid < r{
            (self.cmpfn)(self.rec(min, mid, l, mid) , self.rec(mid, max, mid, r))
        }else if mid <= l {
            self.rec(mid, max, l, r)
        }else if r <= mid {
            self.rec(min, mid, l, r)
        }else{
            0
        }
    }

    fn debug(&self){
        println!("{:?}", self.tree);
    }
}
anonymous
Anonymous
2021年04月20日
Meds information leaflet. What side effects? <a href="https://lyricainfo.top">what is the price of lyrica</a> in the USA All about pills. Read now.
anonymous
Anonymous
2021年04月27日
Pills prescribing information. Long-Term Effects. <a href="https://pregabalininfo.top">lyrica w/out prescription</a> in Canada Everything about meds. Get information now.
anonymous
Anonymous
2021年04月30日
generic cialis india <a href="https://mycialistabs.com/">generic cialis online canada</a> cialis canada pharmacy
anonymous
Anonymous
2021年04月30日
cialis ad <a href="https://mycialistabs.com/">tadalafil 5mg</a> cialis viagra
anonymous
Anonymous
2021年05月03日
generic cialis available in canada <a href="https://toptadalafiltabs.com/">cialis canada</a> cialis women
anonymous
Anonymous
2021年05月03日
buy cialis without prescription <a href="https://toptadalafiltabs.com/">cialis 20mg price</a> cialis memes
anonymous
Anonymous
2021年05月05日
how to write a casual analysis essay <a href="https://topessaywriterfas.com/">college persuasive essay</a> how to write a high school essay application
anonymous
Anonymous
2021年05月05日
what are five consequences of world war i? write your answer in an essay of at least 125 words. <a href="https://topessaywriterfas.com/">high school vs college essay</a> how to write common application essay
anonymous
Anonymous
2021年05月06日
custlm essay writing service <a href="http://writemyessayslfd.com/">write essays for money</a> essay topics for civil service exam
anonymous
Anonymous
2021年05月07日
best essay reviews writing service <a href="http://writemyessayslfd.com/">click</a> best essay writjing service
anonymous
Anonymous
2021年05月07日
viagra cost per pill <a href="https://mrviagrashop.com">sildenafil citrate 25mg</a> get viagra
anonymous
Anonymous
2021年05月07日
natural alternatives to viagra <a href="https://mrviagrashop.com">teva generic viagra cost</a> over the counter viagra substitute walgreens
anonymous
Anonymous
2021年05月07日
canadian pharmacy ezzz viagra <a href="https://mysildenafilkr.com/">https://mysildenafilkr.com/</a> generic viagra walmart
anonymous
Anonymous
2021年05月07日
buy viagra cheapest <a href="https://mysildenafilkr.com/">sildenafil india</a> viagra gel
anonymous
Anonymous
2021年05月12日
writing resume <a href="http://coverletterforresumetop.com/">best way to make a resume</a> margins for resume
anonymous
Anonymous
2021年05月12日
is cialis a controlled substance <a href="http://tadalafilled.com/">cialis shelf life</a> viagra cialis
anonymous
Anonymous
2021年05月12日
ceo resume <a href="http://coverletterforresumetop.com/">resumes that get jobs</a> consulting resume
anonymous
Anonymous
2021年05月12日
does insurance cover cialis <a href="http://tadalafilled.com/">generic cialis online</a> cheap cialis 20mg
anonymous
Anonymous
2021年05月13日
cv cover letter <a href="https://writingacoverletteronline.com/">rn resume cover letter</a> resume library
anonymous
Anonymous
2021年05月13日
apa cover letter <a href="https://writingacoverletteronline.com/">best resume websites</a> fonts for resume
anonymous
Anonymous
2021年05月14日
generic viagra online <a href="https://edviagramaster.net/">buy generic viagra</a> over the counter viagra
anonymous
Anonymous
2021年05月14日
viagra price <a href="https://edviagramaster.net/">https://edviagramaster.net/</a> sildenafil 100mg
anonymous
Anonymous
2021年05月15日
best natural viagra <a href="https://sildenafilviagratop.com">watermelon viagra</a> online viagra
anonymous
Anonymous
2021年05月15日
sildenafil walmart <a href="https://sildenafilviagratop.com">generic viagra names</a> viagra cvs
anonymous
Anonymous
2021年05月15日
purchasing cialis online <a href="https://cialisortadalafil.com/">cialis on line</a> how to get cialis without doctor
anonymous
Anonymous
2021年05月16日
when will generic cialis be available <a href="https://cialisortadalafil.com/">cialis 20 mg</a> cialis sample
anonymous
Anonymous
2021年05月17日
cialis viagra online <a href="https://topcialistabs.com/">canadian pharmacy cialis 20mg</a> price of cialis
anonymous
Anonymous
2021年05月17日
canadian pharmacy cialis <a href="https://topcialistabs.com/">topcialistabs.com</a> cialis 5mg daily how long before it works
anonymous
Anonymous
2021年06月01日
Medication prescribing information. Drug Class. <a href="https://imodium4u.top">how to get generic imodium</a> in the USA Everything what you want to know about medicines. Read information here.