In this problem you operate on two arrays of $N$ integers. We will call them the ${0}^{t h}$ and the $1^{st}$ respectively. 

Your goal is just to maintain them under the modification operations, such as:   

1 $\mbox{id}$ $\boldsymbol{l}$ $\textbf{r}$: Reverse the subarray of the $\text{id}^{\text{th}}$ array, starting at the ${l}^{\mbox{th}}$ number, ending at the $r^{\mbox{th}}$ number, inclusively;  
2 $\mbox{id}$ $\boldsymbol{l}_{1}$ $r_1$ $l_2$ $r_2$: Swap two consecutive fragments of the $\text{id}^{\text{th}}$ array, the first is from the $l_1^{th}$ number to the $r_1^{th}$, the second is from the $l_{2}^{t h}$ number to the $r_2^{th}$;  
3 $\boldsymbol{l}$ $\textbf{r}$: Swap the piece that starts at the ${l}^{\mbox{th}}$ number and end at the $r^{\mbox{th}}$ one between the ${0}^{t h}$ and the $1^{st}$ array;  
4 $\boldsymbol{l}$ $\textbf{r}$: We consider only the piece from the ${l}^{\mbox{th}}$ number to the $r^{\mbox{th}}$ one. The numbers in the ${0}^{t h}$ array are $\mbox{X}$-coordinates of some set of points and the numbers in the $1^{st}$ array are $\mathbf{Y}$-coordinates of them. For the obtained set of points we would like to place such a circle on a plane that would contain all the points in it and would have the minimal radius. Find this minimal radius.  

Input Format 

The first line of input contains two space separated integers $N$ and $\mbox{M}$ denoting the number of integers in arrays and the number of queries respectively. 

The second line contains $N$ space separated integers: the initial elements of the ${0}^{t h}$ array. 

The third line contains $N$ space separated integers: the initial elements of the $1^{th}$ array. 

Then there are $\mbox{M}$ lines containing queries in the format listed above.  

Output Format 

For each type-4 query output the sought minimal radius with exactly two symbols after the decimal point precision.  

Constraints 

$1\leq N,M\leq10^5$ 

All the numbers in arrays are non-negative and don't exceed $10^{6}$. 

The sum of $R-L$ over the type-4 queries won't exceed $10^{6}$. 

In the query of the type 2, $1\leq l_1\leq r_1<l_2\leq r_2\leq N$. 

In the queries of the types 1, 3, 4, $1\leq l\leq r\leq N$; $0\leq id<2$.

Sample Input

10 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
3 2 6
1 0 9 9
4 6 9
2 0 2 7 9 9
1 0 3 6
2 1 2 3 4 5
1 1 7 10
2 1 8 8 9 10
4 6 9
2 0 2 2 4 6

Example Output

2.12
2.50

Source: hackerrank | Difficulty: MEDIUM_HARD
Tags: Data structures


Solutions:
def check_function(*args):
	pass

def reverse(arr, l, r):
	arr[l - 1:r] = reversed(arr[l - 1:r])
	return arr
check_function(reverse, [([[1, 2, 3, 4], 2, 3], [1, 3, 2, 4]), ([[1, 2, 3, 4], 1, 4], [4, 3, 2, 1]), ([[1, 2, 3, 4], 1, 3], [3, 2, 1, 4]), ([[1, 2, 3, 4], 2, 4], [1, 4, 3, 2])])

def swap1(arr, l1, r1, l2, r2):
	return arr[:l1 - 1] + arr[l2 - 1:r2] + arr[r1:l2 - 1] + arr[l1 - 1:r1] + arr[r2:]
check_function(swap1, [([[1, 2, 3, 4, 5], 2, 2, 4, 4], [1, 4, 3, 2, 5]), ([[1, 2, 3, 4, 5], 1, 2, 4, 4], [4, 3, 1, 2, 5]), ([[1, 2, 3, 4, 5], 2, 2, 4, 5], [1, 4, 5, 3, 2])])

def swap2(arr1, arr2, l, r):
	return [arr1[:l - 1] + arr2[l - 1:r] + arr1[r:], arr2[:l - 1] + arr1[l - 1:r] + arr2[r:]]
check_function(swap2, [([[1, 2, 3, 4], [5, 6, 7, 8], 2, 3], [[1, 6, 7, 4], [5, 2, 3, 8]])])
from math import sqrt

def dist(p1, p2):
	x = p1[0] - p2[0]
	y = p1[1] - p2[1]
	return sqrt(x * x + y * y)
