#K51352. Count Successful Sends
Count Successful Sends
Count Successful Sends
You are given a set of log entries recording message sending events in an organization. Each log entry is either a send
or an error
record. A send
record has the format "send <sender> to <receiver> at <time>" while an error
record has the format "error <sender> at <time>". For each query, given as a time interval \([t_1, t_2]\), you must determine the number of successful sends that occurred within that time interval. A send is considered successful if there is no corresponding error from the same sender at the same time.
Note: The logs may not be in sorted order by time. Each query is processed independently. The input is read from standard input and the output should be printed to standard output.
inputFormat
The first line contains two integers \(n\) and \(q\) representing the number of log entries and the number of queries, respectively. The next \(n\) lines each contain a log entry in one of the two formats:
send <sender> to <receiver> at <time>
error <sender> at <time>
The following \(q\) lines each contain two integers \(t_1\) and \(t_2\), representing a time interval.
outputFormat
For each of the \(q\) queries, output one integer on a new line representing the count of successful sends in the specified time interval. A successful send is defined as a send log entry for which there is no error log entry with the same sender and the same time.
## sample6 2
send Alice to Bob at 1
send Alice to Carol at 3
error Alice at 3
send Bob to Alice at 4
send Carol to Alice at 5
error Carol at 5
2 4
1 5
1
3
</p>