| import random | |
| import string | |
| def generate_random_string(length): | |
| return ''.join(random.choice(string.ascii_lowercase) for _ in range(length)) | |
| def generate_operation(current_length, query_count, max_queries): | |
| operations = [] | |
| # Choose operation type with weighted probabilities | |
| if query_count >= max_queries: | |
| # No more queries allowed | |
| op_type = random.choices(['R', 'I'], weights=[0.6, 0.4])[0] | |
| else: | |
| op_type = random.choices(['Q', 'R', 'I'], weights=[0.5, 0.3, 0.2])[0] | |
| if op_type == 'Q': | |
| x = random.randint(1, current_length) | |
| y = random.randint(1, current_length) | |
| operations.append(f"Q {x} {y}") | |
| return operations, current_length, query_count + 1 | |
| elif op_type == 'R': | |
| x = random.randint(1, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"R {x} {d}") | |
| return operations, current_length, query_count | |
| else: # op_type == 'I' | |
| x = random.randint(0, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"I {x} {d}") | |
| return operations, current_length + 1, query_count | |
| def construct_inputs(): | |
| inputs_list = [] | |
| # Small test cases | |
| for _ in range(10): | |
| initial_length = random.randint(1, 20) | |
| initial_string = generate_random_string(initial_length) | |
| m = random.randint(1, 30) | |
| max_queries = min(m, 20) | |
| operations = [] | |
| current_length = initial_length | |
| query_count = 0 | |
| for _ in range(m): | |
| if current_length >= 100000: # Prevent string from getting too long | |
| break | |
| ops, current_length, query_count = generate_operation(current_length, query_count, max_queries) | |
| operations.extend(ops) | |
| test_case = f"{initial_string}\n{len(operations)}\n" + "\n".join(operations) | |
| inputs_list.append(test_case) | |
| # Medium test cases | |
| for _ in range(15): | |
| initial_length = random.randint(50, 500) | |
| initial_string = generate_random_string(initial_length) | |
| m = random.randint(100, 1000) | |
| max_queries = min(m // 3, 500) | |
| operations = [] | |
| current_length = initial_length | |
| query_count = 0 | |
| for _ in range(m): | |
| if current_length >= 100000: | |
| break | |
| ops, current_length, query_count = generate_operation(current_length, query_count, max_queries) | |
| operations.extend(ops) | |
| test_case = f"{initial_string}\n{len(operations)}\n" + "\n".join(operations) | |
| inputs_list.append(test_case) | |
| # Large test cases | |
| for _ in range(10): | |
| initial_length = random.randint(1000, 10000) | |
| initial_string = generate_random_string(initial_length) | |
| m = random.randint(10000, 50000) | |
| max_queries = min(m // 5, 2000) | |
| operations = [] | |
| current_length = initial_length | |
| query_count = 0 | |
| for _ in range(m): | |
| if current_length >= 100000: | |
| break | |
| ops, current_length, query_count = generate_operation(current_length, query_count, max_queries) | |
| operations.extend(ops) | |
| test_case = f"{initial_string}\n{len(operations)}\n" + "\n".join(operations) | |
| inputs_list.append(test_case) | |
| # Edge cases | |
| # Single character string | |
| test_case = "a\n3\nQ 1 1\nR 1 b\nQ 1 1" | |
| inputs_list.append(test_case) | |
| # Only queries | |
| initial_string = generate_random_string(100) | |
| operations = [] | |
| for _ in range(50): | |
| x = random.randint(1, 100) | |
| y = random.randint(1, 100) | |
| operations.append(f"Q {x} {y}") | |
| test_case = f"{initial_string}\n{len(operations)}\n" + "\n".join(operations) | |
| inputs_list.append(test_case) | |
| # Only modifications | |
| initial_string = generate_random_string(50) | |
| operations = [] | |
| for _ in range(30): | |
| x = random.randint(1, 50) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"R {x} {d}") | |
| test_case = f"{initial_string}\n{len(operations)}\n" + "\n".join(operations) | |
| inputs_list.append(test_case) | |
| return inputs_list | |
Xet Storage Details
- Size:
- 4.27 kB
- Xet hash:
- 9a09d21c4f90dc2f552284cf267ab152ae3f92d7771d96e87e3c1d0484218fe0
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.