Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include<iostream>using namespace std;struct SegNode{int leftBound, rightBound;int sum;int lazyTag_set, lazyTag_add;SegNode *left, *right;};SegNode* Seg_build(int *Val, int leftBound, int rightBound){SegNode *root = new SegNode;root->leftBound = leftBound;root->rightBound = rightBound;root->lazyTag_set = -1;root->lazyTag_add = 0;root->left = root->right = NULL;if(leftBound == rightBound)root->sum = Val[root->leftBound];else{int mid = (leftBound + rightBound) / 2;root->left = Seg_build(Val, leftBound, mid);root->right = Seg_build(Val, mid+1, rightBound);root->sum = root->left->sum + root->right->sum;}return root;