C++ | Event based sorting + Queue
Code

# Code
```cpp []
class Solution {
public:
    #define pp pair<int,int>
    vector<int> countMentions(int n, vector<vector<string>>& events) 
    {
        vector<int>count(n,0);
        queue<pp>offline;
        vector<bool>online(n,true);
        sort(events.begin(), events.end(), [&](auto &a, auto &b){
            if(stoi(a[1])==stoi(b[1])) 
                return a[0]=="OFFLINE";  
            return stoi(a[1])<stoi(b[1]);
        });
        for(auto &e:events)
        {
            int ts=stoi(e[1]);
            while(!offline.empty() && offline.front().first<=ts)
            {
                online[offline.front().second]=true;
                offline.pop();
            }
            if(e[0]=="MESSAGE")
            {
                if(e[2]=="ALL")
                {
                    for(int i=0;i<n;i++)
                       count[i]++;
                }
                else if(e[2]=="HERE")
                {
                    for(int i=0;i<n;i++)
                        count[i]+=online[i];  
                }
                else
                {
                    e[2]+=" ";
                    string a="";
                    for(auto &c:e[2])
                    {
                        if(c==' ')
                        {
                            count[stoi(a)]++;
                            a="";
                        } 
                        else if(isdigit(c))  
                           a+=c;
                    }
                }
            }
            else
            {
                int id=stoi(e[2]);
                online[id]=false;
                offline.push({ts+60,id});
            }
        }
        return count;
    }
};
```
['C++']