完全k叉树,每层节点数量是已知的,直接推过去模拟就可以了

class Solution {
   public:
    long long tree2(int k, vector<int>& a) {
        long long ans = 0;
        int n = a.size();
        int fa = 0;
        for (int i = 1; i < n;) {                      //第i个节点
            for (int j = 0; j < k && i < n; ++j, ++i)  //每遍历k个换一次父亲
                ans += (a[fa] ^ a[i]);
            ++fa;
        }
        return ans;
    }
};