C++ Segment Tree With Discretization Solution
Code\n\nclass Solution {\npublic:\n    static const int maxn=2e5+5;\n    int seg[maxn<<2];\n    void update(int cur,int l,int r,int target,int val)\n    {\n    
# Code\n```\nclass Solution {\npublic:\n    static const int maxn=2e5+5;\n    int seg[maxn<<2];\n    void update(int cur,int l,int r,int target,int val)\n    {\n        if(l+1==r)\n        {\n            seg[cur]=max(seg[cur],val);\n            return;\n        }\n        int mid=(l+r)>>1;\n        if(target<mid)update(cur<<1,l,mid,target,val);\n        else update(cur<<1|1,mid,r,target,val);\n        seg[cur]=max(seg[cur<<1],seg[cur<<1|1]);\n    }\n    int query(int cur,int l,int r,int ql,int qr)\n    {\n        if(ql<=l&&r<=qr)return seg[cur];\n        if(l>=qr||r<=ql)return 0;\n        int mid=(l+r)>>1;\n        return max(query(cur<<1,l,mid,ql,qr),query(cur<<1|1,mid,r,ql,qr));\n    }\n    vector<int> maximumSumQueries(vector<int>& nums1, vector<int>& nums2, vector<vector<int>>& queries) \n    {\n        int n=nums1.size();\n        unordered_map<int,int>map_x,map_y;\n        set<int>set_x,set_y;\n        for(auto &x:nums1)set_x.insert(x);\n        for(auto &y:nums2)set_y.insert(y);\n        for(auto &x:queries)set_x.insert(x[0]),set_y.insert(x[1]);\n        for(auto &x:set_x)map_x[x]=map_x.size();\n        for(auto &y:set_y)map_y[y]=map_y.size();\n        vector<array<int,3>>nums(n);\n        for(int i=0;i<n;i++)nums[i]={map_x[nums1[i]],map_y[nums2[i]],nums1[i]+nums2[i]};\n        int m=queries.size();\n        vector<vector<int>>map_queries(m);\n        for(int i=0;i<m;i++)map_queries[i]={map_x[queries[i][0]],map_y[queries[i][1]],i};\n        sort(nums.begin(),nums.end(),greater<array<int,3>>());\n        sort(map_queries.begin(),map_queries.end(),greater<vector<int>>());\n        vector<int>res(m);\n        int idx=0;\n        for(int i=0;i<m;i++)\n        {\n            while(idx<n&&nums[idx][0]>=map_queries[i][0])\n            {\n                update(1,0,maxn,nums[idx][1],nums[idx][2]);\n                idx++;\n            }\n            res[map_queries[i][2]]=query(1,0,maxn,map_queries[i][1],maxn);\n        }\n        for(auto &x:res)if(x==0)x=-1;\n        return res;\n    }\n};\n```
['Segment Tree', 'C++']