easy cpp solution to understand
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 cmp(const vector<string>& a, const vector<string>& b) {
        int time_a = stoi(a[1]);
        int time_b = stoi(b[1]);
        
        if (time_a != time_b) 
            return time_a < time_b;
        return a[0] == "OFFLINE";
    }

    vector<int> countMentions(int numberOfUsers, vector<vector<string>>& events) {
        int n = events.size();
        vector<int> vec(numberOfUsers, 0);
        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> st;
        vector<int> pq(numberOfUsers, 0);

        sort(events.begin(), events.end(), cmp);

        for (int i = 0; i < n; i++) {
            vector<string> temp = events[i];
            cout << temp[0] << "  " << temp[1] << endl;
            if (temp[0] == "MESSAGE") {
                string str = temp[2];
                if (str == "ALL") {
                    string times = temp[1];
                    int curr_time = 0;
                    for (char j : times) {
                        curr_time *= 10;
                        curr_time += (j - '0');
                    }
                    while (!st.empty() && st.top().first <= curr_time) {
                        int id = st.top().second;
                        st.pop();
                        pq[id]--;
                    }
                    for (int j = 0; j < numberOfUsers; j++) {
                        vec[j]++;
                    }
                } else if (str == "HERE") {
                    string times = temp[1];
                    int curr_time = 0;
                    for (char j : times) {
                        curr_time *= 10;
                        curr_time += (j - '0');
                    }
                    while (!st.empty() && st.top().first <= curr_time) {
                        int id = st.top().second;
                        st.pop();
                        pq[id]--;
                    }
                    for (int j = 0; j < numberOfUsers; j++) {
                        if (pq[j] == 0) vec[j]++;
                    }
                } else {
                    string times = temp[1];
                    int curr_time = 0;
                    for (char j : times) {
                        curr_time *= 10;
                        curr_time += (j - '0');
                    }
                    while (!st.empty() && st.top().first <= curr_time) {
                        int id = st.top().second;
                        st.pop();
                        pq[id]--;
                    }
                    string str = temp[2];
                    str += " ";
                    int size = str.size();
                    int num = 0;
                    for (int j = 0; j < size; j++) {
                        if (str[j] == 'i') continue;
                        else if (str[j] == 'd') continue;
                        if (isdigit(str[j])) {
                            num *= 10;
                            num += (str[j] - '0');
                        } else if (str[j] == ' ') {
                            vec[num]++;
                            num = 0;
                        }
                    }
                }
            } else if (temp[0] == "OFFLINE") {
                string user = temp[2];
                int user_id = 0;
                for (char j : user) {
                    user_id *= 10;
                    user_id += (j - '0');
                }
                string times = temp[1];
                int curr_time = 0;
                for (char j : times) {
                    curr_time *= 10;
                    curr_time += (j - '0');
                }
                while (!st.empty() && st.top().first <= curr_time) {
                    int id = st.top().second;
                    st.pop();
                    pq[id]--;
                }
                if (pq[user_id] == 1) {
                    st.push({curr_time + 60, user_id});
                    pq[user_id]++;
                } else {
                    st.push({curr_time + 60, user_id});
                    pq[user_id] = 1;
                }
            }
        }

        return vec;
    }
};

```
['C++']