Sorting Solution || O(NlogN + N*M)
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

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

# Code
```cpp []
class Solution {
public:
    vector<int> countMentions(int n, vector<vector<string>>& events) 
    {
        vector<int> user(n, 1);
        int m = events.size();
        for (int i = 0; i < m; i++)
        {
            if (events[i][0] == "OFFLINE") 
            {
                int a = stoi(events[i][1]) + 60;
                events.push_back({"ONLINE", to_string(a), events[i][2]});
            }
        }
        auto cmp = [](vector<string> &a, vector<string> &b)
        {
            if (a[1] != b[1])
                return stoi(a[1]) < stoi(b[1]);
            if (a[0] == "ONLINE") return true;
            if (b[0] == "ONLINE") return false;
            return a[0] == "OFFLINE";
        };
        sort(events.begin(), events.end(), cmp);
        vector<int> res(n, 0);
        for (auto &e:events)
        {
            if (e[0] == "MESSAGE")
            {
                if (e[2] == "HERE")
                {
                    add(res, user, 0);
                }
                if (e[2] == "ALL") add(res, user, 1);
                else
                {
                    stringstream ss(e[2]);
                    string token;
                    while (ss >> token) 
                    {
                        if (token.substr(0, 2) == "id")
                        {
                            int userIndex = stoi(token.substr(2));
                            res[userIndex]++;
                        }
                    }
                }
            }
            else if (e[0] == "OFFLINE")
            {
                // cout << e[2] << endl;
                user[stoi(e[2])] = 0;
            }
            else
            {
                // cout << e[2] << endl;
                user[stoi(e[2])] = 1;
            }
        }
        return res;
    }
private:
    void add(vector<int> &res, vector<int> &user, bool a)
    {
        for (int i = 0; i < res.size(); i++)
        {
            res[i] += (user[i] || a);
        }
        return;
    }
};
```
['C++']