check_function(dist, [([(0, 1), (1, 1)], 1), ([(0, 0), (3, 4)], 5)])

def vec(p1, p2):
	return (p2[0] - p1[0], p2[1] - p1[1])

def dot(v1, v2):
	return v1[0] * v2[0] + v1[1] * v2[1]

def cross(v1, v2):
	return v1[0] * v2[1] - v1[1] * v2[0]

def mid(p1, p2):
	return ((p2[0] + p1[0]) / 2, (p2[1] + p1[1]) / 2)

def circumradius(p1, p2, p3):
	d1 = dist(p2, p3)
	d2 = dist(p1, p3)
	d3 = dist(p2, p1)
	return d1 * d2 * d3 / sqrt((d1 + d2 + d3) * (d1 + d2 - d3) * (d1 - d2 + d3) * (-d1 + d2 + d3))
check_function(circumradius, [([(0, 0), (0, 1), (1, 0)], sqrt(1 / 2)), ([(-1, 0), (1 / 2, sqrt(3) / 2), (1 / 2, -sqrt(3) / 2)], 1)])

def circumcenter(p1, p2, p3):
	d = 2 * (cross(p1, p2) + cross(p2, p3) + cross(p3, p1))
	if d == 0:
		return None
	l1 = dot(p1, p1)
	l2 = dot(p2, p2)
	l3 = dot(p3, p3)
	return ((l1 * (p2[1] - p3[1]) + l2 * (p3[1] - p1[1]) + l3 * (p1[1] - p2[1])) / d, (l1 * (p3[0] - p2[0]) + l2 * (p1[0] - p3[0]) + l3 * (p2[0] - p1[0])) / d)

def circumcircle(p1, p2, p3):
	center = circumcenter(p1, p2, p3)
	if center is None:
		return None
	radius = circumradius(p1, p2, p3)
	return (radius, center)
check_function(circumcircle, [([(0, 0), (1, 1), (2, 2)], None), ([(0, 0), (0, 1), (1, 0)], (sqrt(1 / 2), (0.5, 0.5))), ([(-1, 0), (1 / 2, sqrt(3) / 2), (1 / 2, -sqrt(3) / 2)], (1, (0, 0)))])

def circle_diameter(p1, p2):
	return (dist(p1, p2) / 2, mid(p1, p2))
check_function(circle_diameter, [([(0, 0), (6, 8)], (5, (3, 4)))])

def smallest_circle_trivial(points):
	npoints = len(points)
	if not npoints:
		return (0, (0, 0))
	if npoints == 1:
		return (0, points[0])
	if npoints == 2:
		return circle_diameter(*points)
	if npoints > 3:
		raise ValueError('smallest_circle_trivial: non-trivial', npoints, points)
	(p1, p2, p3) = points
	s1 = vec(p2, p3)
	s2 = vec(p3, p1)
	s3 = vec(p1, p2)
	if dot(s1, s2) >= 0:
		return circle_diameter(p1, p2)
	if dot(s2, s3) >= 0:
		return circle_diameter(p2, p3)
	if dot(s3, s1) >= 0:
		return circle_diameter(p3, p1)
	return circumcircle(p1, p2, p3)
smallest_circle_trivial_tests = [([[]], (0, (0, 0))), ([[(1, 2)]], (0, (1, 2))), ([[(1, 3), (1, 1)]], (1, (1, 2))), ([[(0, 0), (0, 1), (1, 0)]], (sqrt(1 / 2), (0.5, 0.5))), ([[(0, 0), (0, 10), (1, 4)]], (5, (0, 5))), ([[(0, 0), (1, 4), (0, 10)]], (5, (0, 5))), ([[(1, 4), (0, 0), (0, 10)]], (5, (0, 5))), ([[(1, 4), (0, 10), (0, 0)]], (5, (0, 5))), ([[(0, 10), (0, 0), (1, 4)]], (5, (0, 5))), ([[(0, 10), (1, 4), (0, 0)]], (5, (0, 5))), ([[(-1, 0), (1 / 2, sqrt(3) / 2), (1 / 2, -sqrt(3) / 2)]], (1, (0, 0)))]
check_function(smallest_circle_trivial, smallest_circle_trivial_tests)

def inside_p(point, circle):
	return circle[0] >= dist(circle[1], point)
from random import choice

def smallest_circle_welzl(points, boundary=None):
	points = list(set(points))
	if boundary is None:
		boundary = []
	if not points or len(boundary) == 3:
		return smallest_circle_trivial(boundary)
	p = choice(points)
	rest = list(set(points) - {p})
	circle = smallest_circle_welzl(rest, boundary)
	if inside_p(p, circle):
		return circle
	return smallest_circle_welzl(rest, boundary + [p])
