| 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, max_queries_left): | |
| operations = [] | |
| # Decide operation type based on probabilities | |
| if max_queries_left > 0 and random.random() < 0.4: # 40% chance for query | |
| op_type = 'Q' | |
| elif random.random() < 0.5: # 30% chance for replace (50% of remaining 60%) | |
| op_type = 'R' | |
| else: # 30% chance for insert | |
| op_type = 'I' | |
| if op_type == 'Q': | |
| x = random.randint(1, current_length) | |
| y = random.randint(1, current_length) | |
| return f"Q {x} {y}", 0, -1 # returns operation, length_change, queries_used | |
| elif op_type == 'R': | |
| x = random.randint(1, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| return f"R {x} {d}", 0, 0 | |
| else: # Insert | |
| x = random.randint(0, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| return f"I {x} {d}", 1, 0 | |
| 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) | |
| operations = [] | |
| current_length = initial_length | |
| queries_used = 0 | |
| max_queries = min(10, m // 2 + 1) | |
| for _ in range(m): | |
| if current_length >= 100000: # Prevent string from getting too long | |
| # Force a query or replace operation | |
| if queries_used < max_queries and random.random() < 0.7: | |
| x = random.randint(1, current_length) | |
| y = random.randint(1, current_length) | |
| operations.append(f"Q {x} {y}") | |
| queries_used += 1 | |
| else: | |
| x = random.randint(1, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"R {x} {d}") | |
| else: | |
| op, length_change, query_change = generate_operation(current_length, max_queries - queries_used) | |
| operations.append(op) | |
| current_length += length_change | |
| if query_change == -1: | |
| queries_used += 1 | |
| test_case = f"{initial_string}\n{m}\n" + "\n".join(operations) | |
| inputs.append(test_case) | |
| # Medium test cases | |
| for _ in range(15): | |
| initial_length = random.randint(20, 1000) | |
| initial_string = generate_random_string(initial_length) | |
| m = random.randint(50, 1000) | |
| operations = [] | |
| current_length = initial_length | |
| queries_used = 0 | |
| max_queries = min(100, m // 3 + 1) | |
| for _ in range(m): | |
| if current_length >= 100000: | |
| if queries_used < max_queries and random.random() < 0.7: | |
| x = random.randint(1, current_length) | |
| y = random.randint(1, current_length) | |
| operations.append(f"Q {x} {y}") | |
| queries_used += 1 | |
| else: | |
| x = random.randint(1, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"R {x} {d}") | |
| else: | |
| op, length_change, query_change = generate_operation(current_length, max_queries - queries_used) | |
| operations.append(op) | |
| current_length += length_change | |
| if query_change == -1: | |
| queries_used += 1 | |
| test_case = f"{initial_string}\n{m}\n" + "\n".join(operations) | |
| inputs.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, 150000) | |
| operations = [] | |
| current_length = initial_length | |
| queries_used = 0 | |
| max_queries = min(10000, m // 10 + 1) | |
| for _ in range(m): | |
| if current_length >= 100000: | |
| if queries_used < max_queries and random.random() < 0.8: | |
| x = random.randint(1, current_length) | |
| y = random.randint(1, current_length) | |
| operations.append(f"Q {x} {y}") | |
| queries_used += 1 | |
| else: | |
| x = random.randint(1, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"R {x} {d}") | |
| else: | |
| op, length_change, query_change = generate_operation(current_length, max_queries - queries_used) | |
| operations.append(op) | |
| current_length += length_change | |
| if query_change == -1: | |
| queries_used += 1 | |
| test_case = f"{initial_string}\n{m}\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") | |
| # Maximum operations with minimal queries | |
| operations = [] | |
| for i in range(149990): | |
| operations.append(f"R 1 {random.choice(string.ascii_lowercase)}") | |
| for i in range(10): | |
| operations.append("Q 1 1") | |
| edge_case = f"a\n150000\n" + "\n".join(operations) | |
| inputs.append(edge_case) | |
| return inputs | |
Xet Storage Details
- Size:
- 5.54 kB
- Xet hash:
- 53918f0d3884e13176fe495b165ddf476f8b573c733b946132a36b2e3ad19ef5
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.