P2262 [HNOI2004] FTP Server
Background
File Transfer Protocol, abbreviated as FTP, enables resource sharing. Typically, users browse resources on an FTP server through a file-explorer-like interface, and users with different permissions can download files/folders and upload files/folders.
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 $0$ or more files and folders. No two files/folders in the same folder share the same name.
A user has three attributes:
- $\text{userType}$: user type.
- $\text{userState}$: user state (the operation the user is currently performing).
- $\text{userPosition}$: the user’s current position (i.e., the folder the user is currently browsing).
There are $3$ types of users: upload user $\text{uploadUser}$, download user $\text{downloadUser}$, and anonymous user $\text{guest}$.
There are $3$ types of operations: browse $\text{scan}$, download $\text{download}$, and 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 $\text{uploadUser}$: browse $\text{scan}$, upload $\text{upload}$.
- Download user $\text{downloadUser}$: browse $\text{scan}$, download $\text{download}$.
- Anonymous user $\text{guest}$: browse $\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:
- $\text{fileName/folderName}$: the name (without spaces or line breaks).
- $\text{fileSize/folderSize}$: the size
(unit: $\text{byte}$, $0 < \mathrm{fileSize} < 10^5$, $0 < \mathrm{folderSize} < 10^8$, and a folder’s size is the sum of the sizes of all files it contains).
- $\text{fileState/folderState}$: the current state, which has two possible values:
- $\text{normal}$: when a file/folder is in the normal state, users are allowed to operate on it.
- $\text{uploading}$: in this state, users may only browse it. If one or more files in a folder are in the $\text{uploading}$ state, then the folder is also in the $\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), $\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 $\text{maxServerFlux} < 10^7$.
3. The maximum download/upload throughput allowed per user $\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 $\text{userFlux}$, in units of $\text{byte/second}$. Note that if, at some moment, the remaining size to upload/download ($> 0$) is less than $\text{userFlux}$, the upload/download still takes one full second.
How is $\text{userFlux}$ determined?
$$\mathrm{userFlux} = \min(\mathrm{presentMaxUserFlux}, \mathrm{maxUserFlux})$$
Here, $\text{presentMaxUserFlux}$ is the server’s current per-user maximum throughput:
$$\mathrm{presentMaxUserFlux} = \lfloor \mathrm{maxServerFlux} / \mathrm{userTotal} \rfloor$$
($\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:
### $\verb!connect!$ command
- Format: $\verb![name] + 空格 + connect + 空格 + 参数A!$。
- Example: $\verb!tsinghua connect 1!$。
- A user named $\verb!name!$ requests to connect to the server with identity $\verb!A!$. If the current number of users has not reached $\text{maxUserNumber}$ and the user is not already connected, the connection succeeds and the server returns $\verb!success!$. Otherwise, it returns $\verb!unsuccess!$. Once connected successfully, the user’s position $\text{userPosition}$ is set to the server’s root directory. $A = 1$ denotes an upload user, $A = 2$ denotes a download user, and $A = 3$ denotes an anonymous user.
### $\verb!quit!$ command
- Format: $\verb![name] + 空格 + quit!$。
- Example: $\verb!tsinghua quit!$。
- The user named $\verb!name!$ disconnects from the server. If the user is not connected, return $\verb!unsuccess!$; otherwise, return $\verb!success!$. (Note that the user may disconnect in any state.)
### $\verb!cd!$ command
- Format: $\verb![name] + 空格 + cd + 空格 + [folderName/文件夹名称]!$。
- Example: $\verb!THU cd FD!$。
- The user named $\verb!name!$ attempts to enter a folder named $\text{folderName}$ within the current folder. If a folder named $\text{folderName}$ exists and is in the $\text{normal}$ state, change the user’s current position $\text{userPosition}$ and return $\verb!success!$. If the folder does not exist or the user is not successfully connected, return $\verb!unsuccess!$.
### $\verb!cd..!$ command
- Format: $\verb![name] + 空格 + cd..!$。
- Example: $\verb!9# cd..!$。
- The user named $\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 $\verb!unsuccess!$; otherwise, it returns $\verb!success!$ and updates $\text{userPosition}$.
### $\verb!download!$ command
- Format: $\verb![name] + 空格 + download + 空格 + [name1]!$。
- Example: $\verb!A download 1.txt!$。
- The user named $\verb!name!$ attempts to download a file or folder named $\verb!name1!$ in the current folder. If the user is not connected, the user lacks download permission, the file/folder named $\verb!name1!$ does not exist, or the file/folder is in the $\text{uploading}$ state, return $\verb!unsuccess!$; otherwise, return $\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.)
### $\verb!upload!$ command
- Format: $\verb![name] + 空格 + upload + 空格 + [name1] + 空格 + [size]!$。
- Example: $\verb!A upload B 1!$。
- The user named $\verb!name!$ attempts to upload, into the current folder, a file or folder named $\verb!name1!$ with size $\text{size}$. Note:
- Uploading a folder via the $\verb!upload!$ command can only create an empty folder. When $\text{size} = 0$, it indicates uploading a folder; when $\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 $\verb!unsuccess!$; otherwise, return $\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 $\verb!upload!$ and $\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 $3$ positive integers, representing $\text{maxUserNumber}, \text{maxServerFlux}, \text{maxUserFlux}$. The following lines describe the storage of the existing file resources on the $\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 $\verb!name + 空格 + size!$. If $\text{size} = 0$, it indicates a folder; otherwise, it indicates a file of 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 $\verb!time + 空格 + order!$. For example, $\verb!4 ares connect 1!$ means: at $4$ seconds after the server starts, a user named $\verb!ares!$ requests to connect to the server as an $\text{uploadUser}$.
The last line of input is the string $\verb!down!$.
All command times $\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 $\verb!success!$ or $\verb!unsuccess!$, indicating whether each operation succeeds.
Explanation/Hint
Source: HNOI2004 (modified).
Translated by ChatGPT 5