check_function(smallest_circle_welzl, smallest_circle_trivial_tests + [([[(0, 1), (0, 0), (1, 0), (1, 1)]], (sqrt(1 / 2), (1 / 2, 1 / 2))), ([[(-1, 0), (1 / 2, sqrt(3) / 2), (1 / 2, -sqrt(3) / 2), (0, 1), (0, -1), (0, 1 / 2), (3 / 5, 4 / 5), (1, 0), (sqrt(3) / 2, 1 / 2), (-sqrt(3) / 2, 1 / 2), (0, 0), (sqrt(1 / 2), sqrt(1 / 2))]], (1, (0, 0)))])

def run_queries(n, arrs, queries):
	for (query, *parameters) in queries:
		if query == 1:
			arrs[parameters[0]] = reverse(arrs[parameters[0]], *parameters[1:])
			assert len(arrs[parameters[0]]) == n
		elif query == 2:
			arrs[parameters[0]] = swap1(arrs[parameters[0]], *parameters[1:])
			assert len(arrs[parameters[0]]) == n
		elif query == 3:
			arrs = swap2(arrs[0], arrs[1], *parameters)
			assert n == len(arrs[0])
			assert n == len(arrs[1])
		elif query == 4:
			circle = smallest_circle_welzl(zip(arrs[0][parameters[0] - 1:parameters[1]], arrs[1][parameters[0] - 1:parameters[1]]))
			print('{:.2f}'.format(circle[0]))
		else:
			raise ValueError('run_queries', query, parameters)

def read_int_line():
	return [int(x) for x in input().split()]
(n, m) = read_int_line()
arrs = [read_int_line(), read_int_line()]
assert n == len(arrs[0])
assert n == len(arrs[1])
queries = [read_int_line() for _ in range(m)]
run_queries(n, arrs, queries)


import copy
import math, random
import itertools
(N, M) = map(int, input().split())
arr0 = list(map(int, input().split()))
arr1 = list(map(int, input().split()))
arr = [arr0, arr1]
TOLERANCE = 1e-08

def about_eq(f1, f2):
	return abs(f1 - f2) < TOLERANCE

class Point:

	def __init__(self, x=None, y=None):
		self.x = x if x is None else float(x)
		self.y = y if y is None else float(y)

	def __bool__(self):
		return self.x is not None and self.y is not None

	def __eq__(self, p):
		return about_eq(self.x, p.x) and about_eq(self.y, p.y)

	def __hash__(self):
		return hash((self.x, self.y))

	def __str__(self):
		return '(%.4f, %.4f)' % (self.x, self.y)

	def distance(self, p):
		dist_x = p.x - self.x
		dist_y = p.y - self.y
		return (dist_x ** 2 + dist_y ** 2) ** 0.5

	def value(self):
		return (self.x, self.y)
	__nonzero__ = __bool__

class Circle:

	def __init__(self, center, radius):
		self.center = center
		self.radius = radius

	def __bool__(self):
		return self.center is not None and self.radius is not None

	def __contains__(self, p):
		return self.center.distance(p) <= self.radius + TOLERANCE

	def __eq__(self, c):
		return self.center == c.center and about_eq(self.radius, c.radius)

	def __hash__(self):
		return hash((self.center, self.radius))

	def __str__(self):
		return '%.2f' % self.radius if self else 'Circle is None'
	__nonzero__ = __bool__

def _mini_circle_2_points(p1, p2):
	center = Point((p1.x + p2.x) * 0.5, (p1.y + p2.y) * 0.5)
	radius = center.distance(p1)
	return Circle(center, radius)

def _mini_circle_3_points(A, B, C):
	a = B.distance(C)
	b = C.distance(A)
	c = A.distance(B)
	if a ** 2 >= b ** 2 + c ** 2:
		return _mini_circle_2_points(B, C)
	elif b ** 2 >= c ** 2 + a ** 2:
		return _mini_circle_2_points(C, A)
	elif c ** 2 >= a ** 2 + b ** 2:
		return _mini_circle_2_points(A, B)
	D = 2 * (A.x * (B.y - C.y) + B.x * (C.y - A.y) + C.x * (A.y - B.y))
	x = ((A.x ** 2 + A.y ** 2) * (B.y - C.y) + (B.x ** 2 + B.y ** 2) * (C.y - A.y) + (C.x ** 2 + C.y ** 2) * (A.y - B.y)) / D
	y = ((A.x ** 2 + A.y ** 2) * (C.x - B.x) + (B.x ** 2 + B.y ** 2) * (A.x - C.x) + (C.x ** 2 + C.y ** 2) * (B.x - A.x)) / D
	center = Point(x, y)
	radius = center.distance(A)
	return Circle(center, radius)

