| import random | |
| import string | |
| def generate_string(length, pattern_type="random"): | |
| if pattern_type == "random": | |
| return ''.join(random.choice(string.ascii_lowercase) for _ in range(length)) | |
| elif pattern_type == "repetitive": | |
| base = random.choice(string.ascii_lowercase) | |
| return base * length | |
| elif pattern_type == "alternating": | |
| chars = random.sample(string.ascii_lowercase, 2) | |
| return ''.join(chars[i % 2] for i in range(length)) | |
| elif pattern_type == "palindrome": | |
| half = ''.join(random.choice(string.ascii_lowercase) for _ in range(length // 2)) | |
| if length % 2 == 0: | |
| return half + half[::-1] | |
| else: | |
| return half + random.choice(string.ascii_lowercase) + half[::-1] | |
| elif pattern_type == "periodic": | |
| period = random.randint(2, min(10, length)) | |
| pattern = ''.join(random.choice(string.ascii_lowercase) for _ in range(period)) | |
| return (pattern * (length // period + 1))[:length] | |
| def generate_operations(initial_length, max_ops, query_heavy=False): | |
| operations = [] | |
| current_length = initial_length | |
| if query_heavy: | |
| # Generate mostly queries with few modifications | |
| num_queries = int(max_ops * 0.8) | |
| num_modifications = max_ops - num_queries | |
| else: | |
| # Balanced operations | |
| num_queries = max_ops // 3 | |
| num_modifications = max_ops - num_queries | |
| # Add queries | |
| for _ in range(num_queries): | |
| x = random.randint(1, current_length) | |
| y = random.randint(1, current_length) | |
| operations.append(f"Q {x} {y}") | |
| # Add modifications and insertions | |
| for _ in range(num_modifications): | |
| op_type = random.choice(['R', 'I']) | |
| if op_type == 'R': | |
| x = random.randint(1, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"R {x} {d}") | |
| else: # Insert | |
| x = random.randint(0, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"I {x} {d}") | |
| current_length += 1 | |
| random.shuffle(operations) | |
| return operations | |
| def generate_adversarial_case_1(): | |
| # Long repetitive string with many queries | |
| initial_string = generate_string(50000, "repetitive") | |
| operations = generate_operations(50000, 10000, query_heavy=True) | |
| result = initial_string + "\n" + str(len(operations)) + "\n" | |
| result += "\n".join(operations) | |
| return result | |
| def generate_adversarial_case_2(): | |
| # Palindromic string with strategic modifications | |
| initial_string = generate_string(30000, "palindrome") | |
| operations = [] | |
| # Add queries that test palindrome properties | |
| for _ in range(3000): | |
| pos = random.randint(1, len(initial_string) // 2) | |
| mirror_pos = len(initial_string) - pos + 1 | |
| operations.append(f"Q {pos} {mirror_pos}") | |
| # Add modifications that break palindrome | |
| for _ in range(2000): | |
| pos = random.randint(1, len(initial_string)) | |
| char = random.choice(string.ascii_lowercase) | |
| operations.append(f"R {pos} {char}") | |
| random.shuffle(operations) | |
| result = initial_string + "\n" + str(len(operations)) + "\n" | |
| result += "\n".join(operations) | |
| return result | |
| def generate_adversarial_case_3(): | |
| # Periodic pattern with insertions that disrupt period | |
| initial_string = generate_string(40000, "periodic") | |
| operations = [] | |
| current_length = len(initial_string) | |
| # Queries testing periodic structure | |
| for _ in range(2000): | |
| x = random.randint(1, current_length) | |
| y = random.randint(1, current_length) | |
| operations.append(f"Q {x} {y}") | |
| # Strategic insertions to break periodicity | |
| for _ in range(3000): | |
| pos = random.randint(0, current_length) | |
| char = random.choice(string.ascii_lowercase) | |
| operations.append(f"I {pos} {char}") | |
| current_length += 1 | |
| # Add query after insertion | |
| if current_length > 1: | |
| x = random.randint(1, current_length) | |
| y = random.randint(1, current_length) | |
| operations.append(f"Q {x} {y}") | |
| result = initial_string + "\n" + str(len(operations)) + "\n" | |
| result += "\n".join(operations) | |
| return result | |
| def generate_adversarial_case_4(): | |
| # Maximum constraints case | |
| initial_string = generate_string(100000, "random") | |
| operations = generate_operations(100000, 150000) | |
| result = initial_string + "\n" + str(len(operations)) + "\n" | |
| result += "\n".join(operations) | |
| return result | |
| def generate_adversarial_case_5(): | |
| # Edge case: single character with maximum operations | |
| initial_string = "a" | |
| operations = [] | |
| current_length = 1 | |
| # Build up string through insertions | |
| for i in range(50000): | |
| pos = random.randint(0, current_length) | |
| char = random.choice(string.ascii_lowercase) | |
| operations.append(f"I {pos} {char}") | |
| current_length += 1 | |
| # Add query every few insertions | |
| if i % 10 == 0 and current_length > 1: | |
| x = random.randint(1, current_length) | |
| y = random.randint(1, current_length) | |
| operations.append(f"Q {x} {y}") | |
| # Add remaining queries | |
| for _ in range(min(10000, 150000 - len(operations))): | |
| if current_length > 1: | |
| x = random.randint(1, current_length) | |
| y = random.randint(1, current_length) | |
| operations.append(f"Q {x} {y}") | |
| result = initial_string + "\n" + str(len(operations)) + "\n" | |
| result += "\n".join(operations) | |
| return result | |
| def construct_inputs(): | |
| return [ | |
| generate_adversarial_case_1(), | |
| generate_adversarial_case_2(), | |
| generate_adversarial_case_3(), | |
| generate_adversarial_case_4(), | |
| generate_adversarial_case_5() | |
| ] | |
Xet Storage Details
- Size:
- 5.89 kB
- Xet hash:
- 38e0db4c4fe878895adbb24c9abe818d48d68bcf1e2b793d0d53353841dd2054
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.