int query(int node,int lo,int hi,int from,int to) {
if(lo>hi||lo>to||from>hi)
return 0;
refresh(node,lo,hi);
if(lo>=from&&hi<=to) {
return tree[node];
}
return query(node*2,lo,(lo+hi)/2,from,to)+query(node*2+1,(lo+hi)/2+1,hi,from,to);
}
Again, formatting is not something that is required and many people do it different ways.
I use tabs instead of spaces, just because I find it easier. But if you do use spaces, use a consistent amount. I've worked with people who use 2, 3 or 4 spaces. As long as they use a consistent amount, then I can reformat it using tabs and they can reformat my tabs to spaces.
The curly brace closes go at the same indentation as the line that the barce opened on. When you trace back vertically from a closing brace you will find the statement that caused the opening, and the opening bracket is at the end of that line.