Tsukihjy's picture
download
raw
4.31 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, 20)
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, 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 // 10, 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)
# String with repeated characters
test_case = "aaaa\n5\nQ 1 2\nQ 2 3\nI 2 b\nQ 1 3\nQ 3 5"
inputs_list.append(test_case)
# Maximum constraint test
initial_string = generate_random_string(50000)
operations = []
current_length = 50000
query_count = 0
max_queries = 2000
for _ in range(30000):
if current_length >= 100000:
break
ops, current_length, query_count = generate_operation(current_length, query_count, max_queries)
operations.extend(ops)
if query_count >= max_queries and len(operations) > 20000:
break
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.31 kB
·
Xet hash:
0fe207b6f30f1619985af1eb9a268c88dba673ecd4a838d41edbce088f388cf5

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