You are implementing a management layer for a distributed cloud storage service. Users can upload files, remove files, and run two kinds of analytics queries against the stored data. The system must process a list of operations sequentially and report the requested results.
Every file is identified by a unique case-sensitive name. When a file is uploaded, its recorded size is set to the given integer (a non‑negative number of bytes). Uploading a name that already exists simply updates its size to the new value with no extra side effects. Deleting a file that does not exist should be silently ignored — the operation consumes no resources and returns no error.
The service supports two query types:
total_usage — return the sum of the sizes of all files currently stored.threshold_count <K> — return how many files have a size strictly greater than K bytes.All operations are given as an array of strings. Each string is one of the following:
"upload <name> <size>""delete <name>""total_usage""threshold_count <K>"<name> is a non‑empty alphanumeric identifier (a-zA-Z0-9). <size> and <K> are integers. The command tokens are separated by a single space.
Process the operations in order and collect the integer answers for every query that appears (both total_usage and threshold_count). Return those answers as an array, preserving the original order of the queries.
Example 1 — Basic uploads and queries
operations = [
"upload report.pdf 2400",
"upload photo.jpg 5000",
"total_usage",
"threshold_count 3000",
"delete report.pdf",
"total_usage"
]
Walk‑through:
report.pdf (2400 bytes).photo.jpg (5000 bytes). Current files: report.pdf = 2400, photo.jpg = 5000.total_usage → 2400 + 5000 = 7400.threshold_count 3000 → files > 3000 are only photo.jpg → 1.report.pdf. Current files: only photo.jpg (5000).total_usage → 5000.Output: [7400, 1, 5000]
operations = ['upload report.pdf 2400', 'upload photo.jpg 5000', 'total_usage', 'threshold_count 3000', 'delete report.pdf', 'total_usage'][7400,1, 5000]
empty
We start with an empty file system. The first operation is 'upload report.pdf 2400'.
Example 2 — Overwrite, non‑existent delete, and zero‑threshold edge
operations = [
"upload a.txt 15",
"upload a.txt 25",
"total_usage",
"delete b.txt",
"threshold_count 0",
"threshold_count 20"
]
Walk‑through:
a.txt with size 15.a.txt again with size 25 (overwrite). Current files: a.txt = 25.total_usage → 25.b.txt — no such file, nothing changes.threshold_count 0 — files > 0: a.txt (25) → 1.threshold_count 20 — files > 20: a.txt (25) → 1.Output: [25, 1, 1]
Example 3 — Empty system and threshold on large sizes
operations = [
"total_usage",
"upload data.bin 1000000000",
"upload config.cfg 500000000",
"threshold_count 800000000",
"delete data.bin",
"threshold_count 800000000",
"total_usage"
]
Walk‑through:
total_usage — no files yet → 0.data.bin = 1,000,000,000 and config.cfg = 500,000,000.threshold_count 800000000 — only data.bin is > 800,000,000 → 1.data.bin. Remaining: config.cfg (500,000,000).threshold_count 800000000 — no file exceeds 800,000,000 → 0.total_usage → 500,000,000.Output: [0, 1, 0, 500000000]
n satisfies 1 <= n <= 100,000.K are integers in the range 0 <= size, K <= 1,000,000,000.operations = ['upload report.pdf 2400', 'upload photo.jpg 5000', 'total_usage', 'threshold_count 3000', 'delete report.pdf', 'total_usage'][7400,1, 5000]
empty
We start with an empty file system. The first operation is 'upload report.pdf 2400'.