#P2262. [HNOI2004] FTP服务器

[HNOI2004] FTP服务器

Description

All resources on an FTP server are stored as files in a tree structure across different folders. The lowest level is the root directory (i.e., the root folder). The root directory contains several files and folders. Each folder may contain 00 or more files and folders. No two files/folders in the same folder share the same name.

A user has three attributes:

  • userType\text{userType}: user type.
  • userState\text{userState}: user state (the operation the user is currently performing).
  • userPosition\text{userPosition}: the user’s current position (i.e., the folder the user is currently browsing).

There are 33 types of users: upload user uploadUser\text{uploadUser}, download user downloadUser\text{downloadUser}, and anonymous user guest\text{guest}.

There are 33 types of operations: browse scan\text{scan}, download download\text{download}, and upload upload\text{upload}.

A user’s permissions are the operations that the user is allowed to perform. Different types of users have different permissions.

Permissions for each user type are as follows:

  • Upload user uploadUser\text{uploadUser}: browse scan\text{scan}, upload upload\text{upload}.
  • Download user downloadUser\text{downloadUser}: browse scan\text{scan}, download download\text{download}.
  • Anonymous user guest\text{guest}: browse scan\text{scan}.

No user may perform an operation outside their permissions. For example, an anonymous user is not allowed to download a file or folder.

A file/folder has three attributes:

  • fileName/folderName\text{fileName/folderName}: the name (without spaces or line breaks).
  • fileSize/folderSize\text{fileSize/folderSize}: the size (unit: byte\text{byte}, 0<fileSize<1050 < \mathrm{fileSize} < 10^5, 0<folderSize<1080 < \mathrm{folderSize} < 10^8, and a folder’s size is the sum of the sizes of all files it contains).
  • fileState/folderState\text{fileState/folderState}: the current state, which has two possible values:
    • normal\text{normal}: when a file/folder is in the normal state, users are allowed to operate on it.
    • uploading\text{uploading}: in this state, users may only browse it. If one or more files in a folder are in the uploading\text{uploading} state, then the folder is also in the uploading\text{uploading} state.

In addition to its file resources, an FTP server has the following properties:

  1. The maximum number of accessing users (including all user types), maxUserNumber<100\text{maxUserNumber} < 100. If the current number of accessing users has already reached the maximum, any new connection attempts will fail.
  2. The server’s maximum throughput maxServerFlux<107\text{maxServerFlux} < 10^7.
  3. The maximum download/upload throughput allowed per user maxUserFlux\text{maxUserFlux}.

The minimal time unit for running the FTP server is one second.

Each user can perform only one operation at any given moment. Downloading and uploading files/folders take time, which depends on the user’s throughput userFlux\text{userFlux}, in units of byte/second\text{byte/second}. Note that if, at some moment, the remaining size to upload/download (>0> 0) is less than userFlux\text{userFlux}, the upload/download still takes one full second.

How is userFlux\text{userFlux} determined?

$$\mathrm{userFlux} = \min(\mathrm{presentMaxUserFlux}, \mathrm{maxUserFlux})$$

Here, presentMaxUserFlux\text{presentMaxUserFlux} is the server’s current per-user maximum throughput:

$$\mathrm{presentMaxUserFlux} = \lfloor \mathrm{maxServerFlux} / \mathrm{userTotal} \rfloor$$

(userTotal\text{userTotal} denotes the number of users currently performing upload and download operations at that moment.)

A user interacts with the FTP server through a sequence of commands. The commands are introduced below:

connect\verb!connect! command

  • Format: [name] + 空格 + connect + 空格 + 参数A\verb![name] + 空格 + connect + 空格 + 参数A!
  • Example: tsinghua connect 1\verb!tsinghua connect 1!
  • A user named name\verb!name! requests to connect to the server with identity A\verb!A!. If the current number of users has not reached maxUserNumber\text{maxUserNumber} and the user is not already connected, the connection succeeds and the server returns success\verb!success!. Otherwise, it returns unsuccess\verb!unsuccess!. Once connected successfully, the user’s position userPosition\text{userPosition} is set to the server’s root directory. A=1A = 1 denotes an upload user, A=2A = 2 denotes a download user, and A=3A = 3 denotes an anonymous user.

quit\verb!quit! command

  • Format: [name] + 空格 + quit\verb![name] + 空格 + quit!
  • Example: tsinghua quit\verb!tsinghua quit!
  • The user named name\verb!name! disconnects from the server. If the user is not connected, return unsuccess\verb!unsuccess!; otherwise, return success\verb!success!. (Note that the user may disconnect in any state.)

