Using map and set || CPP
Data Structure Utilization:\n\nThe solution employs a combination of data structures, including vectors, maps, and sets, to efficiently manage the elements and 
Data Structure Utilization:\n\nThe solution employs a combination of data structures, including vectors, maps, and sets, to efficiently manage the elements and their indices.\nA map is used to store occurrences of each unique element in the array, with the element value as the key and a set of indices as the value.\nSets are utilized to track the indices of marked elements.\nQuery Processing:\n\nThe solution iterates through each query and performs operations to mark elements and update the sum of unmarked elements.\nIt calculates the sum of unmarked elements after each query, considering the conditions specified in the problem statement.\nOptimization:\n\nTo optimize the solution, it avoids unnecessary iterations and operations by utilizing data structures effectively.\nBy using sets to track marked elements, it ensures efficient removal and lookup operations.\nBenefits:\n\nThe solution offers an efficient approach to handle queries on arrays with marked and unmarked elements.\nIt provides a balance between simplicity and performance by leveraging appropriate data structures and algorithmic techniques\n\nMy contest solution:\n```\nclass Solution {\npublic:\n    vector<long long> unmarkedSumArray(vector<int>& nums, vector<vector<int>>& queries) {\n        vector<long long>ans;\n        long long sum=0,i,j,val,tsum=0;\n        map<long long,set<long long>>mp;\n        for(i=0;i<nums.size();i++){\n            //cout<<nums[i]<<" ";\n            sum=sum+nums[i];\n            mp[nums[i]].insert(i);\n        }\n        //cout<<sum<<" ";\n        for(auto x:queries){\n            if(sum!=0){\n            if(mp.find(nums[x[0]])!=mp.end()){\n                if(mp[nums[x[0]]].find(x[0])!=mp[nums[x[0]]].end()){\n                mp[nums[x[0]]].erase(x[0]);\n                if(mp[nums[x[0]]].size()==0){mp.erase(nums[x[0]]);}\n                sum=sum-nums[x[0]];\n                    //cout<<sum<<" ";\n            }}\n            long long val=x[1];\n            vector<long long>eras;\n            \n            for(auto z:mp){\n                if(val==0)break;\n                if(z.second.size()==val){\n                    eras.push_back(z.first);\n                    sum=sum-(val*z.first);\n                    //cout<<sum<<" ";\n                    break;\n                }\n                \n                if(z.second.size()<val){\n                    eras.push_back(z.first);\n                    val=val-(z.second.size());\n                    sum=sum-(z.second.size()*z.first);\n                    //cout<<z.first<<" ";\n                   //cout<<sum<<" "<<1<<" ";\n                }\n                \n                else if(z.second.size()>val){\n                    sum=sum-(val*z.first);\n                    //cout<<z.first<<" ";\n                    while(val!=0){\n                        auto it=mp[z.first].begin();\n                        mp[z.first].erase(it);\n                        val--;\n                    }\n                   // cout<<sum<<" "<<2<<" ";\n                    break;\n                }\n            }\n            \n            for(auto z:eras){\n                mp.erase(z);\n            }\n            \n            }\n            ans.push_back(sum);\n        }\n        return ans;\n    }\n};
[]