Tsukihjy's picture
download
raw
4.58 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, query_count, max_queries):
operations = []
# Choose operation type with weighted probabilities
if query_count >= max_queries:
# No more queries allowed
op_type = random.choices(['R', 'I'], weights=[0.6, 0.4])[0]
else:
op_type = random.choices(['Q', 'R', 'I'], weights=[0.5, 0.3, 0.2])[0]
if op_type == 'Q':
x = random.randint(1, current_length)
y = random.randint(1, current_length)
operations.append(f"Q {x} {y}")
return operations, current_length, query_count + 1
elif op_type == 'R':
x = random.randint(1, current_length)
d = random.choice(string.ascii_lowercase)
operations.append(f"R {x} {d}")
return operations, current_length, query_count
else: # op_type == 'I'
x = random.randint(0, current_length)
d = random.choice(string.ascii_lowercase)
operations.append(f"I {x} {d}")
return operations, current_length + 1, query_count
def construct_inputs():
inputs_list = []
# 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)
max_queries = min(m // 2 + 1, 10)
operations = []
current_length = initial_length
query_count = 0
for _ in range(m):
if current_length >= 100000: # Prevent string from getting too long
break
ops, current_length, query_count = generate_operation(current_length, query_count, max_queries)
operations.extend(ops)
test_case = f"{initial_string}\n{len(operations)}\n" + "\n".join(operations)
inputs_list.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)
max_queries = min(m // 3 + 1, 100)
operations = []
current_length = initial_length
query_count = 0
for _ in range(m):
if current_length >= 100000:
break
ops, current_length, query_count = generate_operation(current_length, query_count, max_queries)
operations.extend(ops)
test_case = f"{initial_string}\n{len(operations)}\n" + "\n".join(operations)
inputs_list.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, 50000)
max_queries = min(m // 5 + 1, 1000)
operations = []
current_length = initial_length
query_count = 0
for _ in range(m):
if current_length >= 100000:
break
ops, current_length, query_count = generate_operation(current_length, query_count, max_queries)
operations.extend(ops)
test_case = f"{initial_string}\n{len(operations)}\n" + "\n".join(operations)
inputs_list.append(test_case)
# Edge cases
# Single character string
test_case = "a\n3\nQ 1 1\nR 1 b\nQ 1 1"
inputs_list.append(test_case)
# Only queries
initial_string = generate_random_string(100)
operations = []
for _ in range(50):
x = random.randint(1, 100)
y = random.randint(1, 100)
operations.append(f"Q {x} {y}")
test_case = f"{initial_string}\n{len(operations)}\n" + "\n".join(operations)
inputs_list.append(test_case)
# Many insertions
initial_string = "abc"
operations = []
current_length = 3
for i in range(100):
if current_length >= 1000:
break
x = random.randint(0, current_length)
d = random.choice(string.ascii_lowercase)
operations.append(f"I {x} {d}")
current_length += 1
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}")
test_case = f"{initial_string}\n{len(operations)}\n" + "\n".join(operations)
inputs_list.append(test_case)
return inputs_list

Xet Storage Details

Size:
4.58 kB
·
Xet hash:
ad5f51faab35ddc2c257675319011ce0c89d2c148480d5e171fd445c384dbc03

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