CF1696G.Fishingprince Plays With Array Again

NOI/NOI+/CTSC

通过率:0%

时间限制:6.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

Suppose you are given a 1-indexed sequence aa of non-negative integers, whose length is nn, and two integers xx, yy. In consecutive tt seconds (tt can be any positive real number), you can do one of the following operations:

  • Select 1≤i<n1\le i \lt n, decrease aia_i by x⋅tx\cdot t, and decrease ai+1a_{i+1} by y⋅ty\cdot t.
  • Select 1≤i<n1\le i \lt n, decrease aia_i by y⋅ty\cdot t, and decrease ai+1a_{i+1} by x⋅tx\cdot t.

Define the minimum amount of time (it might be a real number) required to make all elements in the sequence less than or equal to 00 as f(a)f(a).

For example, when x=1x=1, y=2y=2, it takes 33 seconds to deal with the array [3,1,1,3][3,1,1,3]. We can:

  • In the first 1.51.5 seconds do the second operation with i=1i=1.
  • In the next 1.51.5 seconds do the first operation with i=3i=3.

We can prove that it's not possible to make all elements less than or equal to 00 in less than 33 seconds, so f([3,1,1,3])=3f([3,1,1,3])=3.

Now you are given a 1-indexed sequence bb of positive integers, whose length is nn. You are also given positive integers xx, yy. Process qq queries of the following two types:

  • 1 k v: change bkb_k to vv.
  • 2 l r: print f([bl,bl+1,…,br])f([b_l,b_{l+1},\dots,b_r]).

假设你有一个从 1 开始编号的非负整数序列 aa,其长度为 nn,以及两个整数 xx、yy。在连续的 tt 秒内(tt 可为任意正实数),你可以执行以下两种操作之一:

  • 选择满足 1≤i<n1\le i \lt n 的下标 ii,将 aia_i 减少 x⋅tx\cdot t,同时将 ai+1a_{i+1} 减少 y⋅ty\cdot t;
  • 选择满足 1≤i<n1\le i \lt n 的下标 ii,将 aia_i 减少 y⋅ty\cdot t,同时将 ai+1a_{i+1} 减少 x⋅tx\cdot t。

定义使序列中所有元素均小于等于 00 所需的最少时间(该时间可能为实数)为 f(a)f(a)。

例如,当 x=1x=1、y=2y=2 时,处理数组 [3,1,1,3][3,1,1,3] 需要 33 秒。具体方案如下:

  • 前 1.51.5 秒对 i=1i=1 执行第二种操作;
  • 接下来的 1.51.5 秒对 i=3i=3 执行第一种操作。

可以证明,无法在少于 33 秒内使所有元素 ≤0\le 0,因此 f([3,1,1,3])=3f([3,1,1,3])=3。

现在给你一个从 1 开始编号的正整数序列 bb,其长度为 nn,以及正整数 xx、yy。你需要处理 qq 个查询,查询分为以下两类:

  • 1 k v:将 bkb_k 修改为 vv;
  • 2 l r:输出 f([bl,bl+1,…,br])f([b_l,b_{l+1},\dots,b_r])。

输入格式

The first line of input contains two integers nn and qq (2≤n≤2⋅1052\le n\le 2\cdot 10^5, 1≤q≤2⋅1051\le q\le 2\cdot 10^5).

The second line of input contains two integers xx and yy (1≤x,y≤1061\le x,y\le 10^6).

The third line of input contains nn integers b1,b2,…,bnb_1,b_2,\ldots,b_n (1≤bi≤1061\le b_i\le 10^6).

This is followed by qq lines. Each of these qq lines contains three integers. The first integer opop is either 11 or 22.

  • If it is 11, it is followed by two integers kk, vv (1≤k≤n1\le k\le n, 1≤v≤1061\le v\le 10^6). It means that you should change bkb_k to vv.
  • If it is 22, it is followed by two integers ll, rr (1≤l<r≤n1\le l \lt r\le n). It means that you should print f([bl,bl+1,…,br])f([b_l,b_{l+1},\dots,b_r]).

输入的第一行包含两个整数 nn 和 qq(2≤n≤2⋅1052\le n\le 2\cdot 10^5,1≤q≤2⋅1051\le q\le 2\cdot 10^5)。

输入的第二行包含两个整数 xx 和 yy(1≤x,y≤1061\le x,y\le 10^6)。

输入的第三行包含 nn 个整数 b1,b2,…,bnb_1,b_2,\ldots,b_n(1≤bi≤1061\le b_i\le 10^6)。

接下来是 qq 行。每行包含三个整数。第一个整数 opop 为 11 或 22。

  • 若 op=1op=1,则其后跟两个整数 kk、vv(1≤k≤n1\le k\le n,1≤v≤1061\le v\le 10^6),表示将 bkb_k 修改为 vv。
  • 若 op=2op=2,则其后跟两个整数 ll、rr(1≤l<r≤n1\le l \lt r\le n),表示输出 f([bl,bl+1,…,br])f([b_l,b_{l+1},\dots,b_r])。

输出格式

For each query of type 22, print one real number — the answer to the query. Your answer is considered correct if its absolute error or relative error does not exceed 10−910^{-9}.

对于每个类型为 22 的查询,输出一个实数——该查询的答案。若您的答案的绝对误差或相对误差不超过 10−910^{-9},则视为正确。

输入输出样例

  • 输入#1

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

    输出#1

    3.500000000000000
    1.000000000000000

说明/提示

Let's analyse the sample.

In the first query, we are asked to compute f([3,1,1,4])f([3,1,1,4]). The answer is 3.53.5. One optimal sequence of operations is:

  • In the first 1.51.5 seconds do the second operation with i=1i=1.
  • In the next 22 seconds do the first operation with i=3i=3.

In the third query, we are asked to compute f([1,1,1])f([1,1,1]). The answer is 11. One optimal sequence of operations is:

  • In the first 0.50.5 seconds do the second operation with i=1i=1.
  • In the next 0.50.5 seconds do the first operation with i=2i=2.

我们来分析样例。

在第一个查询中,我们需要计算 f([3,1,1,4])f([3,1,1,4])。答案为 3.53.5。一种最优的操作序列如下:

  • 前 1.51.5 秒执行第二种操作,其中 i=1i=1;
  • 接下来的 22 秒执行第一种操作,其中 i=3i=3。

在第三个查询中,我们需要计算 f([1,1,1])f([1,1,1])。答案为 11。一种最优的操作序列如下:

  • 前 0.50.5 秒执行第二种操作,其中 i=1i=1;
  • 接下来的 0.50.5 秒执行第一种操作,其中 i=2i=2。

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

首页