| 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 = [] | |
| if query_count < max_queries and random.random() < 0.4: # 40% chance for query | |
| op_type = 'Q' | |
| x = random.randint(1, current_length) | |
| y = random.randint(1, current_length) | |
| operations.append(f"{op_type} {x} {y}") | |
| query_count += 1 | |
| elif random.random() < 0.5: # 30% chance for modify (50% of remaining 60%) | |
| op_type = 'R' | |
| x = random.randint(1, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"{op_type} {x} {d}") | |
| else: # 30% chance for insert | |
| op_type = 'I' | |
| x = random.randint(0, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"{op_type} {x} {d}") | |
| current_length += 1 | |
| return operations[0], current_length, query_count | |
| def construct_inputs(): | |
| inputs = [] | |
| # Small test cases | |
| for _ in range(10): | |
| initial_length = random.randint(5, 20) | |
| initial_string = generate_random_string(initial_length) | |
| m = random.randint(5, 30) | |
| max_queries = min(m // 2, 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: # Keep string length reasonable | |
| break | |
| test_case = f"{initial_string}\n{len(operations)}\n" + "\n".join(operations) | |
| inputs.append(test_case) | |
| # Medium test cases | |
| for _ in range(8): | |
| initial_length = random.randint(50, 200) | |
| initial_string = generate_random_string(initial_length) | |
| m = random.randint(100, 1000) | |
| 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: # Keep string length reasonable | |
| break | |
| test_case = f"{initial_string}\n{len(operations)}\n" + "\n".join(operations) | |
| inputs.append(test_case) | |
| # Large test cases | |
| for _ in range(7): | |
| initial_length = random.randint(1000, 5000) | |
| initial_string = generate_random_string(initial_length) | |
| m = random.randint(5000, 50000) | |
| max_queries = min(m // 5, 2000) | |
| 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: # Keep string length reasonable | |
| break | |
| test_case = f"{initial_string}\n{len(operations)}\n" + "\n".join(operations) | |
| inputs.append(test_case) | |
| # Edge cases | |
| # Single character string | |
| test_case = "a\n3\nQ 1 1\nI 1 b\nQ 1 2" | |
| inputs.append(test_case) | |
| # String with repeated characters | |
| test_case = "aaaa\n5\nQ 1 2\nQ 2 3\nR 2 b\nQ 1 2\nI 0 c" | |
| inputs.append(test_case) | |
| # Maximum operations with small string | |
| operations = [] | |
| query_count = 0 | |
| current_length = 10 | |
| for i in range(1000): | |
| if query_count < 200 and random.random() < 0.2: | |
| x = random.randint(1, current_length) | |
| y = random.randint(1, current_length) | |
| operations.append(f"Q {x} {y}") | |
| query_count += 1 | |
| elif random.random() < 0.5: | |
| x = random.randint(1, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"R {x} {d}") | |
| else: | |
| x = random.randint(0, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"I {x} {d}") | |
| current_length += 1 | |
| if current_length > 100: | |
| current_length = 10 # Reset to keep manageable | |
| test_case = f"{generate_random_string(10)}\n{len(operations)}\n" + "\n".join(operations) | |
| inputs.append(test_case) | |
| return inputs | |
Xet Storage Details
- Size:
- 4.54 kB
- Xet hash:
- 31a119bae87dfd90d5993d463dcb7784a231cbd54797cd48f2b776458b812d10
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.