| import random | |
| import string | |
| def generate_string(length): | |
| """Generate a random string of lowercase letters""" | |
| return ''.join(random.choice(string.ascii_lowercase) for _ in range(length)) | |
| def generate_repetitive_string(length, pattern_size=3): | |
| """Generate a string with repetitive patterns""" | |
| pattern = ''.join(random.choice(string.ascii_lowercase) for _ in range(pattern_size)) | |
| return (pattern * (length // pattern_size + 1))[:length] | |
| def generate_palindromic_string(length): | |
| """Generate a palindromic string""" | |
| half = length // 2 | |
| left_half = ''.join(random.choice(string.ascii_lowercase) for _ in range(half)) | |
| if length % 2 == 0: | |
| return left_half + left_half[::-1] | |
| else: | |
| middle = random.choice(string.ascii_lowercase) | |
| return left_half + middle + left_half[::-1] | |
| def generate_operations(string_length, num_ops): | |
| """Generate a mix of operations""" | |
| operations = [] | |
| current_length = string_length | |
| for _ in range(num_ops): | |
| op_type = random.choices(['Q', 'R', 'I'], weights=[0.4, 0.3, 0.3])[0] | |
| if op_type == 'Q': | |
| x = random.randint(1, current_length) | |
| y = random.randint(1, current_length) | |
| operations.append(f"Q {x} {y}") | |
| elif 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 | |
| if current_length > 100000: # Prevent exceeding limit | |
| current_length -= 1 | |
| continue | |
| return operations | |
| def generate_adversarial_queries(string_length, num_queries): | |
| """Generate adversarial query patterns""" | |
| operations = [] | |
| # Edge case queries | |
| operations.append(f"Q 1 1") # Same position | |
| operations.append(f"Q 1 {string_length}") # Start and end | |
| operations.append(f"Q {string_length} {string_length}") # Last position | |
| # Adjacent positions | |
| for i in range(min(5, string_length - 1)): | |
| pos = random.randint(1, string_length - 1) | |
| operations.append(f"Q {pos} {pos + 1}") | |
| # Random queries for remaining | |
| for _ in range(num_queries - len(operations)): | |
| x = random.randint(1, string_length) | |
| y = random.randint(1, string_length) | |
| operations.append(f"Q {x} {y}") | |
| return operations | |
| def generate_heavy_modification_sequence(string_length): | |
| """Generate sequences with heavy modifications""" | |
| operations = [] | |
| current_length = string_length | |
| # Multiple insertions at beginning | |
| for i in range(min(10, 100000 - current_length)): | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"I 0 {d}") | |
| current_length += 1 | |
| # Multiple modifications | |
| for _ in range(20): | |
| if current_length > 0: | |
| x = random.randint(1, current_length) | |
| d = random.choice(string.ascii_lowercase) | |
| operations.append(f"R {x} {d}") | |
| # Queries after modifications | |
| for _ in range(10): | |
| if current_length > 0: | |
| x = random.randint(1, current_length) | |
| y = random.randint(1, current_length) | |
| operations.append(f"Q {x} {y}") | |
| return operations | |
| def construct_inputs(): | |
| inputs = [] | |
| # Test case 1: Small string with basic operations | |
| s1 = "abcabc" | |
| ops1 = ["Q 1 4", "R 2 x", "Q 1 4", "I 3 y", "Q 1 5"] | |
| inputs.append(f"{s1}\n{len(ops1)}\n" + "\n".join(ops1)) | |
| # Test case 2: Repetitive pattern string | |
| s2 = generate_repetitive_string(50, 3) | |
| ops2 = generate_adversarial_queries(len(s2), 15) | |
| inputs.append(f"{s2}\n{len(ops2)}\n" + "\n".join(ops2)) | |
| # Test case 3: Palindromic string | |
| s3 = generate_palindromic_string(100) | |
| ops3 = generate_operations(len(s3), 50) | |
| inputs.append(f"{s3}\n{len(ops3)}\n" + "\n".join(ops3)) | |
| # Test case 4: Single character repeated | |
| s4 = "a" * 1000 | |
| ops4 = generate_adversarial_queries(len(s4), 20) + generate_operations(len(s4), 30) | |
| random.shuffle(ops4) | |
| inputs.append(f"{s4}\n{len(ops4)}\n" + "\n".join(ops4)) | |
| # Test case 5: Maximum length with heavy modifications | |
| s5 = generate_string(10000) | |
| ops5 = generate_heavy_modification_sequence(len(s5)) | |
| inputs.append(f"{s5}\n{len(ops5)}\n" + "\n".join(ops5)) | |
| # Test case 6: Alternating pattern | |
| s6 = "ab" * 5000 | |
| ops6 = generate_operations(len(s6), 100) | |
| inputs.append(f"{s6}\n{len(ops6)}\n" + "\n".join(ops6)) | |
| # Test case 7: Edge case - single character | |
| s7 = "x" | |
| ops7 = ["Q 1 1", "I 0 y", "Q 1 2", "R 1 z", "Q 1 2"] | |
| inputs.append(f"{s7}\n{len(ops7)}\n" + "\n".join(ops7)) | |
| # Test case 8: Large string with many queries | |
| s8 = generate_string(50000) | |
| ops8 = [] | |
| for _ in range(5000): | |
| x = random.randint(1, len(s8)) | |
| y = random.randint(1, len(s8)) | |
| ops8.append(f"Q {x} {y}") | |
| # Add some modifications | |
| for _ in range(1000): | |
| if random.random() < 0.5: | |
| x = random.randint(1, len(s8)) | |
| d = random.choice(string.ascii_lowercase) | |
| ops8.append(f"R {x} {d}") | |
| else: | |
| x = random.randint(0, min(len(s8), 99999)) | |
| d = random.choice(string.ascii_lowercase) | |
| ops8.append(f"I {x} {d}") | |
| random.shuffle(ops8) | |
| inputs.append(f"{s8}\n{len(ops8)}\n" + "\n".join(ops8)) | |
| return inputs | |
Xet Storage Details
- Size:
- 5.63 kB
- Xet hash:
- 07c7b7b77dc2dc862eec1c3df27a304591daeefffae9c10971e1c2a9f0abd4d1
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.