def _b_minicircle0(R):
	if len(R) == 0:
		return Circle(None, None)
	if len(R) == 1:
		return Circle(R.pop(), 0)
	elif len(R) == 2:
		p1 = R.pop()
		p2 = R.pop()
		return _mini_circle_2_points(p1, p2)
	else:
		return _mini_circle_3_points(*list(R))

def _b_minicircle(P, R):
	P = copy.deepcopy(P)
	R = copy.deepcopy(R)
	if len(P) == 0 or len(R) == 3:
		D = _b_minicircle0(R)
	else:
		p = P.pop()
		D = _b_minicircle(P, R)
		if not D or p not in D:
			R.add(p)
			D = _b_minicircle(P, R)
	return D

def _make_Set_of_Points(points):
	return set([p if isinstance(p, Point) else Point(p[0], p[1]) for p in points])

def minicircle(points):
	P = _make_Set_of_Points(points)
	return _b_minicircle(P, set()) if P else None
for i in range(M):
	q = list(map(int, input().split()))
	if q[0] == 1:
		l = arr[q[1]]
		q[2] = q[2] - 1
		q[3] = q[3] - 1
		l_part1 = l[:q[2]]
		l_part2 = l[q[2]:q[3] + 1]
		l_part3 = l[q[3] + 1:]
		l_part2.reverse()
		l_part1.extend(l_part2)
		l_part1.extend(l_part3)
		arr[q[1]] = l_part1
	elif q[0] == 2:
		l = copy.deepcopy(arr[q[1]])
		q[2] -= 1
		q[3] -= 1
		q[4] -= 1
		q[5] -= 1
		slice_temp = [slice(0, q[2]), slice(q[4], q[5] + 1), slice(q[3] + 1, q[4]), slice(q[2], q[3] + 1), slice(q[5] + 1, len(arr[q[1]]))]
		arr[q[1]] = list(itertools.chain.from_iterable([arr[q[1]][x] for x in slice_temp]))
	elif q[0] == 3:
		q[1] -= 1
		q[2] -= 1
		(arr[0][q[1]:q[2] + 1], arr[1][q[1]:q[2] + 1]) = (arr[1][q[1]:q[2] + 1], arr[0][q[1]:q[2] + 1])
	elif q[0] == 4:
		q[1] -= 1
		q[2] -= 1
		print(minicircle(zip(arr[0][q[1]:q[2] + 1], arr[1][q[1]:q[2] + 1])))


def check_function(*args):
	pass

def reverse(arr, l, r):
	arr[l - 1:r] = reversed(arr[l - 1:r])
	return arr
check_function(reverse, [([[1, 2, 3, 4], 2, 3], [1, 3, 2, 4]), ([[1, 2, 3, 4], 1, 4], [4, 3, 2, 1]), ([[1, 2, 3, 4], 1, 3], [3, 2, 1, 4]), ([[1, 2, 3, 4], 2, 4], [1, 4, 3, 2])])

def swap1(arr, l1, r1, l2, r2):
	return arr[:l1 - 1] + arr[l2 - 1:r2] + arr[r1:l2 - 1] + arr[l1 - 1:r1] + arr[r2:]
check_function(swap1, [([[1, 2, 3, 4, 5], 2, 2, 4, 4], [1, 4, 3, 2, 5]), ([[1, 2, 3, 4, 5], 1, 2, 4, 4], [4, 3, 1, 2, 5]), ([[1, 2, 3, 4, 5], 2, 2, 4, 5], [1, 4, 5, 3, 2])])

def swap2(arr1, arr2, l, r):
	return [arr1[:l - 1] + arr2[l - 1:r] + arr1[r:], arr2[:l - 1] + arr1[l - 1:r] + arr2[r:]]
check_function(swap2, [([[1, 2, 3, 4], [5, 6, 7, 8], 2, 3], [[1, 6, 7, 4], [5, 2, 3, 8]])])
from math import sqrt

def dist(p1, p2):
	x = p1[0] - p2[0]
	y = p1[1] - p2[1]
	return sqrt(x * x + y * y)
check_function(dist, [([(0, 1), (1, 1)], 1), ([(0, 0), (3, 4)], 5)])

def vec(p1, p2):
	return (p2[0] - p1[0], p2[1] - p1[1])

