0032. Port control

Имя входного файла: control.in
Имя выходного файла: control.out
Ограничение по времени: 3 s
Ограничение по памяти: 64 megabytes

There are many different protocols designed for using with communication systems. One of them, called V5, is designed to communicate between two telephone stations. The first station, Access Network (AN) is a direct telephone service provider and so it works with end-users. The second, Local Exchange (LE) is the main station controlling the work of AN so all AN users are in fact LE users. This technology is used when there is, for example, one station for 10000 users in the small district, and there is another district with lack of telephone numbers.

Of course LE needs all information about users ports and also it should be able to send commands to all user ports such as blocking/unblocking, performance grading (for digital ISDN lines), etc. So for such purposes a special Layer 3 subprotocol is designed, called port control protocol. Of course all actions performed should be confirmed by another side and the next action may not be transmitted before the acknowledge to the current has got.

Your task is to implement the LE side of this protocol. There may be up to 4096 user ports on your station. Each port may got a command from your station at any time. These commands are to be forwarded to AN in order they have come. Remember that you are not allowed to send a command to the port before the previous command sent to this port has been acknowledged by AN.

Also there may come the port information messages from AN. You must forward these messages to your station and then acknowledge them to AN.

It is guaranteed that there will never come too many messages in total, the limitation for queued messages at any time is 40000. But any single port may have a huge number of messages waiting (of course no more than 40000).

Input file

The input file contain a sequence of incoming events, one event per line. The events allowed are the following:

  1. R port code – this is a request from your station to the specific port for execution of the action with code code.
  2. A port code – this is an acknowledge from AN notifiying the requested action with code code is successfully completed. If code differs from the last inacknowledged action code, this event is to be ignored.
  3. I port code – this message indicates reception of line information message from AN. The line information with code code must be forwarded to main part of your station.

The port numbers are any integer numbers in range from 0 to 109. The code parameter always lies in range 0…255. There will be no more than 4096 different ports.

The input file size is limited to 1000000 bytes.

Output file

Output all the events received and the actions performed, one per line. The actions are following:

  1. S port code – you sent a command request to AN.
  2. B port code – you sent a line information acknowledge to AN.
  3. J port code – you forwarded line information to your station.
Only single spaces are allowed as separators.

Examples:

control.incontrol.out
R 1 1 R 1 2 I 1 3 R 2 1 A 1 4 A 2 1 A 1 1 A 1 2 R 1 1 S 1 1 R 1 2 I 1 3 J 1 3 B 1 3 R 2 1 S 2 1 A 1 4 A 2 1 A 1 1 S 1 2 A 1 2


Источник: Petrozavodsk training camp, Summer 2002. Startup contest
Автор: Andrew Lopatin, Nick Durov

Обсудить       Отправить решение



Версия для печати