Segment Tree + Offline Query + Sorting + Sweepline
\n# Code\n\nbool comp(vector<int>& a, vector<int>& b){\n    if(a[0] == b[0]){\n        if(a[1] == b[1]){\n            return a[2] > b[2];\n        }\n        el
\n# Code\n```\nbool comp(vector<int>& a, vector<int>& b){\n    if(a[0] == b[0]){\n        if(a[1] == b[1]){\n            return a[2] > b[2];\n        }\n        else{\n            return a[1] > b[1];\n        }\n    }\n    else{\n        return a[0] > b[0];\n    }\n}\n\nclass Solution {\npublic:\n    vector<int>stree;\n    void update(int tidx, int s, int e, int idx, int val){\n        if(s == e){\n            stree[tidx] = val;\n            return;\n        }\n        int mid = (s + e)/2;\n        if(idx <= mid){\n            update(2*tidx, s, mid, idx, val);\n        }\n        else{\n            update(2*tidx+1, mid+1, e, idx, val);\n        }\n        stree[tidx] = max(stree[2*tidx], stree[2*tidx+1]);\n    }\n\n    int queri(int tidx, int s, int e, int l, int r){\n        if(s > r or e < l){\n            return -1;\n        }\n        else if(s >= l and e <= r){\n            return stree[tidx];\n        }\n        int mid = (s + e)/2;\n        int left_ans = queri(2*tidx, s, mid, l, r);\n        int right_ans = queri(2*tidx+1, mid+1, e, l, r);\n\n        return max(left_ans, right_ans);\n    }\n\n    vector<int> maximumSumQueries(vector<int>& nums1, vector<int>& nums2, vector<vector<int>>& query) {\n        int n = nums1.size(); int q = query.size();\n        vector<vector<int>>srtArr;\n        set<int>s;\n        for(int i=0;i<n;i++){\n            s.insert(nums2[i]);\n        }\n        for(int i=0;i<q;i++){\n            s.insert(query[i][1]);\n        }\n        map<int,int> mapping;\n        int pos = 1;\n        for(auto nuts:s){\n            mapping[nuts] = pos++; \n        }\n        pos++;\n        for(int i=0;i<n;i++){\n            srtArr.push_back({nums1[i], mapping[nums2[i]], nums1[i] + nums2[i]});\n        }\n        map<pair<int,int>, vector<int>>index;\n        for(int i=0;i<q;i++){\n            srtArr.push_back({query[i][0], mapping[query[i][1]], -1});\n            index[{query[i][0], mapping[query[i][1]]}].push_back(i);\n        }\n        sort(srtArr.begin(), srtArr.end(), comp);\n        stree.clear();\n        stree = vector<int>(4*pos + 1, -1);\n        vector<int>vp(pos+1, -1);\n        vector<int>sol(q);\n        for(int i=0;i<((int)srtArr.size());i++){\n            int x = srtArr[i][0], y = srtArr[i][1], z = srtArr[i][2];\n            if(z == -1){\n                // query\n                int as = -1;\n                as = queri(1, 0, pos-1, y, pos+1);\n                pair<int, int> P = {x, y};\n                for(int j:index[P]){\n                    sol[j] = as;\n                }\n            }\n            else{\n                if(vp[y] < z){\n                    update(1, 0, pos-1, y, z);\n                    vp[y] = z;\n                }\n            }\n        }\n\n        return sol;\n    }\n};\n```
['Binary Indexed Tree', 'Segment Tree', 'Ordered Map', 'C++']