SHORT AND EASY JAVA SOLUTION USING PRIORITY QUEUE O(NMLOGN)
Approach
sort array according to timestamp, if timestamp is same then offline one will come first
maintain a priority queue of offline users,
when we want to se

# Approach
<!-- Describe your approach to solving the problem. -->
- sort array according to timestamp, if timestamp is same then offline one will come first
- maintain a priority queue of offline users, 
- when we want to send messages, remove all users who became online from the priority queue

# Complexity
- Time complexity: O(n*m*logn), where n is number of users, m is event's length
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(n)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public int[] countMentions(int n, List<List<String>> events) {
        events.sort((a,b)->{
            int aa = Integer.parseInt(a.get(1));
            int bb = Integer.parseInt(b.get(1));
            if(aa != bb)return  aa - bb;
            return a.get(0).charAt(0) == 'O'? -1 : 1;
        });
        int[] ans = new int[n];
        PriorityQueue<int[]> pq = new PriorityQueue<>((a,b)->(a[1] - b[1]));
        for(List<String> event : events){
            int time = Integer.parseInt(event.get(1));
            while(!pq.isEmpty() && pq.peek()[1] <= time)pq.poll();
            if(event.get(0).charAt(0) == 'M'){
                if(event.get(2).charAt(0) != 'i')
                    for(int i=0;i<n;i++)ans[i]++;
                if(event.get(2).charAt(0) == 'H')
                    for(int[] x : pq)ans[x[0]]--;
                if(event.get(2).charAt(0) == 'i'){
                    String[] all  = event.get(2).split(" ");
                    for(String x : all){
                        int id = Integer.parseInt(x.substring(2));
                        ans[id]++;
                    }
                }
            }else 
                pq.add(new int[]{Integer.parseInt(event.get(2)),Integer.parseInt(event.get(1))+60});
            
        }
        return ans;
    }
}
```
['Java']