C++ segment tree easy to understand solution
```\nclass MajorityChecker {\n    public:\n    unordered_map> pos;\n    vector seg;\n    vector arr;\n    int seg_size;\n    int n;\n    \n    int nextPower_2( 
```\nclass MajorityChecker {\n    public:\n    unordered_map<int, vector<int>> pos;\n    vector<int> seg;\n    vector<int> arr;\n    int seg_size;\n    int n;\n    \n    int nextPower_2( unsigned int x) {\n        int  value = 1 ;\n        while( value <= x) {\n            value = value << 1;\n        }\n        return value;\n    }\n    \n    int get_occurrence(int num, int l, int r) {\n        auto iter = pos.find(num);\n        if (iter == pos.end()) {\n            return 0;\n        }\n        auto& vec = iter->second;\n        auto iter_l = lower_bound(vec.begin(), vec.end(), l);\n        if (iter_l == vec.end()) {\n            return 0;\n        }\n        auto iter_r = upper_bound(vec.begin(), vec.end(), r);\n        return iter_r - iter_l;\n    }\n    \n    void buildTree(int pos, int low, int high) {\n        if(low == high){\n            seg[pos] = arr[high];\n            return;\n        }\n        int mid = (low + high)/2;\n        buildTree(2*pos+1, low, mid);\n        buildTree(2*pos+2, mid+1, high);\n        \n        if(seg[2*pos + 1] != -1 && get_occurrence(seg[2*pos + 1], low, high) * 2 > high - low + 1)\n            seg[pos] = seg[2*pos + 1];\n         if(seg[2*pos + 2] != -1 && get_occurrence(seg[2*pos + 2], low, high) * 2 > high - low + 1)\n            seg[pos] = seg[2*pos + 2];\n    }\n    \n    pair<int, int> rangeMinQuery(int low, int high, int qLow, int qHigh, int pos) {\n        if(qLow <= low && qHigh >= high) {\n            int count = get_occurrence(seg[pos], qLow, qHigh);\n            if (count * 2 > qHigh - qLow + 1) {\n                return make_pair(seg[pos], count);\n            }\n            else {\n                return make_pair(-1, -1);\n            }\n        }     \n        if(qLow > high || qHigh < low)\n            return {-1, -1};\n        int mid = (low + high)/2;\n        pair<int,int> l =  rangeMinQuery(low, mid, qLow, qHigh, 2*pos+1);\n        pair<int,int> r = rangeMinQuery(mid+1, high, qLow, qHigh, 2*pos+2);\n        if(l.first != -1) return l;\n        if(r.first != -1) return r;\n        return {-1, -1};\n    }   \n    \n    MajorityChecker(vector<int>& a) {\n        n = a.size();\n        for (int i = 0; i < a.size(); ++i) {\n            pos[a[i]].push_back(i);\n            arr.push_back(a[i]);\n        }\n        seg_size = nextPower_2(n);\n        seg = vector<int>(2 * seg_size - 1, -1);\n        buildTree(0, 0, n - 1);\n    }\n    \n\n    \n    int query(int left, int right, int threshold) {\n        pair<int, int> temp = rangeMinQuery(0, n-1, left, right, 0);\n        if(temp.second >= threshold) return temp.first;\n        return -1;\n    }\n};
[]