def dot(v1, v2):
	return v1[0] * v2[0] + v1[1] * v2[1]

def cross(v1, v2):
	return v1[0] * v2[1] - v1[1] * v2[0]

def mid(p1, p2):
	return ((p2[0] + p1[0]) / 2, (p2[1] + p1[1]) / 2)

def circumradius(p1, p2, p3):
	d1 = dist(p2, p3)
	d2 = dist(p1, p3)
	d3 = dist(p2, p1)
	return d1 * d2 * d3 / sqrt((d1 + d2 + d3) * (d1 + d2 - d3) * (d1 - d2 + d3) * (-d1 + d2 + d3))
check_function(circumradius, [([(0, 0), (0, 1), (1, 0)], sqrt(1 / 2)), ([(-1, 0), (1 / 2, sqrt(3) / 2), (1 / 2, -sqrt(3) / 2)], 1)])

def circumcenter(p1, p2, p3):
	d = 2 * (cross(p1, p2) + cross(p2, p3) + cross(p3, p1))
	if d == 0:
		return None
	l1 = dot(p1, p1)
	l2 = dot(p2, p2)
	l3 = dot(p3, p3)
	return ((l1 * (p2[1] - p3[1]) + l2 * (p3[1] - p1[1]) + l3 * (p1[1] - p2[1])) / d, (l1 * (p3[0] - p2[0]) + l2 * (p1[0] - p3[0]) + l3 * (p2[0] - p1[0])) / d)

def circumcircle(p1, p2, p3):
	center = circumcenter(p1, p2, p3)
	if center is None:
		return None
	radius = circumradius(p1, p2, p3)
	return (radius, center)
check_function(circumcircle, [([(0, 0), (1, 1), (2, 2)], None), ([(0, 0), (0, 1), (1, 0)], (sqrt(1 / 2), (0.5, 0.5))), ([(-1, 0), (1 / 2, sqrt(3) / 2), (1 / 2, -sqrt(3) / 2)], (1, (0, 0)))])

def circle_diameter(p1, p2):
	return (dist(p1, p2) / 2, mid(p1, p2))
check_function(circle_diameter, [([(0, 0), (6, 8)], (5, (3, 4)))])

def smallest_circle_trivial(points):
	npoints = len(points)
	if not npoints:
		return (0, (0, 0))
	if npoints == 1:
		return (0, points[0])
	if npoints == 2:
		return circle_diameter(*points)
	if npoints > 3:
		raise ValueError('smallest_circle_trivial: non-trivial', npoints, points)
	(p1, p2, p3) = points
	s1 = vec(p2, p3)
	s2 = vec(p3, p1)
	s3 = vec(p1, p2)
	if dot(s1, s2) >= 0:
		return circle_diameter(p1, p2)
	if dot(s2, s3) >= 0:
		return circle_diameter(p2, p3)
	if dot(s3, s1) >= 0:
		return circle_diameter(p3, p1)
	return circumcircle(p1, p2, p3)
smallest_circle_trivial_tests = [([[]], (0, (0, 0))), ([[(1, 2)]], (0, (1, 2))), ([[(1, 3), (1, 1)]], (1, (1, 2))), ([[(0, 0), (0, 1), (1, 0)]], (sqrt(1 / 2), (0.5, 0.5))), ([[(0, 0), (0, 10), (1, 4)]], (5, (0, 5))), ([[(0, 0), (1, 4), (0, 10)]], (5, (0, 5))), ([[(1, 4), (0, 0), (0, 10)]], (5, (0, 5))), ([[(1, 4), (0, 10), (0, 0)]], (5, (0, 5))), ([[(0, 10), (0, 0), (1, 4)]], (5, (0, 5))), ([[(0, 10), (1, 4), (0, 0)]], (5, (0, 5))), ([[(-1, 0), (1 / 2, sqrt(3) / 2), (1 / 2, -sqrt(3) / 2)]], (1, (0, 0)))]
check_function(smallest_circle_trivial, smallest_circle_trivial_tests)

def inside_p(point, circle):
	return circle[0] >= dist(circle[1], point)
from random import choice

def smallest_circle_welzl(points, boundary=None):
	points = list(set(points))
	if boundary is None:
		boundary = []
	if not points or len(boundary) == 3:
		return smallest_circle_trivial(boundary)
	p = choice(points)
	rest = list(set(points) - {p})
	circle = smallest_circle_welzl(rest, boundary)
	if inside_p(p, circle):
		return circle
	return smallest_circle_welzl(rest, boundary + [p])
