Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <iostream>#include <cstdlib>#include <climits>using namespace std;typedef struct node{int key, val, num, lazy;long totalVal;struct node *left, *right, *father;}Node;Node* createNode(int key, int val) {Node *node = (Node*)malloc(sizeof(Node));node->key = key;node->val = val;node->num = 1;node->totalVal = val;node->lazy = 0;node->left = NULL;node->right = NULL;node->father = NULL;return node;}void update(Node *x) {//here must initializex->num = 1;x->totalVal = x->val;if(x->left) {x->num += x->left->num;