You are building a notification system for multiple companies. Each company has a list of subscriber IDs, and each broadcast log describes one scheduled message.
Implement a function that processes all broadcast logs whose `scheduled_at` time falls within the inclusive range `[start_time, end_time]`, but only if they have not already been sent.
Because coding platforms usually cannot verify real side effects, simulate `send_subscriber_msg(subscriber_id, message)` by recording each delivery as a tuple `(subscriber_id, log_id, message)`.
Rules:
- A log should be processed only if `start_time <= scheduled_at <= end_time` and `sent == False`.
- Process logs in their original order.
- For each qualifying log, send the message to all subscribers of that log's company, in the order stored in the subscriber list.
- After processing a qualifying log, mark it as `sent = True`.
- If a company has no subscribers, the log is still considered processed and must still be marked as sent.
- Return the generated deliveries and the updated logs.
- Do not rely on mutating the caller's input; return the updated state explicitly.
Examples
Input: ({1: [101, 102], 2: [201]}, [{'log_id': 1, 'company_id': 1, 'message': 'A', 'scheduled_at': 5, 'sent': False}, {'log_id': 2, 'company_id': 2, 'message': 'B', 'scheduled_at': 8, 'sent': False}, {'log_id': 3, 'company_id': 1, 'message': 'C', 'scheduled_at': 10, 'sent': False}], 5, 8)
Expected Output: ([(101, 1, 'A'), (102, 1, 'A'), (201, 2, 'B')], [{'log_id': 1, 'company_id': 1, 'message': 'A', 'scheduled_at': 5, 'sent': True}, {'log_id': 2, 'company_id': 2, 'message': 'B', 'scheduled_at': 8, 'sent': True}, {'log_id': 3, 'company_id': 1, 'message': 'C', 'scheduled_at': 10, 'sent': False}])
Explanation: Logs scheduled at 5 and 8 are inside the inclusive window [5, 8]. Log 3 is outside.
Input: ({1: [7]}, [{'log_id': 1, 'company_id': 1, 'message': 'X', 'scheduled_at': 6, 'sent': True}, {'log_id': 2, 'company_id': 1, 'message': 'Y', 'scheduled_at': 9, 'sent': False}], 6, 9)
Expected Output: ([(7, 2, 'Y')], [{'log_id': 1, 'company_id': 1, 'message': 'X', 'scheduled_at': 6, 'sent': True}, {'log_id': 2, 'company_id': 1, 'message': 'Y', 'scheduled_at': 9, 'sent': True}])
Explanation: Log 1 is in the time window but is already sent, so only log 2 is processed.
Input: ({3: [30, 31]}, [{'log_id': 4, 'company_id': 3, 'message': 'Exact', 'scheduled_at': 12, 'sent': False}, {'log_id': 5, 'company_id': 3, 'message': 'Late', 'scheduled_at': 13, 'sent': False}], 12, 12)
Expected Output: ([(30, 4, 'Exact'), (31, 4, 'Exact')], [{'log_id': 4, 'company_id': 3, 'message': 'Exact', 'scheduled_at': 12, 'sent': True}, {'log_id': 5, 'company_id': 3, 'message': 'Late', 'scheduled_at': 13, 'sent': False}])
Explanation: Edge case: start and end times are equal, so only logs exactly at time 12 are processed.
Input: ({1: [1]}, [{'log_id': 6, 'company_id': 9, 'message': 'NoList', 'scheduled_at': 2, 'sent': False}], 1, 3)
Expected Output: ([], [{'log_id': 6, 'company_id': 9, 'message': 'NoList', 'scheduled_at': 2, 'sent': True}])
Explanation: The log is inside the window, but the company has no subscribers. It is still marked as sent.
Input: ({}, [], 0, 0)
Expected Output: ([], [])
Explanation: Edge case: no companies and no logs.