Mark Elements on Array by Perferming Quieries
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\nTime co
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\nTime complexity: O(nlogn) -->\n\nSpace complexity: O(n)\n# Code\n```java []\nclass Solution {\n    public long[] unmarkedSumArray(int[] nums, int[][] queries) {\n        HashSet<Integer> nm = new HashSet<>();\n        PriorityQueue<Integer> pq =new PriorityQueue<>();\n        long val= 0 ;\n        for(int i=0;i<nums.length;i++)\n        {\n            nm.add(i);\n            pq.add(nums[i]);\n            val+=nums[i];\n        }\n        int lent = queries.length;\n        \n        HashMap<Integer,Queue<Integer>> h = new HashMap<>();\n        for(int i=0;i<nums.length;i++){\n            \n            int val1 = nums[i];\n            if(h.get(val1)==null){\n                Queue<Integer> q = new LinkedList<>();\n                q.add(i);\n                h.put(val1,q);\n            }else{\n                Queue<Integer>  q= h.get(val1);\n                q.add(i);\n            }\n        }\n        long ans[] = new long[lent];\n        for(int i=0;i<lent;i++)\n        {\n            int left = queries[i][0];\n            int right = queries[i][1];   \n            long sum = 0;\n            if(nm.contains(left)){\n                nm.remove(left);\n                val-=nums[left];\n            }\n            \n            while(right>0)\n            {    \n                if(pq.size()>0)\n                {\n                    int val2 = pq.poll();\n                    Queue<Integer> indexes = h.get(val2);\n                    int ind3 = indexes.remove();\n                    \n                    if(nm.contains(ind3))\n                    {\n                        right--;\n                        nm.remove(ind3);\n                        val-=nums[ind3];\n                    }\n                }\n                else\n                {\n                    break;\n                }\n            }\n            ans[i] = val;\n        }\n        return ans;\n    }\n}\n```
['Java']