コード例 #1
0
int main() {
    int nums[] = {-2, 0, 3, -5, 2, -1};
    SegmentTree<int> *segmentTree = new SegmentTree<int>(nums, sizeof(nums) / sizeof(int), [](int a, int b) -> int {
        return a + b;
    });
    std::cout << segmentTree->query(2,5) << std::endl;
    segmentTree->print();
    return 0;
}
コード例 #2
0
int main ()
{
    SegmentTree obj;
    int n;
    cout<<"Enter the number of elements"<<endl;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>obj.ary[i];
    obj.print(n);

    obj.makeTree(1,n,1);
    int a,b;
    while(cin>>a>>b)
    {
        cout<<"The lowest number between "<<a<<"to "<<b<<"is "<<obj.query(1,n,a,b,1);
    }
    return 0;
}