CF895E.Eyes Closed

提高+/省选-

通过率:0%

时间限制:2.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasya and Petya were tired of studying so they decided to play a game. Before the game begins Vasya looks at array a consisting of n integers. As soon as he remembers all elements of a the game begins. Vasya closes his eyes and Petya does q actions of one of two types:

  1. Petya says 4 integers _l_1, _r_1, _l_2, _r_2 — boundaries of two non-intersecting segments. After that he swaps one random element from the [_l_1, _r_1] segment with another random element from the [_l_2, _r_2] segment.

  2. Petya asks Vasya the sum of the elements of a in the [l, r] segment.

Vasya is a mathematician so he answers Petya the mathematical expectation of the sum of the elements in the segment.

Your task is to write a program which will answer the second type questions as Vasya would do it. In other words your program should print the mathematical expectation of the sum of the elements of a in the [l, r] segment for every second type query.

瓦西娅和佩佳学习累了,于是决定玩一个游戏。游戏开始前,瓦西娅观察一个由 nn 个整数组成的数组 aa。一旦他记住了数组 aa 的所有元素,游戏便正式开始。瓦西娅闭上眼睛,佩佳执行 qq 次操作,每次操作为以下两种类型之一:

  1. 佩佳给出四个整数 l1, r1, l2, r2l_1,\ r_1,\ l_2,\ r_2 —— 表示两个互不相交区间的边界。随后,他从区间 [l1, r1][l_1,\ r_1] 中随机选取一个元素,再从区间 [l2, r2][l_2,\ r_2] 中随机选取一个元素,并将这两个元素交换。

  2. 佩佳询问瓦西娅:数组 aa 在区间 [l, r][l,\ r] 内所有元素的和是多少?

瓦西娅是一名数学家,因此他回答的是该区间内元素之和的数学期望值。

你的任务是编写一个程序,对每一个第二类查询,按瓦西娅的方式作答——即输出数组 aa 在区间 [l, r][l,\ r] 内元素之和的数学期望值。

输入格式

The first line contains two integers n, q (2 ≤ n ≤ 105, 1 ≤ q ≤ 105) — the number of elements in the array and the number of queries you need to handle.

The second line contains n integers a__i (1 ≤ a__i ≤ 109) — elements of the array.

The next q lines contain Petya's actions of type 1 or 2.

If it is a type 1 action then the line contains 5 integers 1, _l_1, _r_1, _l_2, _r_2 (1 ≤ _l_1 ≤ _r_1 ≤ n, 1 ≤ _l_2 ≤ _r_2 ≤ n).

If it is a type 2 query then the line contains 3 integers 2, l, r (1 ≤ l ≤ r ≤ n).

It is guaranteed that there is at least one type 2 query and segments [_l_1, _r_1], [_l_2, _r_2] don't have common elements.

第一行包含两个整数 nn 和 qq(2≤n≤1052 \leq n \leq 10^5,1≤q≤1051 \leq q \leq 10^5)—— 分别表示数组的元素个数以及需要处理的查询次数。

第二行包含 nn 个整数 aia_i(1≤ai≤1091 \leq a_i \leq 10^9)—— 表示数组的元素。

接下来的 qq 行描述了 Petya 执行的操作,类型为 1 或 2。

若为类型 1 的操作,则该行包含 5 个整数:1, l1, r1, l2, r21,\ l_1,\ r_1,\ l_2,\ r_2(其中 1≤l1≤r1≤n1 \leq l_1 \leq r_1 \leq n,1≤l2≤r2≤n1 \leq l_2 \leq r_2 \leq n)。

若为类型 2 的查询,则该行包含 3 个整数:2, l, r2,\ l,\ r(其中 1≤l≤r≤n1 \leq l \leq r \leq n)。

保证至少存在一个类型 2 的查询,且区间 [l1, r1][l_1,\ r_1] 与 [l2, r2][l_2,\ r_2] 不相交。

输出格式

For each type 2 query print one real number — the mathematical expectation of the sum of elements in the segment.

Your answer will be considered correct if its absolute or relative error doesn't exceed 10 - 4 — formally, the answer is correct if where x is jury's answer and y is yours.

对于每个类型 2 的查询,输出一个实数——该区间内元素和的数学期望值。

若你的答案的绝对误差或相对误差不超过 10−410^{-4},则视为正确。形式化地说,当且仅当

时,答案正确,其中 xx 是出题方的答案,yy 是你的答案。

输入输出样例

  • 输入#1

    4 4
    1 1 2 2
    1 2 2 3 3
    2 1 2
    1 1 2 3 4
    2 1 2

    输出#1

    3.0000000
    3.0000000
  • 输入#2

    10 5
    1 1 1 1 1 2 2 2 2 2
    1 1 5 6 10
    2 1 5
    1 1 5 6 10
    1 1 5 6 10
    2 6 10

    输出#2

    6.0000000
    8.0400000
  • 输入#3

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

    输出#3

    23.0000000
    14.0000000
    28.0133333
    21.5733333
    55.0000000

输入解题思路,AI测评打分。不知道怎么写?

首页