当前位置: 首页>>代码示例>>C++>>正文


C++ SegmentTree::query_min方法代码示例

本文整理汇总了C++中SegmentTree::query_min方法的典型用法代码示例。如果您正苦于以下问题:C++ SegmentTree::query_min方法的具体用法?C++ SegmentTree::query_min怎么用?C++ SegmentTree::query_min使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SegmentTree的用法示例。


在下文中一共展示了SegmentTree::query_min方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test

    int
    test() {
        SegmentTree st;
        st.initialize(14, 100);

        st.insert(0, 45);
        st.insert(1, 4);
        st.insert(2, 5);
        st.insert(3, 2);
        st.insert(4, 99);
        st.insert(5, 41);
        st.insert(6, 45);
        st.insert(7, 45);
        st.insert(8, 51);
        st.insert(9, 89);
        st.insert(10, 1);
        st.insert(11, 3);
        st.insert(12, 5);
        st.insert(13, 98);

        vi_t v;
        v.push_back(45);
        v.push_back(4);
        v.push_back(5);
        v.push_back(2);
        v.push_back(99);
        v.push_back(41);
        v.push_back(45);
        v.push_back(45);
        v.push_back(51);
        v.push_back(89);
        v.push_back(1);
        v.push_back(3);
        v.push_back(5);
        v.push_back(98);

        for (int i = 0; i < 14; ++i) {
            for (int j = i; j < 14; ++j) {
                pii_t one = st.query_min(i, j);
                pii_t two = naive_query_min(v, i, j);
                printf("query_min(%d, %d) == (%d, %d)\n", i, j, one.INDEX, two.INDEX);
                assert(one.LENGTH == two.LENGTH);
            }
        }

        return 0;
    }
开发者ID:dhruvbird,项目名称:genome-diff-compression,代码行数:47,代码来源:segtree.hpp

示例2: assert

// 'rin' is the input range set
//
// 'rout' is the output range set. It is guaranteed that 'rout'
// contains the mapping needed to re-contruct the least number of
// ranges needed to represent the complete range. Start with rout[0]
// and keep following the indexes till you reach some 'k' for which
// rout[k] == n.
//
// rout[i] contains the next index within rout (in sorted string
// order) where you need to jump to find the next range that completes
// the smallest number of ranges that cover the entire range.
// 
// you will need to index into 'slcp' to locate the index of this
// range in the original string
//
void
compress_ranges(vi_t &rin, vi_t &rout) {
    SegmentTree st;
    rout.clear();
    if (rin.empty()) {
        return;
    }

    const int n = rin.size();
    st.initialize(n + 1, n + 1);
    rout.resize(n);
    st.insert(n, 0);

    for (int i = rin.size() - 1; i >= 0; --i) {
        assert(rin[i] > 0);
        int l = i + 1, r = std::min(n, i+rin[i]);
        pii_t m = st.query_min(l, r);
        rout[i] = m.INDEX;
        st.insert(i, m.LENGTH + 1);
    }
}
开发者ID:dhruvbird,项目名称:genome-diff-compression,代码行数:36,代码来源:algorithm.hpp


注:本文中的SegmentTree::query_min方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。