| 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 = ['Q', 'R', 'I'] | |
| # Bias towards queries if we haven't used many yet | |
| if max_queries_left > 0 and random.random() < 0.4: | |
| op = 'Q' | |
| else: | |
| op = random.choice(operations) | |
| if op == 'Q': | |
| x = random.randint(1, current_length) | |
| y = random.randint(1, current_length) | |
| return f"Q {x} {y}", current_length, 1 | |
| elif op == 'R': | |
| x = random.randint(1, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| return f"R {x} {d}", current_length, 0 | |
| else: # op == 'I' | |
| x = random.randint(0, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| return f"I {x} {d}", current_length + 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: | |
| # Only allow queries and replacements if string is too long | |
| 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, current_length, query_count = generate_operation(current_length, max_queries - queries_used) | |
| operations.append(op) | |
| queries_used += query_count | |
| test_case = initial_string + '\n' + str(m) + '\n' + '\n'.join(operations) | |
| inputs.append(test_case) | |
| # Medium test cases | |
| for _ in range(8): | |
| initial_length = random.randint(50, 500) | |
| initial_string = generate_random_string(initial_length) | |
| m = random.randint(100, 1000) | |
| operations = [] | |
| current_length = initial_length | |
| queries_used = 0 | |
| max_queries = min(100, m // 3) | |
| 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, current_length, query_count = generate_operation(current_length, max_queries - queries_used) | |
| operations.append(op) | |
| queries_used += query_count | |
| test_case = initial_string + '\n' + str(m) + '\n' + '\n'.join(operations) | |
| inputs.append(test_case) | |
| # Large test cases | |
| for _ in range(7): | |
| 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) | |
| for _ in range(m): | |
| if current_length >= 100000: | |
| if queries_used < max_queries and random.random() < 0.9: | |
| 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, current_length, query_count = generate_operation(current_length, max_queries - queries_used) | |
| operations.append(op) | |
| queries_used += query_count | |
| test_case = initial_string + '\n' + str(m) + '\n' + '\n'.join(operations) | |
| inputs.append(test_case) | |
| return inputs | |
Xet Storage Details
- Size:
- 4.74 kB
- Xet hash:
- 18fd767a8fabd437723068916672e827adce9b39bca8271cf0e1837c6d00da39
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.