map<int,int>は使えないのか?
valueのデフォを0として、
int uniqval(int key ){
int ans = map[ key ] + key
map[ key ] = map[ key ] + 1
return ans; }
でいける気がするけど。