#K67622. Calculate Branch Visit Times

    ID: 32684 Type: Default 1000ms 256MiB

Calculate Branch Visit Times

Calculate Branch Visit Times

You are given an integer \( m \) representing the number of branches and a sequence of log entries which denote when visitors start and end their visits at various branches. Each log entry is a string in the format:

\( branch\_id:visit\_id:action:timestamp \)

where:

  • \( branch\_id \) is an integer in the range \( [0, m-1] \), identifying the branch.
  • \( visit\_id \) is an integer that uniquely identifies a particular visit.
  • \( action \) is either "start" or "end".
  • \( timestamp \) is an integer representing the time of the event.

Your task is to compute the total visit time for each branch. For each visit, the visit time is calculated as the difference between the end timestamp and the start timestamp. It is guaranteed that every start event has a corresponding end event.

Note: The input is read from stdin and the output should be printed to stdout.

inputFormat

The input is given via stdin in the following format:

 m
 n
 log1
 log2
 ...
 logn

Where:

  • m is the number of branches.
  • n is the number of log entries.
  • Each of the next n lines is a log entry in the format branch_id:visit_id:action:timestamp.

outputFormat

Output a single line with \( m \) integers separated by a space. Each integer represents the total visit time for the branch with the corresponding index (from 0 to \( m-1 \)).

## sample
2
6
1:100:start:5
1:100:end:10
0:101:start:1
1:102:start:11
1:102:end:15
0:101:end:3
2 9

</p>