Tsukihjy's picture
download
raw
5.7 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, 50)
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, current_length, query_count = generate_operation(current_length, max_queries - queries_used)
operations.append(op)
queries_used += query_count
test_case = f"{initial_string}\n{m}\n" + "\n".join(operations)
inputs.append(test_case)
# Medium test cases
for _ in range(10):
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(m // 3 + 1, 100)
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, current_length, query_count = generate_operation(current_length, max_queries - queries_used)
operations.append(op)
queries_used += query_count
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(m // 15 + 1, 10000)
for _ in range(m):
if current_length >= 100000:
if queries_used < max_queries and random.random() < 0.6:
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 = 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
initial_string = generate_random_string(1000)
operations = []
current_length = 1000
queries_used = 0
for i in range(149990):
if current_length >= 100000:
x = random.randint(1, current_length)
d = random.choice(string.ascii_lowercase)
operations.append(f"R {x} {d}")
else:
x = random.randint(0, current_length)
d = random.choice(string.ascii_lowercase)
operations.append(f"I {x} {d}")
current_length += 1
# Add some queries at the end
for _ in range(10):
x = random.randint(1, current_length)
y = random.randint(1, current_length)
operations.append(f"Q {x} {y}")
test_case = f"{initial_string}\n150000\n" + "\n".join(operations)
inputs.append(test_case)
return inputs

Xet Storage Details

Size:
5.7 kB
·
Xet hash:
db97368c3e177801d4e3a3836bfa6d4f1d7cd7b4fd71ab88f63511ff28df6c8f

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