walk in a park✅Most Optimized✅100% || 40.5MB🚀88.24% || 18ms🔥💯
Approach :The Logic in the code is basically simulation. We simulate(efficiently) the process and store offline users and check at every turn if it's their time
![image.png](https://assets.leetcode.com/users/images/37b52b0d-f61a-4fb3-b439-98a5b3620447_1737922609.1449177.png)

# Approach :
<!-- Describe your approach to solving the problem. -->
###### The Logic in the code is basically simulation. We simulate`(efficiently)` the process and store offline users and check at every turn if it's their time to be online again. after that basically a bunch of if statements to do as the problem asks us to do :)
----
# Complexity :
- Time complexity: $O(n * m))$ `where n is number of users and m is events.size`
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: $O(n)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class customSort {
public:
    bool operator()(const vector<string>& a, const vector<string>& b) const {
        int time1 = stoi(a[1]);
        int time2 = stoi(b[1]);
        if(time1 == time2) {
            return a[0] == "OFFLINE";
        }

        return time1 < time2;
    }
};

class Solution {
public:
    vector<int> countMentions(int numberOfUsers, vector<vector<string>>& events) {
        sort(events.begin(), events.end(), customSort());
        // for(auto &event : events) {
        //     cout << event[0] << " " << event[1] << "\n";
        // }
        unordered_set<int> offlineUsers;
        int onlineUsersCnt = numberOfUsers;
        vector<int> ans(numberOfUsers);
        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> offline;
        for(auto &event : events) {
            while(!offline.empty() && offline.top().first <= stoi(event[1])) {
                // cout << "graah\n";
                offlineUsers.erase(offline.top().second);
                offline.pop();
            }
            if(event[0] == "MESSAGE") {
                if(event[2] == "HERE") {
                    for(int i = 0; i < numberOfUsers; ++i) {
                        if(offlineUsers.count(i))   continue;

                        ++ans[i];
                    } 
                }else if(event[2] == "ALL") {
                    for(int i = 0; i < numberOfUsers; ++i) {
                        ++ans[i];
                    } 
                }else {
                    for(int i = 2; i < event[2].size(); i += 3) {
                        int len = 0;
                        int iOrig = i;
                        while(i < event[2].size() && event[2][i] != ' ') {
                            ++i;
                            ++len;
                        }
                        // cout << "meow\n";
                        int user = stoi(event[2].substr(iOrig, len));
                        ++ans[user];
                    }
                }
            }else {
                // cout << "roar\n";
                offline.push({stoi(event[1]) + 60, stoi(event[2])});
                offlineUsers.insert(stoi(event[2]));
            }
        }
        return ans;
    }
};
```
['Hash Table', 'String', 'Heap (Priority Queue)', 'C++']