C++ solution. Sort by timestamp.
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:
    static bool compare(vector<string>& a, vector<string>& b) {
        if(stoi(a[1]) == stoi(b[1])) return a[0][0] > b[0][0]; // OFFLINE is prior to MESSAGE
        return stoi(a[1]) < stoi(b[1]);
    }
    vector<int> countMentions(int numberOfUsers, vector<vector<string>>& events) {
        vector<int> mentions(numberOfUsers, 0);
        vector<int> offline(numberOfUsers, -1);
        sort(events.begin(), events.end(), compare);
        for(int i = 0; i < events.size(); i++) {
            if(events[i][0] == "MESSAGE") {
                if(events[i][2] == "ALL") {
                    for(int j = 0; j < numberOfUsers; j++) mentions[j]++;
                }
                else if(events[i][2] == "HERE") {
                    for(int j = 0; j < numberOfUsers; j++) {
                        if(offline[j] == -1 || offline[j] + 60 <= stoi(events[i][1])) mentions[j]++;
                    }
                }
                else {
                    int start = 0;
                    for(int j = 0; j < events[i][2].length(); j++) {
                        if(events[i][2][j + 1] == ' ' || j == events[i][2].length() - 1) {
                            int temp = stoi(events[i][2].substr(start + 2, j - start - 1));
                            mentions[temp]++;
                            start = j + 2;
                        }
                    }
                }
            }
            if(events[i][0] == "OFFLINE") {
                offline[stoi(events[i][2])] = stoi(events[i][1]);
            }
        }
        return mentions;
    }
};
```
['C++']