Rust solution
IntuitionThe problem requires counting the number of times each user is mentioned in a series of events. There are three types of events:
OFFLINE: A user goes o
# Intuition
The problem requires counting the number of times each user is mentioned in a series of events. There are three types of events:

*    OFFLINE: A user goes offline, marking their status for the event.
*    MESSAGE: A message is sent, either mentioning specific users, all users, or just users that are currently online.

The key challenge is handling the timing of the events, especially the "offline" state of users. We need to track when users go offline and ensure they are counted correctly when messages are sent to them, even if they go offline for a while.
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
To solve this problem, we first initialize a vector to track the mentions for each user, a HashMap to store the offline times of users, and a HashSet to keep track of currently online users. We then sort the events by timestamp and process each event in order. For "OFFLINE" events, we mark the user as offline and update the offline_map. For "MESSAGE" events, we handle three cases: if the message is for all users, we increment mentions for all users; if the message is for users currently online, we increment mentions for those users; and if the message mentions specific users by ID, we update the mentions for those users. Additionally, we check and update offline users who have been offline for over 60 minutes, bringing them back online if necessary. Finally, we return the vector of mentions.
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity: O(ElogE + E×N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

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

# Code
```rust []
use std::collections::{HashMap, HashSet};

impl Solution {
    pub fn count_mentions(number_of_users: i32, events: Vec<Vec<String>>) -> Vec<i32> {
        let mut mentions = vec![0; number_of_users as usize];
        let mut offline_map: HashMap<i32, i32> = HashMap::new();
        let mut online_users: HashSet<i32> = (0..number_of_users).collect();

        let mut events = events;
        events.sort_by(|a, b| {
            let time_a: i32 = a[1].parse().unwrap();
            let time_b: i32 = b[1].parse().unwrap();
            if time_a != time_b {
                time_a.cmp(&time_b)
            } else {
                if a[0] == "OFFLINE" { std::cmp::Ordering::Less } else { std::cmp::Ordering::Greater }
            }
        });

        let mut curr_time = 0;

        for event in events {
            let event_type = &event[0];
            let timestamp: i32 = event[1].parse().unwrap();
            let data = &event[2];

            if timestamp > curr_time {
                curr_time = timestamp;

                let mut to_remove = Vec::new();

                for (&user_id, &offline_time) in offline_map.iter() {
                    if curr_time - offline_time >= 60 {
                        to_remove.push(user_id);
                        online_users.insert(user_id);
                    }
                }

                for user_id in to_remove {
                    offline_map.remove(&user_id);
                }
            }

            match event_type.as_str() {
                "OFFLINE" => {
                    let user_id: i32 = data.parse().unwrap();
                    online_users.remove(&user_id);
                    offline_map.insert(user_id, curr_time);
                }
                "MESSAGE" => {
                    if data == "ALL" {
                        for i in 0..number_of_users {
                            mentions[i as usize] += 1;
                        }
                    } else if data == "HERE" {
                        let mut to_remove = Vec::new();
                        for (&user_id, &offline_time) in offline_map.iter() {
                            if curr_time - offline_time >= 60 {
                                to_remove.push(user_id);
                                online_users.insert(user_id);
                            }
                        }

                        for user_id in to_remove {
                            offline_map.remove(&user_id);
                        }

                        for &user_id in online_users.iter() {
                            mentions[user_id as usize] += 1;
                        }
                    } else {
                        let tokens: Vec<&str> = data.split_whitespace().collect();
                        for token in tokens {
                            if token.starts_with("id") {
                                let user_id: i32 = token[2..].parse().unwrap();
                                mentions[user_id as usize] += 1;
                            }
                        }
                    }
                }
                _ => {}
            }
        }

        mentions
    }
}

```
['Array', 'Hash Table', 'Math', 'Ordered Map', 'Sorting', 'Simulation', 'Rust']