check_function(smallest_circle_welzl, smallest_circle_trivial_tests + [([[(0, 1), (0, 0), (1, 0), (1, 1)]], (sqrt(1 / 2), (1 / 2, 1 / 2))), ([[(-1, 0), (1 / 2, sqrt(3) / 2), (1 / 2, -sqrt(3) / 2), (0, 1), (0, -1), (0, 1 / 2), (3 / 5, 4 / 5), (1, 0), (sqrt(3) / 2, 1 / 2), (-sqrt(3) / 2, 1 / 2), (0, 0), (sqrt(1 / 2), sqrt(1 / 2))]], (1, (0, 0)))])

def run_queries(n, arrs, queries):
	for (query, *parameters) in queries:
		if query == 1:
			arrs[parameters[0]] = reverse(arrs[parameters[0]], *parameters[1:])
			assert len(arrs[parameters[0]]) == n
		elif query == 2:
			arrs[parameters[0]] = swap1(arrs[parameters[0]], *parameters[1:])
			assert len(arrs[parameters[0]]) == n
		elif query == 3:
			arrs = swap2(arrs[0], arrs[1], *parameters)
			assert n == len(arrs[0])
			assert n == len(arrs[1])
		elif query == 4:
			circle = smallest_circle_welzl(zip(arrs[0][parameters[0] - 1:parameters[1]], arrs[1][parameters[0] - 1:parameters[1]]))
			print('{:.2f}'.format(circle[0]))
		else:
			raise ValueError('run_queries', query, parameters)

def read_int_line():
	return [int(x) for x in input().split()]
(n, m) = read_int_line()
arrs = [read_int_line(), read_int_line()]
assert n == len(arrs[0])
assert n == len(arrs[1])
queries = [read_int_line() for _ in range(m)]
run_queries(n, arrs, queries)


import math
import os
import random
import re

class Point:

	def __init__(self, newx=0, newy=0):
		self.x = newx
		self.y = newy

	def distance(self, other):
		d = math.sqrt((self.x - other.x) ** 2 + (self.y - other.y) ** 2)
		return d

	def is_inside(self, c):
		return self.distance(c.center) <= c.radius

	def __str__(self):
		return f'({self.x}, {self.y})'

class Circle:

	def __init__(self, c=Point(), r=0):
		self.center = c
		self.radius = r

	def is_valid(self, P):
		for p in P:
			if not p.is_inside(self):
				return False
		return True

def collinear(A, B, C):
	return abs((A.y - B.y) * (A.x - C.x) - (A.y - C.y) * (A.x - B.x)) <= 1e-09

def get_circle_center(A, B, C):
	bx = B.x - A.x
	by = B.y - A.y
	cx = C.x - A.x
	cy = C.y - A.y
	b = bx ** 2 + by ** 2
	c = cx ** 2 + cy ** 2
	d = bx * cy - by * cx
	if d == 0:
		print('div by zero')
	return Point((cy * b - by * c) / (2 * d), (bx * c - cx * b) / (2 * d))

def circle_from_2points(A, B):
	C = Point((A.x + B.x) / 2.0, (A.y + B.y) / 2.0)
	return Circle(C, A.distance(B) / 2.0)

def circle_from_3points(A, B, C):
	I = get_circle_center(A, B, C)
	I.x += A.x
	I.y += A.y
	return Circle(I, A.distance(I))

def min_circle_trivial(R):
	if len(R) == 0:
		return Circle()
	elif len(R) == 1:
		return Circle(R[0], 0)
	elif len(R) == 2:
		return circle_from_2points(R[0], R[1])
	c = circle_from_2points(R[0], R[1])
	if c.is_valid(P):
		return c
	c = circle_from_2points(R[0], R[2])
	if c.is_valid(P):
		return c
	c = circle_from_2points(R[1], R[2])
	if c.is_valid(P):
		return c
	return circle_from_3points(R[0], R[1], R[2])

def find_MEC(P, R, n):
	if n == 0 or len(R) == 3:
		return min_circle_trivial(R)
	ridx = random.randint(0, n - 1)
	rndm_p = P[ridx]
	(P[ridx], P[n - 1]) = (P[n - 1], P[ridx])
	d = find_MEC(P, R.copy(), n - 1)
	if rndm_p.is_inside(d):
		return d
	R.append(rndm_p)
	return find_MEC(P, R.copy(), n - 1)
