Tsukihjy's picture
download
raw
5.4 kB
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(m // 2 + 1, 20)
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, new_length, query_count = generate_operation(current_length, max_queries - queries_used)
operations.append(op)
current_length = new_length
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(15):
initial_length = random.randint(20, 1000)
initial_string = generate_random_string(initial_length)
m = random.randint(50, 5000)
operations = []
current_length = initial_length
queries_used = 0
max_queries = min(m // 3 + 1, 1000)
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, new_length, query_count = generate_operation(current_length, max_queries - queries_used)
operations.append(op)
current_length = new_length
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(10):
initial_length = random.randint(1000, 50000)
initial_string = generate_random_string(initial_length)
m = random.randint(10000, 150000)
operations = []
current_length = initial_length
queries_used = 0
max_queries = min(m // 5 + 1, 10000)
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, new_length, query_count = generate_operation(current_length, max_queries - queries_used)
operations.append(op)
current_length = new_length
queries_used += query_count
test_case = initial_string + '\n' + str(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")
# String with repeated patterns
inputs.append("abcabcabc\n5\nQ 1 4\nQ 2 5\nI 3 x\nQ 1 5\nR 4 y")
# Maximum operations with minimal queries
operations = []
for i in range(149995):
operations.append(f"R 1 {random.choice(string.ascii_lowercase)}")
for i in range(5):
operations.append("Q 1 1")
edge_case = "x\n150000\n" + '\n'.join(operations)
inputs.append(edge_case)
return inputs

Xet Storage Details

Size:
5.4 kB
·
Xet hash:
f832770e71d17ca03d6807fb78a875bdad0343fdca13ee6ce15d9655aa3ff948

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.