| 47 | } |
| 48 | |
| 49 | void updateNode(TreeNode * n, int pos, int val){ |
| 50 | if(!n)return; |
| 51 | |
| 52 | if(n->l == n->r && n->l == pos){ |
| 53 | n->v = val; |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | int m = (n->l+n->r)/2; |
| 58 | |
| 59 | // 后序遍历 |
| 60 | if(pos <= m){ |
| 61 | updateNode(n->left, pos, val); |
| 62 | }else{ |
| 63 | updateNode(n->right, pos, val); |
| 64 | } |
| 65 | n->v = n->left->v + n->right->v; |
| 66 | } |
| 67 | |
| 68 | int query(TreeNode * n, int l, int r){ |
| 69 | if(!n)return 0; |
nothing calls this directly
no outgoing calls
no test coverage detected