nm = input()
N = eval(nm.split()[0])
M = eval(nm.split()[1])
A = [0, 0]
A[0] = [0] + list(map(int, input().split()))
A[1] = [0] + list(map(int, input().split()))
for _ in range(M):
	q = list(map(int, input().split()))
	qtype = q[0]
	if qtype == 1:
		(id, l, r) = q[1:]
		A[id][l:r + 1] = reversed(A[id][l:r + 1])
	elif qtype == 2:
		(id, l1, r1, l2, r2) = q[1:]
		A[id] = A[id][0:l1] + A[id][l2:r2 + 1] + A[id][r1 + 1:l2] + A[id][l1:r1 + 1] + A[id][r2 + 1:]
	elif qtype == 3:
		(l, r) = q[1:]
		temp = A[0][l:r + 1]
		A[0][l:r + 1] = A[1][l:r + 1]
		A[1][l:r + 1] = temp
	elif qtype == 4:
		(l, r) = q[1:]
		P = []
		for i in range(l, r + 1):
			p = Point(A[0][i], A[1][i])
			P.append(p)
		c = find_MEC(P, R=[], n=len(P))
		print(f'{c.radius:.2f}')


def check_function(*args):
	pass

def reverse(arr, l, r):
	arr[l - 1:r] = reversed(arr[l - 1:r])
	return arr
check_function(reverse, [([[1, 2, 3, 4], 2, 3], [1, 3, 2, 4]), ([[1, 2, 3, 4], 1, 4], [4, 3, 2, 1]), ([[1, 2, 3, 4], 1, 3], [3, 2, 1, 4]), ([[1, 2, 3, 4], 2, 4], [1, 4, 3, 2])])

def swap1(arr, l1, r1, l2, r2):
	return arr[:l1 - 1] + arr[l2 - 1:r2] + arr[r1:l2 - 1] + arr[l1 - 1:r1] + arr[r2:]
check_function(swap1, [([[1, 2, 3, 4, 5], 2, 2, 4, 4], [1, 4, 3, 2, 5]), ([[1, 2, 3, 4, 5], 1, 2, 4, 4], [4, 3, 1, 2, 5]), ([[1, 2, 3, 4, 5], 2, 2, 4, 5], [1, 4, 5, 3, 2])])

def swap2(arr1, arr2, l, r):
	return [arr1[:l - 1] + arr2[l - 1:r] + arr1[r:], arr2[:l - 1] + arr1[l - 1:r] + arr2[r:]]
check_function(swap2, [([[1, 2, 3, 4], [5, 6, 7, 8], 2, 3], [[1, 6, 7, 4], [5, 2, 3, 8]])])
from math import sqrt

def dist(p1, p2):
	x = p1[0] - p2[0]
	y = p1[1] - p2[1]
	return sqrt(x * x + y * y)
check_function(dist, [([(0, 1), (1, 1)], 1), ([(0, 0), (3, 4)], 5)])

def vec(p1, p2):
	return (p2[0] - p1[0], p2[1] - p1[1])

def dot(v1, v2):
	return v1[0] * v2[0] + v1[1] * v2[1]

def cross(v1, v2):
	return v1[0] * v2[1] - v1[1] * v2[0]

def mid(p1, p2):
	return ((p2[0] + p1[0]) / 2, (p2[1] + p1[1]) / 2)

def circumradius(p1, p2, p3):
	d1 = dist(p2, p3)
	d2 = dist(p1, p3)
	d3 = dist(p2, p1)
	return d1 * d2 * d3 / sqrt((d1 + d2 + d3) * (d1 + d2 - d3) * (d1 - d2 + d3) * (-d1 + d2 + d3))
check_function(circumradius, [([(0, 0), (0, 1), (1, 0)], sqrt(1 / 2)), ([(-1, 0), (1 / 2, sqrt(3) / 2), (1 / 2, -sqrt(3) / 2)], 1)])

def circumcenter(p1, p2, p3):
	d = 2 * (cross(p1, p2) + cross(p2, p3) + cross(p3, p1))
	if d == 0:
		return None
	l1 = dot(p1, p1)
	l2 = dot(p2, p2)
	l3 = dot(p3, p3)
	return ((l1 * (p2[1] - p3[1]) + l2 * (p3[1] - p1[1]) + l3 * (p1[1] - p2[1])) / d, (l1 * (p3[0] - p2[0]) + l2 * (p1[0] - p3[0]) + l3 * (p2[0] - p1[0])) / d)

def circumcircle(p1, p2, p3):
	center = circumcenter(p1, p2, p3)
	if center is None:
		return None
	radius = circumradius(p1, p2, p3)
	return (radius, center)
