| 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 // 2 + 1, 10) | |
| 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(10): | |
| initial_length = random.randint(50, 500) | |
| initial_string = generate_random_string(initial_length) | |
| m = random.randint(100, 1000) | |
| max_queries = min(m // 3 + 1, 100) | |
| 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 + 1, 1000) | |
| 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) | |
| # String with repeated characters | |
| test_case = "aaaa\n5\nQ 1 2\nQ 2 3\nI 2 b\nQ 1 3\nQ 3 5" | |
| inputs_list.append(test_case) | |
| # Maximum operations with minimal queries | |
| operations = [] | |
| current_length = 100 | |
| for i in range(149990): | |
| if i % 15000 == 0 and len([op for op in operations if op.startswith('Q')]) < 10000: | |
| x = random.randint(1, current_length) | |
| y = random.randint(1, current_length) | |
| operations.append(f"Q {x} {y}") | |
| elif i % 2 == 0: | |
| x = random.randint(1, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"R {x} {d}") | |
| else: | |
| if current_length < 99999: | |
| x = random.randint(0, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"I {x} {d}") | |
| current_length += 1 | |
| else: | |
| x = random.randint(1, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"R {x} {d}") | |
| initial_string = generate_random_string(100) | |
| 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.85 kB
- Xet hash:
- a709faa9ccdb8b3bfa2b0b258be83d9e639c357444e6529cb6dc614fda8d4d94
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.