Sorting + Simulation | O(nlogn)
ApproachJust simulate the events, but pay attention to the sequence of each event:
We need to sort the events according to the timestamp first, and then accordi
# Approach
<!-- Describe your approach to solving the problem. -->
Just simulate the events, but **pay attention to the sequence of each event**:
- We need to sort the events according to the timestamp first, and then according to the event type (Offline happens first if the timestamp is the same).
- Deal with each event in sorted order.

1. Message Event
  - `mentions_string = "ALL"`: plus one mention for **all** users.
  - `mentions_string = "HERE"`: plus one mention for **online** users.
  - `mentions_string = <ids>`: seperate each id and plus one for that user (**can mention one user more than one time**).
2. Offline Event
  - user will automatically be online again at time `timestamp + 60`.

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

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

# Code
```cpp []
class Solution {
   public:
    vector<int> countMentions(int numberOfUsers, vector<vector<string>>& events) {
        auto compare = [](const vector<string>& v1, const vector<string>& v2) {
            int timestamp1 = stoi(v1[1]);
            int timestamp2 = stoi(v2[1]);
            if (timestamp1 == timestamp2) {
                return v1[0] > v2[0];
            }
            return timestamp1 < timestamp2;
        };
        sort(events.begin(), events.end(), compare);

        vector<int> onlineTimes(numberOfUsers, 0);
        vector<int> mentions(numberOfUsers, 0);
        for (auto& event : events) {
            string eventType = event[0], timestamp = event[1], mentionsString = event[2];
            if (eventType == "MESSAGE") {
                dealMessage(onlineTimes, mentions, stoi(timestamp), mentionsString);
            } else {
                dealOffline(onlineTimes, stoi(timestamp), mentionsString);
            }
        }
        return mentions;
    }

   private:
    void dealMessage(vector<int>& onlineTimes, vector<int>& mentions, int timestamp, string& mentionsString) {
        int n = onlineTimes.size();
        if (mentionsString == "ALL") {
            for (int& mention : mentions) ++mention;
        } else if (mentionsString == "HERE") {
            for (int i = 0; i < n; ++i) {
                if (onlineTimes[i] <= timestamp) {
                    ++mentions[i];
                }
            }
        } else {
            istringstream iss(mentionsString);
            string token;
            vector<int> ids(n, 0);

            while (iss >> token) {
                if (token.find("id") == 0) {
                    int i = stoi(token.substr(2));
                    ++ids[i];
                }
            }
            for (int i = 0; i < n; ++i) {
                mentions[i] += ids[i];
            }
        }
    }

    void dealOffline(vector<int>& onlineTimes, int timestamp, string& mentionsString) {
        int i = stoi(mentionsString);
        onlineTimes[i] = timestamp + 60;
    }
};
```
['C++']