check_function(circumcircle, [([(0, 0), (1, 1), (2, 2)], None), ([(0, 0), (0, 1), (1, 0)], (sqrt(1 / 2), (0.5, 0.5))), ([(-1, 0), (1 / 2, sqrt(3) / 2), (1 / 2, -sqrt(3) / 2)], (1, (0, 0)))])

def circle_diameter(p1, p2):
	return (dist(p1, p2) / 2, mid(p1, p2))
check_function(circle_diameter, [([(0, 0), (6, 8)], (5, (3, 4)))])

def smallest_circle_trivial(points):
	npoints = len(points)
	if not npoints:
		return (0, (0, 0))
	if npoints == 1:
		return (0, points[0])
	if npoints == 2:
		return circle_diameter(*points)
	if npoints > 3:
		raise ValueError('smallest_circle_trivial: non-trivial', npoints, points)
	(p1, p2, p3) = points
	s1 = vec(p2, p3)
	s2 = vec(p3, p1)
	s3 = vec(p1, p2)
	if dot(s1, s2) >= 0:
		return circle_diameter(p1, p2)
	if dot(s2, s3) >= 0:
		return circle_diameter(p2, p3)
	if dot(s3, s1) >= 0:
		return circle_diameter(p3, p1)
	return circumcircle(p1, p2, p3)
smallest_circle_trivial_tests = [([[]], (0, (0, 0))), ([[(1, 2)]], (0, (1, 2))), ([[(1, 3), (1, 1)]], (1, (1, 2))), ([[(0, 0), (0, 1), (1, 0)]], (sqrt(1 / 2), (0.5, 0.5))), ([[(0, 0), (0, 10), (1, 4)]], (5, (0, 5))), ([[(0, 0), (1, 4), (0, 10)]], (5, (0, 5))), ([[(1, 4), (0, 0), (0, 10)]], (5, (0, 5))), ([[(1, 4), (0, 10), (0, 0)]], (5, (0, 5))), ([[(0, 10), (0, 0), (1, 4)]], (5, (0, 5))), ([[(0, 10), (1, 4), (0, 0)]], (5, (0, 5))), ([[(-1, 0), (1 / 2, sqrt(3) / 2), (1 / 2, -sqrt(3) / 2)]], (1, (0, 0)))]
check_function(smallest_circle_trivial, smallest_circle_trivial_tests)

def inside_p(point, circle):
	return circle[0] >= dist(circle[1], point)
from random import choice

def smallest_circle_welzl(points, boundary=None):
	points = list(set(points))
	if boundary is None:
		boundary = []
	if not points or len(boundary) == 3:
		return smallest_circle_trivial(boundary)
	p = choice(points)
	rest = list(set(points) - {p})
	circle = smallest_circle_welzl(rest, boundary)
	if inside_p(p, circle):
		return circle
	return smallest_circle_welzl(rest, boundary + [p])
check_function(smallest_circle_welzl, smallest_circle_trivial_tests + [([[(0, 1), (0, 0), (1, 0), (1, 1)]], (sqrt(1 / 2), (1 / 2, 1 / 2))), ([[(-1, 0), (1 / 2, sqrt(3) / 2), (1 / 2, -sqrt(3) / 2), (0, 1), (0, -1), (0, 1 / 2), (3 / 5, 4 / 5), (1, 0), (sqrt(3) / 2, 1 / 2), (-sqrt(3) / 2, 1 / 2), (0, 0), (sqrt(1 / 2), sqrt(1 / 2))]], (1, (0, 0)))])

def run_queries(n, arrs, queries):
	for (query, *parameters) in queries:
		if query == 1:
			arrs[parameters[0]] = reverse(arrs[parameters[0]], *parameters[1:])
			assert len(arrs[parameters[0]]) == n
		elif query == 2:
			arrs[parameters[0]] = swap1(arrs[parameters[0]], *parameters[1:])
			assert len(arrs[parameters[0]]) == n
		elif query == 3:
			arrs = swap2(arrs[0], arrs[1], *parameters)
			assert n == len(arrs[0])
			assert n == len(arrs[1])
		elif query == 4:
			circle = smallest_circle_welzl(zip(arrs[0][parameters[0] - 1:parameters[1]], arrs[1][parameters[0] - 1:parameters[1]]))
			print('{:.2f}'.format(circle[0]))
		else:
			raise ValueError('run_queries', query, parameters)

def read_int_line():
	return [int(x) for x in input().split()]
(n, m) = read_int_line()
arrs = [read_int_line(), read_int_line()]
assert n == len(arrs[0])
assert n == len(arrs[1])
queries = [read_int_line() for _ in range(m)]
run_queries(n, arrs, queries)