C++ solution 
IntuitionThe problem involves tracking the number of mentions each user receives in a chat application based on various events like messages or users going offl
# Intuition
The problem involves tracking the number of mentions each user receives in a chat application based on various events like messages or users going offline. We need to efficiently handle events, taking into account time-sensitive conditions and ensuring accurate mention counts even when users temporarily go offline.

## Key challenges include:

Distinguishing between messages sent to all users, currently online users, or specific users.
Handling offline status, where mentions might depend on the duration a user has been offline.
Processing events chronologically while maintaining the state of each user.
# Approach
We tackle the problem by simulating the event sequence and maintaining the state of each user. Here's the step-by-step breakdown:

## Data Structures:

A res vector of size n to store the mention counts for each user.
A online vector of size n, where each entry is a pair (is_online, last_offline_time). This helps track whether a user is currently online and when they last went offline.
Event Sorting:

Since the events must be processed in chronological order, we sort the events by time. If two events have the same time, we prioritize OFFLINE events before others.
Event Processing:

For each event, we determine its type:
"MESSAGE":
If the message is sent to "ALL", every user's mention count is incremented.
If the message is sent to "HERE", we check each user's status:
If the user is online, increment their mention count.
If offline, check if they’ve been offline for at least 60 seconds. If so, treat them as online again and increment their count.
If the message is sent to a specific user (e.g., id<num>), extract the user ID and increment their mention count.
"OFFLINE":
Mark the specified user as offline and update their last_offline_time.
Output the Result:

After processing all events, the res vector contains the final mention counts for all users.


##### Problem is tough to understand so give your best :-)
# Code
```cpp []
class Solution {
public:
    vector<int> countMentions(int n, vector<vector<string>>& events) {
        vector <int> res(n , 0) ; 
        vector<pair <int , int> > online(n , {1,0}) ; 
        sort(events.begin(), events.end(), [](const vector<string>& a, const vector<string>& b) {
        int timeA = stoi(a[1]);
        int timeB = stoi(b[1]);
        if (timeA != timeB) {
            return timeA < timeB; 
        }
        return a[0] == "OFFLINE"; 
    });
        for (auto s : events){
            
                if (s[0] == "MESSAGE"){
                    if (s[2] == "ALL"){
                        for (int j = 0 ; j < n ; j++){
                            res[j]++ ; 
                        }
                             
                    }
                    else if (s[2] == "HERE"){
                        for (int j = 0 ; j < n ; j++){
                            if (online[j].first == 1) res[j]+=1 ; 
                            else {
                                if (stoi(s[1] ) - online[j].second >= 60 ){
                                    online[j] = {1,0} ; 
                                    res[j]++ ; 
                                }
                            }
                        }
                         
                    }
                    else {
                        for (int id = 0 ; id < s[2].length(); id++){
                            if (s[2][id] == 'd' and s[2][id-1] == 'i'){
                                int numid= 0 ;  
                                id++; 
                                while (id < s[2].length() and isdigit(s[2][id])){
                                    numid = numid*10 +  (s[2][id++] - '0') ; 
                                }
                                
                                res[numid] += 1 ;
                            }
                        
                        }  
                    }
                }
                else {
                    int numid = stoi(s[2]) ;
                    online[numid].first =  0 ; 
                    online[numid].second = stoi(s[1]); 
                    
                    
                    
                    
                }
            
        }
        return res ; 
    }
};
```
['C++']