Sort and simulate
Code

# Code
```cpp []
#include <bits/stdc++.h>
using namespace std;

#define PB push_back
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(), (v).end()

class Solution {
public:
    class Event {
    private:
        string type;
        int ttp;
        vector<string> data;
        int oi;

    public:
        Event(const vector<string>& ed, int idx) {
            type = ed[0];
            ttp = stoi(ed[1]);
            data = vector<string>(ed.begin() + 2, ed.end());
            oi = idx;
        }

        const string& gT() const { return type; }
        int GTPS() const { return ttp; }
        const vector<string>& gD() const { return data; }
        int GHoI() const { return oi; }
    };

    vector<int> countMentions(int numberOfUsers, vector<vector<string>>& events) {
        vector<Event> vv;
        for (int i = 0; i < SZ(events); ++i) {
            vv.PB(Event(events[i], i));
        }

        sort(ALL(vv), [](const Event& a, const Event& b) {
            if (a.GTPS() != b.GTPS()) {
                return a.GTPS() < b.GTPS();
            }
            bool aOOFF = (a.gT() == "OFFLINE");
            bool bOOFF = (b.gT() == "OFFLINE");
            if (aOOFF != bOOFF) return aOOFF;
            return a.GHoI() < b.GHoI();
        });

        vector<int> mtio(numberOfUsers, 0);
        vector<int> OUu(numberOfUsers, 0);

        for (const Event& event : vv) {
            const string& type = event.gT();
            int ttp = event.GTPS();
            const vector<string>& data = event.gD();

            if (type == "OFFLINE") {
                int UI = stoi(data[0]);
                OUu[UI] = ttp + 60;
            } else if (type == "MESSAGE") {
                const string& mentionsStr = data[0];
                istringstream iss(mentionsStr);
                string tk;

                while (iss >> tk) {
                    if (tk == "ALL") {
                        for (int j = 0; j < numberOfUsers; ++j) {
                            mtio[j]++;
                        }
                    } else if (tk == "HERE") {
                        for (int j = 0; j < numberOfUsers; ++j) {
                            if (ttp >= OUu[j]) {
                                mtio[j]++;
                            }
                        }
                    } else if (tk.substr(0, 2) == "id") {
                        int UI = stoi(tk.substr(2));
                        if (UI >= 0 && UI < numberOfUsers) {
                            mtio[UI]++;
                        }
                    }
                }
            }
        }

        return mtio;
    }
};
```
['C++']