| 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 probability | |
| 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) | |
| return f"Q {x} {y}", current_length, query_count + 1 | |
| elif op_type == 'R': | |
| x = random.randint(1, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| return f"R {x} {d}", current_length, query_count | |
| else: # op_type == 'I' | |
| x = random.randint(0, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| return f"I {x} {d}", current_length + 1, query_count | |
| def construct_inputs(): | |
| inputs = [] | |
| # 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): | |
| op, current_length, query_count = generate_operation(current_length, query_count, max_queries) | |
| operations.append(op) | |
| if current_length > 100: # Prevent string from getting too long | |
| break | |
| test_case = initial_string + '\n' + str(len(operations)) + '\n' + '\n'.join(operations) | |
| inputs.append(test_case) | |
| # Medium test cases | |
| for _ in range(10): | |
| initial_length = random.randint(20, 100) | |
| initial_string = generate_random_string(initial_length) | |
| m = random.randint(50, 500) | |
| max_queries = min(m // 3, 100) | |
| operations = [] | |
| current_length = initial_length | |
| query_count = 0 | |
| for _ in range(m): | |
| op, current_length, query_count = generate_operation(current_length, query_count, max_queries) | |
| operations.append(op) | |
| if current_length > 1000: # Prevent string from getting too long | |
| break | |
| test_case = initial_string + '\n' + str(len(operations)) + '\n' + '\n'.join(operations) | |
| inputs.append(test_case) | |
| # Large test cases | |
| for _ in range(10): | |
| initial_length = random.randint(100, 1000) | |
| initial_string = generate_random_string(initial_length) | |
| m = random.randint(1000, 10000) | |
| max_queries = min(m // 10, 1000) | |
| operations = [] | |
| current_length = initial_length | |
| query_count = 0 | |
| for _ in range(m): | |
| op, current_length, query_count = generate_operation(current_length, query_count, max_queries) | |
| operations.append(op) | |
| if current_length > 10000: # Prevent string from getting too long | |
| break | |
| test_case = initial_string + '\n' + str(len(operations)) + '\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 patterns | |
| inputs.append("abcabc\n5\nQ 1 4\nQ 2 5\nI 3 d\nQ 1 5\nR 2 x") | |
| # Maximum operations with small string | |
| operations = [] | |
| current_length = 5 | |
| query_count = 0 | |
| for _ in range(100): | |
| op, current_length, query_count = generate_operation(current_length, query_count, 50) | |
| operations.append(op) | |
| inputs.append("hello\n" + str(len(operations)) + '\n' + '\n'.join(operations)) | |
| return inputs | |
Xet Storage Details
- Size:
- 3.94 kB
- Xet hash:
- 20eeff5547ef42e4794540e89111ffbcfee2191794a938523ccb4c2cf8b87b05
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.