import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner(System.in);
static final int N = (int) (1e5 + 10), M = 320;
static double[] w = new double[N], sum = new double[M], mulsum = new double[M], add = new double[M];
static int n, t, len;
public static void main(String[] args) throws Exception {
n = sc.nextInt(); t = sc.nextInt();
len = (int) Math.sqrt(n);
for (int i = 1; i <= n; i++) {
w[i] = sc.nextDouble();
sum[get(i)] += w[i];
mulsum[get(i)] += w[i] * w[i];
}
while (t-- > 0) {
int op, l, r;
op = sc.nextInt(); l = sc.nextInt(); r = sc.nextInt();
if (op == 1) {
double d = sc.nextDouble();
modify(l, r, d);
} else if (op == 2) {
System.out.printf("%.4f\n", queryAvg(l, r));
} else {
System.out.printf("%.4f\n", queryVar(l, r));
}
}
}
static double queryVar(int l, int r) {
double res = 0;
double m = 0;
if (get(l) == get(r)) {
for (int i = l; i <= r; i++) {
double t = w[i] + add[get(i)];
res += t * t;
m += w[i] + add[get(i)];
}
} else {
int i = l, j = r;
while (get(i) == get(l)) {
double t = w[i] + add[get(i)];
res += t * t;
m += w[i] + add[get(i)];
i++;
}
while (get(j) == get(r)) {
double t = w[j] + add[get(j)];
res += t * t;
m += w[j] + add[get(j)];
j--;
}
for (int k = get(i); k <= get(j); k++) {
res += mulsum[k] + 2 * sum[k] * add[k] + len * add[k] * add[k];
m += sum[k] + add[k] * len;
}
}
double length = r - l + 1;
double avg = m / length;
return res / length - avg * avg;
}
static double queryAvg(int l, int r) {
double res = 0;
if (get(l) == get(r)) {
for (int i = l; i <= r; i++) {
res += w[i] + add[get(i)];
}
} else {
int i = l, j = r;
while (get(i) == get(l)) {
res += w[i] + add[get(i)];
i++;
}
while (get(j) == get(r)) {
res += w[j] + add[get(j)];
j--;
}
for (int k = get(i); k <= get(j); k++) {
res += sum[k] + add[k] * len;
}
}
return res / (double) (r - l + 1);
}
static void modify(int l, int r, double d) {
if (get(l) == get(r)) {
for (int i = l; i <= r; i++) {
mulsum[get(i)] += 2.0 * d * w[i] + d * d;
w[i] += d;
sum[get(i)] += d;
}
} else {
int i = l, j = r;
while (get(i) == get(l)) {
mulsum[get(i)] += 2.0 * d * w[i] + d * d;
w[i] += d;
sum[get(i)] += d;
i++;
}
while (get(j) == get(r)) {
mulsum[get(j)] += 2.0 * d * w[j] + d * d;
w[j] += d;
sum[get(j)] += d;
j--;
}
for (int k = get(i); k <= get(j); k++) {
add[k] += d;
}
}
}
static int get(int i) {
return i / len;
}
}