forked from Haozh20/dsrw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
duck.py
45 lines (35 loc) · 1.35 KB
/
duck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import random
import sys
from testcase.case2 import *
# R = 2
# I = int(1e7)
# N = int(1e7)
# M = int(2e5)
# E = 1
INT_RANGE = 2147483648
RANGE_LIMIT = INT_RANGE >> R
init_keys = random.choices(range(-INT_RANGE, INT_RANGE), k=I)
init_values = random.choices(range(-INT_RANGE, INT_RANGE), k=I)
keys = random.choices(range(-INT_RANGE, INT_RANGE), k=N)
values = random.choices(range(-INT_RANGE, INT_RANGE), k=N)
ranges_left = random.choices(range(-INT_RANGE, INT_RANGE), k=M)
ranges_right = list(map(lambda x: random.randint(
x, min(INT_RANGE - 1, x + RANGE_LIMIT)), ranges_left))
ed_ranges_left = random.choices(range(-INT_RANGE, INT_RANGE), k=E)
ed_ranges_right = list(map(lambda x: random.randint(
x, min(INT_RANGE - 1, x + RANGE_LIMIT)), ranges_left))
init_ops = [f'i {key} {value}\n' for key, value in zip(init_keys, init_values)]
insert_ops = [f'i {key} {value}\n' for key, value in zip(keys, values)]
range_ops = [f'r {lvalue} {rvalue}\n' for lvalue,
rvalue in zip(ranges_left, ranges_right)]
ed_ops = [f'r {lvalue} {rvalue}\n' for lvalue,
rvalue in zip(ed_ranges_left, ed_ranges_right)]
rand_ops = insert_ops + range_ops
for _ in range(4):
random.shuffle(rand_ops)
ops = init_ops + rand_ops + ed_ops
with open(sys.argv[1], 'w') as f:
f.write(f'{I + N + M + E}\n')
f.writelines(ops)