#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 or more files and folders. No two files/folders in the same folder share the same name.
A user has three attributes:
- : user type.
- : user state (the operation the user is currently performing).
- : the user’s current position (i.e., the folder the user is currently browsing).
There are types of users: upload user , download user , and anonymous user .
There are types of operations: browse , download , and 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 : browse , upload .
- Download user : browse , download .
- Anonymous user : browse .
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:
- : the name (without spaces or line breaks).
- : the size (unit: , , , and a folder’s size is the sum of the sizes of all files it contains).
- : the current state, which has two possible values:
- : when a file/folder is in the normal state, users are allowed to operate on it.
- : in this state, users may only browse it. If one or more files in a folder are in the state, then the folder is also in the state.
In addition to its file resources, an FTP server has the following properties:
- The maximum number of accessing users (including all user types), . If the current number of accessing users has already reached the maximum, any new connection attempts will fail.
- The server’s maximum throughput .
- The maximum download/upload throughput allowed per user .
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 , in units of . Note that if, at some moment, the remaining size to upload/download () is less than , the upload/download still takes one full second.
How is determined?
$$\mathrm{userFlux} = \min(\mathrm{presentMaxUserFlux}, \mathrm{maxUserFlux})$$Here, is the server’s current per-user maximum throughput:
$$\mathrm{presentMaxUserFlux} = \lfloor \mathrm{maxServerFlux} / \mathrm{userTotal} \rfloor$$( 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:
command
- Format: 。
- Example: 。
- A user named requests to connect to the server with identity . If the current number of users has not reached and the user is not already connected, the connection succeeds and the server returns . Otherwise, it returns . Once connected successfully, the user’s position is set to the server’s root directory. denotes an upload user, denotes a download user, and denotes an anonymous user.
command
- Format: 。
- Example: 。
- The user named disconnects from the server. If the user is not connected, return ; otherwise, return . (Note that the user may disconnect in any state.)
command
- Format: 。
- Example: 。
- The user named attempts to enter a folder named within the current folder. If a folder named exists and is in the state, change the user’s current position and return . If the folder does not exist or the user is not successfully connected, return .
command
- Format: 。
- Example: 。
- The user named 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 ; otherwise, it returns and updates .
command
- Format: 。
- Example: 。
- The user named attempts to download a file or folder named in the current folder. If the user is not connected, the user lacks download permission, the file/folder named does not exist, or the file/folder is in the state, return ; otherwise, return 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.)
command
- Format: $\verb![name] + 空格 + upload + 空格 + [name1] + 空格 + [size]!$。
- Example: 。
- The user named attempts to upload, into the current folder, a file or folder named with size . Note:
- Uploading a folder via the command can only create an empty folder. When , it indicates uploading a folder; when , 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 ; otherwise, return and start uploading the file/folder. (If a user wishes to upload a non-empty folder, it can be achieved through a sequence of and 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 positive integers, representing $\text{maxUserNumber}, \text{maxServerFlux}, \text{maxUserFlux}$. The following lines describe the storage of the existing file resources on the .
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 . If , it indicates a folder; otherwise, it indicates a file of 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 . For example, means: at seconds after the server starts, a user named requests to connect to the server as an .
The last line of input is the string .
All command times 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 or , 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
京公网安备 11011102002149号