cd\verb!cd! command

  • Format: [name] + 空格 + cd + 空格 + [folderName/文件夹名称]\verb![name] + 空格 + cd + 空格 + [folderName/文件夹名称]!
  • Example: THU cd FD\verb!THU cd FD!
  • The user named name\verb!name! attempts to enter a folder named folderName\text{folderName} within the current folder. If a folder named folderName\text{folderName} exists and is in the normal\text{normal} state, change the user’s current position userPosition\text{userPosition} and return success\verb!success!. If the folder does not exist or the user is not successfully connected, return unsuccess\verb!unsuccess!.

cd..\verb!cd..! command

  • Format: [name] + 空格 + cd..\verb![name] + 空格 + cd..!
  • Example: 9# cd..\verb!9# cd..!
  • The user named name\verb!name! attempts to move from the current folder to its parent folder. If the user is at the root directory or is not connected, the command fails and returns unsuccess\verb!unsuccess!; otherwise, it returns success\verb!success! and updates userPosition\text{userPosition}.

download\verb!download! command

  • Format: [name] + 空格 + download + 空格 + [name1]\verb![name] + 空格 + download + 空格 + [name1]!
  • Example: A download 1.txt\verb!A download 1.txt!
  • The user named name\verb!name! attempts to download a file or folder named name1\verb!name1! in the current folder. If the user is not connected, the user lacks download permission, the file/folder named name1\verb!name1! does not exist, or the file/folder is in the uploading\text{uploading} state, return unsuccess\verb!unsuccess!; otherwise, return success\verb!success! and start downloading the file/folder. (Once a download command starts, the user downloads the snapshot of that file/folder at the moment the command begins. That is, if another user uploads a new file into that folder during the download, the original downloading user cannot obtain that newly uploaded file.)

upload\verb!upload! command

  • Format: $\verb![name] + 空格 + upload + 空格 + [name1] + 空格 + [size]!$。
  • Example: A upload B 1\verb!A upload B 1!
  • The user named name\verb!name! attempts to upload, into the current folder, a file or folder named name1\verb!name1! with size size\text{size}. Note:
    • Uploading a folder via the upload\verb!upload! command can only create an empty folder. When size=0\text{size} = 0, it indicates uploading a folder; when size>0\text{size} > 0, it indicates uploading a file.
    • If a file/folder with the same name already exists in the current directory, or the user is not successfully connected, or the user lacks upload permission, return unsuccess\verb!unsuccess!; otherwise, return success\verb!success! and start uploading the file/folder. (If a user wishes to upload a non-empty folder, it can be achieved through a sequence of upload\verb!upload! and cd\verb!cd! commands.)

Except for upload and download commands, all other commands take no execution time.

Your task is to simulate the operation of an FTP server over a period of time.

Input Format

First, you will read the initial information of the FTP server. The first line contains 33 positive integers, representing $\text{maxUserNumber}, \text{maxServerFlux}, \text{maxUserFlux}$. The following lines describe the storage of the existing file resources on the server\text{server}.

The first line always describes one file or folder in the root directory.

If a line describes a file or a folder, it has the form name + 空格 + size\verb!name + 空格 + size!. If size=0\text{size} = 0, it indicates a folder; otherwise, it indicates a file of size size\text{size}.

If a line describes a folder, then the subsequent lines describe the contents of that folder until a matching minus sign appears. This description is recursive. Since the description starts from all files and folders in the root directory, the last line of the file information is also a minus sign. (See the sample input.)

Each of the following lines is given in the form time + 空格 + order\verb!time + 空格 + order!. For example, 4 ares connect 1\verb!4 ares connect 1! means: at 44 seconds after the server starts, a user named ares\verb!ares! requests to connect to the server as an uploadUser\text{uploadUser}.

The last line of input is the string down\verb!down!.

All command times time\text{time} are non-decreasing according to their appearance order. Commands issued at the same time are executed in the order they appear in the input.

Output Format

Output several lines, each containing success\verb!success! or unsuccess\verb!unsuccess!, indicating whether each operation succeeds.

5 200 200
unzip.exe 100
xxxx 50
bin 0
tpx.exe 200
turbo.exe 300
tpx.tp 400
temp 0
-
-
readme.txt 100
-
0 ares connect 2
0 ares download zip.exe
1 ares download bin
5 ares download xxxx
6 ares cd bin
6 ares connect 1
6 ares quit
7 ares connect 1
7 rosen connect 2
7 ares cd bin
8 ares upload A 300
9 rosen download bin
10 rosen download bin
down

success
unsuccess
success
unsuccess
success
unsuccess
success
success
success
success
success
unsuccess
success

Hint

Source: HNOI2004 (modified).

Translated by ChatGPT 5