| 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': | |
| x = random.randint(1, current_length) | |
| y = random.randint(1, current_length) | |
| operations.append(f"Q {x} {y}") | |
| elif op_type == 'R': | |
| x = random.randint(1, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"R {x} {d}") | |
| else: # op_type == 'I' | |
| x = random.randint(0, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"I {x} {d}") | |
| current_length += 1 | |
| if current_length > 100000: | |
| current_length = 100000 | |
| return operations | |
| def construct_inputs(): | |
| inputs = [] | |
| # Small test cases | |
| for _ in range(10): | |
| initial_length = random.randint(1, 20) | |
| initial_string = generate_random_string(initial_length) | |
| num_ops = random.randint(1, 50) | |
| operations = generate_operations(num_ops, initial_length) | |
| test_case = initial_string + '\n' + str(num_ops) + '\n' + '\n'.join(operations) | |
| inputs.append(test_case) | |
| # Medium test cases | |
| for _ in range(15): | |
| initial_length = random.randint(50, 1000) | |
| initial_string = generate_random_string(initial_length) | |
| num_ops = random.randint(100, 5000) | |
| operations = generate_operations(num_ops, initial_length) | |
| test_case = initial_string + '\n' + str(num_ops) + '\n' + '\n'.join(operations) | |
| inputs.append(test_case) | |
| # Large test cases | |
| for _ in range(10): | |
| initial_length = random.randint(5000, 50000) | |
| initial_string = generate_random_string(initial_length) | |
| num_ops = random.randint(10000, 100000) | |
| operations = generate_operations(num_ops, initial_length) | |
| test_case = initial_string + '\n' + str(num_ops) + '\n' + '\n'.join(operations) | |
| inputs.append(test_case) | |
| # Edge cases | |
| # Single character string | |
| inputs.append("a\n3\nQ 1 1\nR 1 b\nQ 1 1") | |
| # String with repeated characters | |
| inputs.append("aaaaaaa\n5\nQ 1 3\nQ 2 5\nI 3 b\nQ 1 4\nR 2 c") | |
| # Maximum operations with queries | |
| initial_string = generate_random_string(1000) | |
| query_ops = ["Q {} {}".format(random.randint(1, 1000), random.randint(1, 1000)) for _ in range(10000)] | |
| test_case = initial_string + '\n' + str(10000) + '\n' + '\n'.join(query_ops) | |
| inputs.append(test_case) | |
| return inputs | |
Xet Storage Details
- Size:
- 2.84 kB
- Xet hash:
- b50ece15fd7a66ade74040e857fdb65825a70e3b49223b811a8aac561cb19b19
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.