// 演算法 / Algorithm:
// 與 C 版相同：答案僅取決於 n。n<=2 單獨處理，否則可達 XOR 值填滿
// [0, 2^B - 1]（B = n 的位元數），答案為 2^B。
// Same as the C version: the answer depends only on n. Special-case n<=2,
// otherwise reachable values fill [0, 2^B - 1] (B = bit-width of n),
// giving 2^B.

#include <vector>   // std::vector：LeetCode 傳入的動態陣列型別 / dynamic array type used by LeetCode
using namespace std;

class Solution {
public:
    int uniqueXorTriplets(vector<int>& nums) {
        int n = nums.size();       // .size() 回傳容器元素個數，即 n / .size() gives the element count = n

        if (n == 1) return 1;      // 唯一可達值是那個元素本身 / only the element itself is reachable
        if (n == 2) return 2;      // 只能湊出 {1,2} 兩個值 / only {1,2} reachable → 2 values

        int msb = 0;               // 最高有效位的位置 / index of the most significant bit
        int t = n;                 // n 的副本，供位移用 / a mutable copy of n for shifting
        while (t > 1) {            // 逐次右移直到只剩最高位 / shift until only the top bit is left
            t >>= 1;               // 除以 2，丟掉最低位 / divide by 2, drop the lowest bit
            ++msb;                 // 位置往上累加 / bump the top-bit index
        }

        // 2^(msb+1)：用左移計算 2 的次方，快且精確。
        // 2^(msb+1): a left shift computes the power of two quickly and exactly.
        return 1 << (msb + 1);
    }
};
