//determine dimensions of small and large intervals and calculate F+(MAX), F-(SMALL) intervals.
	void calcTightUpperBound() {
		int score_plus =  intervalSum(pos, intervalStart[Left], intervalEnd[Right]);

		int score_mins =  0;
		if(intervalEnd[Left] <= intervalStart[Right])	// check if there is a common interval
			score_mins = intervalSum(neg, intervalEnd[Left], intervalStart[Right]);

		upperbound = score_plus + score_mins;
	}
	//determine dimensions of small and large intervals and calculate F+(MAX), F-(SMALL) intervals.
	void calcNotTightUpperBound() {

		if(isLeafNode())
			return calcTightUpperBound();

		int score_plus =  intervalSum(pos, intervalStart[Left], intervalEnd[Right]);

		upperbound = score_plus;
	}
Example #3
0
int main()
{
	vector<int> vec = {1,2,7,8,5};
	vector<Interval> queries = {Interval(0,4),Interval(1,2),Interval(2,4)};
	
	vector<long long> ret = intervalSum(vec,queries);
	for(auto i : ret)
	{
		cout << i << endl;
	}
}
int main() {
    scanf("%d", &count);
    for(int i = 0; i < count; i++) {
        scanf("%d", &tree[i]);
    }
    createTree();
    scanf("%d", &nCount);
    for(int i = 0; i < nCount; i++) {
        scanf("%d", &isIncrement);
        if(isIncrement == true) {
            scanf("%d%d%d", &fInd, &tInd, &o_i);
            increment(fInd,tInd,o_i);
        }else {
            scanf("%d%d", &fInd, &tInd);
            printf("%d\n", intervalSum(fInd,tInd));
        }
    }
    return 0;
}
        void Main()
        {
			vector<int> A = { 1, 2, 7, 8, 5 };
			vector<Interval> queries = { { 1, 2 }, { 0, 4 }, { 2, 4 } };
			print(intervalSum(A, queries));
        }