| import random | |
| import string | |
| def generate_random_string(length): | |
| return ''.join(random.choice(string.ascii_lowercase) for _ in range(length)) | |
| def generate_operations(num_ops, initial_length): | |
| operations = [] | |
| current_length = initial_length | |
| for _ in range(num_ops): | |
| op_type = random.choices(['Q', 'R', 'I'], weights=[0.4, 0.3, 0.3])[0] | |
| if op_type == 'Q': | |
| if current_length >= 2: | |
| x = random.randint(1, current_length) | |
| y = random.randint(1, current_length) | |
| operations.append(f"Q {x} {y}") | |
| else: | |
| operations.append(f"Q 1 1") | |
| elif op_type == 'R': | |
| if current_length >= 1: | |
| x = random.randint(1, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"R {x} {d}") | |
| elif op_type == 'I': | |
| x = random.randint(0, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"I {x} {d}") | |
| current_length += 1 | |
| return operations | |
| def construct_inputs(): | |
| inputs = [] | |
| # Small test cases | |
| for _ in range(10): | |
| initial_string = generate_random_string(random.randint(1, 20)) | |
| num_ops = random.randint(1, 50) | |
| operations = generate_operations(num_ops, len(initial_string)) | |
| test_case = initial_string + '\n' + str(num_ops) + '\n' + '\n'.join(operations) | |
| inputs.append(test_case) | |
| # Medium test cases | |
| for _ in range(10): | |
| initial_string = generate_random_string(random.randint(50, 500)) | |
| num_ops = random.randint(100, 1000) | |
| operations = generate_operations(num_ops, len(initial_string)) | |
| test_case = initial_string + '\n' + str(num_ops) + '\n' + '\n'.join(operations) | |
| inputs.append(test_case) | |
| # Large test cases | |
| for _ in range(10): | |
| initial_string = generate_random_string(random.randint(1000, 10000)) | |
| num_ops = random.randint(5000, 50000) | |
| operations = generate_operations(num_ops, len(initial_string)) | |
| test_case = initial_string + '\n' + str(num_ops) + '\n' + '\n'.join(operations) | |
| inputs.append(test_case) | |
| # Edge cases | |
| # Single character string | |
| operations = generate_operations(10, 1) | |
| test_case = 'a\n10\n' + '\n'.join(operations) | |
| inputs.append(test_case) | |
| # Maximum length string with maximum operations | |
| initial_string = generate_random_string(10000) | |
| operations = generate_operations(10000, len(initial_string)) | |
| test_case = initial_string + '\n10000\n' + '\n'.join(operations) | |
| inputs.append(test_case) | |
| # Query-heavy test case | |
| initial_string = generate_random_string(1000) | |
| operations = [] | |
| for _ in range(1000): | |
| x = random.randint(1, len(initial_string)) | |
| y = random.randint(1, len(initial_string)) | |
| operations.append(f"Q {x} {y}") | |
| test_case = initial_string + '\n1000\n' + '\n'.join(operations) | |
| inputs.append(test_case) | |
| return inputs | |
Xet Storage Details
- Size:
- 3.12 kB
- Xet hash:
- a851a9e75d0bd1a96588d2623d51a8c69a4c65f4a2e666976519a804459f6f38
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.