Tsukihjy's picture
download
raw
2.9 kB
import random
import string
def generate_random_string(length):
return ''.join(random.choice(string.ascii_lowercase) for _ in range(length))
def generate_operations(num_ops, initial_length):
operations = []
current_length = initial_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
return operations
def construct_inputs():
inputs = []
# Small test cases
for _ in range(10):
initial_length = random.randint(1, 20)
initial_string = generate_random_string(initial_length)
num_ops = random.randint(1, 30)
operations = generate_operations(num_ops, initial_length)
test_case = initial_string + '\n' + str(num_ops) + '\n' + '\n'.join(operations)
inputs.append(test_case)
# Medium test cases
for _ in range(15):
initial_length = random.randint(50, 500)
initial_string = generate_random_string(initial_length)
num_ops = random.randint(100, 1000)
operations = generate_operations(num_ops, initial_length)
test_case = initial_string + '\n' + str(num_ops) + '\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)
num_ops = random.randint(5000, 50000)
operations = generate_operations(num_ops, initial_length)
test_case = initial_string + '\n' + str(num_ops) + '\n' + '\n'.join(operations)
inputs.append(test_case)
# Edge cases
# Single character string
test_case = "a\n3\nQ 1 1\nR 1 b\nI 0 c"
inputs.append(test_case)
# String with repeated characters
test_case = "aaaaaaa\n5\nQ 1 3\nQ 2 5\nR 3 b\nQ 1 3\nI 4 a"
inputs.append(test_case)
# Maximum operations with queries
initial_string = generate_random_string(1000)
operations = []
current_length = 1000
for _ in range(10000):
x = random.randint(1, current_length)
y = random.randint(1, current_length)
operations.append(f"Q {x} {y}")
test_case = initial_string + '\n' + str(10000) + '\n' + '\n'.join(operations)
inputs.append(test_case)
return inputs

Xet Storage Details

Size:
2.9 kB
·
Xet hash:
988005264f6ee4bbb0834393ce8ae881c89ecc172bc681cb69c8d638d4e5c1fa

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