Simple and Easy C++ Solution with Explanation
IntuitionJust doing whatever asked based on the command "MESSAGE" or "OFFLINE"ApproachFirst we have to sort the array based on time stamps to ensure that the us
# Intuition
Just doing whatever asked based on the command **"MESSAGE"** or **"OFFLINE"**

# Approach
First we have to sort the array based on time stamps to ensure that the users are marked offline at correct time and to ensure message is not mentioned to offline users.
If timestamps are same the one containing "OFFLINE" should come before "MESSAGE" to ensure we do not mention to offline users.
I have then kept a vector named online which contain the time stamp where the ith user becomes online again . Initially the values are set to 0(all users are online at timestamp 0).
Now if the command is "OFFLINE" then we will fetch the user id and update the online vector online[user] to timestamp+60 so that we can track the time where the user becomes online again
If the command is "MESSAGE" then we have three cases -
1) "ALL" - if this is given then we will just update all the values in our ans vector by 1. I have done it seperately in function named ***update***.
2) "HERE" - if this is given then we will update those users which are online at the given timestamp. This is done in a seperate function named ***updateOnline***
3) "specific ids" - If specific ids are given then I have fetched those ids from the string by using simple for loop and updated ans[id] by 1

These were the cases which are possible in the entire problem statement
This was the most simplest approach I could think of and if you also found it simple and good then please upvote 

# Complexity
- Time complexity:
O(nlogn)

- Space complexity:
O(n)

# Code
```cpp []
class Solution {
public:
    void update(vector<int>& ans) {
        for (int i = 0; i < ans.size(); i++) {
            ans[i]++;
        }
        return;
    }
    void updateOnline(vector<int>& ans, vector<int>& online, int timestamp) {
        for (int i = 0; i < ans.size(); i++) {
            if (online[i] <= timestamp) {
                ans[i]++;
            }
        }
        return;
    }
    vector<int> countMentions(int numberOfUsers,
                              vector<vector<string>>& events) {
        vector<int> online(numberOfUsers, 0);
        vector<int> ans(numberOfUsers, 0);
        auto comparator = [](const vector<string>& a, const vector<string>& b) {
            int timestampA = stoi(a[1]);
            int timestampB = stoi(b[1]);

            if (timestampA != timestampB) {
                return timestampA < timestampB;
            }
            return a[0] == "OFFLINE" && b[0] == "MESSAGE";
        };
        sort(events.begin(), events.end(), comparator);
        for (auto it : events) {
            string command = it[0];
            int timestamp = stoi(it[1]);
            string take = it[2];
            if (command == "OFFLINE") {
                int user = stoi(take);
                online[user] = timestamp + 60;
            } else if (command == "MESSAGE") {
                if (take == "ALL") {
                    update(ans);
                } else if (take == "HERE") {
                    updateOnline(ans, online, timestamp);
                } else {
                    string num = "";
                    for (int i = 0; i < take.length(); i++) {
                        if (take[i] == 'i' || take[i] == 'd') {
                            continue;
                        } else if (take[i] == ' ') {
                            int id = stoi(num);
                            ans[id]++;
                            num = "";
                        } else {
                            num.push_back(take[i]);
                        }
                    }
                    int lastId = stoi(num);
                    ans[lastId]++;
                }
            }
        }
        return ans;
    }
};
```
['C++']