Clean and easy to understand explanation
IntuitionThe problem revolves around simulating user mentions while managing their online/offline statuses. To solve this:
Track User States: Maintain the curre
## **Intuition**
The problem revolves around simulating user mentions while managing their online/offline statuses. To solve this:

1. **Track User States**: Maintain the current status (online/offline) of users and ensure transitions (offline for 60 units) are handled accurately.
2. **Parse and Process Events**: Handle each event in the order of their timestamps:
   - For `"OFFLINE"`, mark the user as offline.
   - For `"MESSAGE"`, determine mentions based on the type (`HERE`, `ALL`, or specific users).
3. **Count Mentions**: Update the mention count for each user based on their state at the time of the message.
4. **Prioritize State Changes**: Ensure offline events are processed before any message at the same timestamp to maintain consistency.

## **Approach**
1. **Initialization**:
   - Create a `mentions` array of size `numberOfUsers` initialized to `0`.
   - Use a `set` to track offline users.
2. **Sort Events**:
   - Sort the events by timestamp.
   - Process `"OFFLINE"` events before `"MESSAGE"` events at the same timestamp.
3. **Process Events**:
   - For `"OFFLINE"`, mark the user offline and set their reactivation time.
   - For `"MESSAGE"`:
     - If `"HERE"`, count mentions for all online users.
     - If `"ALL"`, count mentions for all users.
     - If `"id<number>"`, count mentions for specific user IDs.
4. **Handle Offline Transition**:
   - When processing events, check if any offline user’s reactivation time has passed and mark them online.
5. **Return Results**:
   - After processing all events, return the `mentions` array.

# Complexity
- **Time Complexity**:
  - Sorting events: \(O(n \log n)\), where \(n\) is the number of events.
  - Processing events: \(O(n \cdot m)\), where \(m\) is the number of offline users at any time.
  - Total: \(O(n \log n + n \cdot m)\).
- **Space Complexity**:
  - Mentions array: \(O(u)\), where \(u\) is the number of users.
  - Offline users set: \(O(m)\).
  - Total: \(O(u + m)\).

# Code
```cpp []
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <unordered_map>

using namespace std;

bool compare(const vector<string>& a, const vector<string>& b) {
    if (stoi(a[1]) == stoi(b[1])) {
        return stoi(a[0]) < stoi(b[0]);
    }
    return stoi(a[1]) < stoi(b[1]);
}

class Solution {
public:
    vector<int> get_mentions(string s) {
        vector<int> mentions;
        string curr = "";
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == ' ') {
                int value = stoi(curr.substr(2));
                mentions.push_back(value);
                curr = "";
                continue;
            }
            curr += s[i];
        }
        int value = stoi(curr.substr(2));
        mentions.push_back(value);
        return mentions;
    }

    vector<int> countMentions(int users, vector<vector<string>>& events) {
        // Convert event types to numeric for sorting purposes
        for (int i = 0; i < events.size(); i++) {
            if (events[i][0] == "MESSAGE") {
                events[i][0] = "1";
            } else {
                events[i][0] = "0";
            }
        }

        // Sort events based on custom comparator
        sort(events.begin(), events.end(), compare);

        vector<int> output(users, 0);
        set<int> offline;
        unordered_map<string, int> user_id;

        for (int i = 0; i < events.size(); i++) {
            int current_time = stoi(events[i][1]);

            if (events[i][0] == "1") { // MESSAGE event
                if (events[i][2] == "HERE") {
                    // Handle "HERE" message
                    vector<int> online;
                    for (auto user_idx : offline) {
                        int time = stoi(events[user_idx][1]);
                        if (current_time >= 60 + time) {
                            online.push_back(user_idx);
                        }
                    }

                    for (auto new_online : online) {
                        offline.erase(new_online);
                        user_id[events[new_online][2]]--;
                        if (user_id[events[new_online][2]] == 0) {
                            user_id.erase(events[new_online][2]);
                        }
                    }

                    for (int m = 0; m < output.size(); m++) {
                        string id = to_string(m);
                        if (user_id.find(id) == user_id.end()) {
                            output[m]++;
                        }
                    }
                } else if (events[i][2] == "ALL") {
                    // Handle "ALL" message
                    for (auto& it : output) {
                        it++;
                    }
                } else {
                    // Handle mention-specific message
                    vector<int> mentions = get_mentions(events[i][2]);
                    for (int m = 0; m < mentions.size(); m++) {
                        output[mentions[m]]++;
                    }
                }
            } else { // OFFLINE event
                offline.insert(i);
                user_id[events[i][2]]++;
            }
        }

        return output;
    }
};

```
['Hash Table', 'Sorting', 'Ordered Set', 'C++']