CF855F.Nagini

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Nagini, being a horcrux You-know-who created with the murder of Bertha Jorkins, has accumulated its army of snakes and is launching an attack on Hogwarts school.

Hogwarts' entrance can be imagined as a straight line (x-axis) from 1 to 105. Nagini is launching various snakes at the Hogwarts entrance. Each snake lands parallel to the entrance, covering a segment at a distance k from x = l to x = r. Formally, each snake can be imagined as being a line segment between points (l, k) and (r, k). Note that k can be both positive and negative, but not 0.

Let, at some x-coordinate x = i, there be snakes at point (i, _y_1) and point (i, _y_2), such that _y_1 > 0 and _y_2 < 0. Then, if for any point (i, _y_3) containing a snake such that _y_3 > 0, _y_1 ≤ _y_3 holds and for any point (i, _y_4) containing a snake such that _y_4 < 0, |_y_2| ≤ |_y_4| holds, then the danger value at coordinate x = i is _y_1 + |_y_2|. If no such _y_1 and _y_2 exist, danger value is 0.

Harry wants to calculate the danger value of various segments of the Hogwarts entrance. Danger value for a segment [l, r) of the entrance can be calculated by taking the sum of danger values for each integer x-coordinate present in the segment.

Formally, you have to implement two types of queries:

  • 1 l r k: a snake is added parallel to entrance from x = l to x = r at y-coordinate y = k (l inclusive, r exclusive).
  • 2 l r: you have to calculate the danger value of segment l to r (l inclusive, r exclusive).

纳吉尼是伏地魔杀害伯莎·乔金斯后制造的魂器,它已集结起蛇群,正向霍格沃茨学校发起进攻。

霍格沃茨的入口可被建模为一条直线(即 xx 轴),范围从 11 到 10510^5。纳吉尼正向霍格沃茨入口投掷各类蛇。每条蛇以与入口平行的方式着陆,在距离 x=lx = l 到 x=rx = r 的区间上覆盖一段线段,其纵坐标为 kk。形式化地说,每条蛇可视为连接点 (l, k)(l,\,k) 与 (r, k)(r,\,k) 的一条线段。注意:kk 可取正数或负数,但不能为 00。

设在某横坐标 x=ix = i 处,存在两条蛇分别位于点 (i, y1)(i,\,y_1) 和 (i, y2)(i,\,y_2),满足 y1>0y_1 > 0 且 y2<0y_2 < 0。若对任意位于 (i, y3)(i,\,y_3) 的蛇(其中 y3>0y_3 > 0)均有 y1≤y3y_1 \le y_3,且对任意位于 (i, y4)(i,\,y_4) 的蛇(其中 y4<0y_4 < 0)均有 ∣y2∣≤∣y4∣|y_2| \le |y_4|,则横坐标 x=ix = i 处的危险值为 y1+∣y2∣y_1 + |y_2|。若不存在满足上述条件的 y1y_1 和 y2y_2,则该坐标的危险值为 00。

哈利希望计算霍格沃茨入口若干区间的危险值。入口区间 [l, r)[l,\,r) 的危险值定义为该区间内所有整数横坐标 xx 对应的危险值之和。

形式化地,你需要支持以下两种操作:

  • 1 l r k:添加一条蛇,其沿入口方向(即水平方向)覆盖横坐标区间 [l, r)[l,\,r)(含 ll,不含 rr),纵坐标为 y=ky = k;
  • 2 l r:计算横坐标区间 [l, r)[l,\,r)(含 ll,不含 rr)的危险值。

输入格式

First line of input contains a single integer q (1 ≤ q ≤ 5·104) denoting the number of queries.

Next q lines each describe a query. Each query description first contains the query type type__i (1 ≤ type__i ≤ 2). This is followed by further description of the query. In case of the type being 1, it is followed by integers l__i, r__i and k__i (,  - 109 ≤ k__i ≤ 109, k ≠ 0). Otherwise, it just contains two integers, l__i and r__i (1 ≤ l__i < r__i ≤ 105).

输入的第一行包含一个整数 $ q (( 1 \leq q \leq 5 \cdot 10^4 $),表示查询次数。

接下来的 $ q $ 行每行描述一次查询。每次查询首先给出查询类型 $ \text{type}_i (( 1 \leq \text{type}_i \leq 2 $),随后是该查询的进一步描述。若查询类型为 1,则其后跟三个整数 $ l_i 、、 r_i $ 和 $ k_i (![](https://pms−wscdn.xmwol.com/image/2baddde172354bdc9c392e65cd8d7409.png),(![](https://pms-wscdn.xmwol.com/image/2baddde172354bdc9c392e65cd8d7409.png), -10^9 \leq k_i \leq 10^9 $,且 $ k_i \neq 0 $);否则(即查询类型为 2),仅包含两个整数 $ l_i $ 和 $ r_i (( 1 \leq l_i < r_i \leq 10^5 $)。

输出格式

Output the answer for each query of type 2 in a separate line.

对每个类型为 2 的查询,分别在单独一行中输出答案。

输入输出样例

  • 输入#1

    3
    1 1 10 10
    1 2 4 -7
    2 1 10

    输出#1

    34
  • 输入#2

    7
    1 2 3 5
    1 1 10 10
    1 4 5 -5
    2 4 8
    1 1 10 -10
    2 4 8
    2 1 10

    输出#2

    15
    75
    170

说明/提示

In the first sample case, the danger value for x-coordinates 1 is 0 as there is no _y_2 satisfying the above condition for x = 1.

Danger values for x-coordinates 2 and 3 is 10 + | - 7| = 17.

Danger values for x-coordinates 4 to 9 is again 0 as there is no _y_2 satisfying the above condition for these coordinates.

Thus, total danger value is 17 + 17 = 34.

在第一个样例中,当 xx 坐标为 1 时,危险值为 0,因为对于 x=1x = 1,不存在满足上述条件的 y2y_2。

当 xx 坐标为 2 和 3 时,危险值为 10+∣−7∣=1710 + |-7| = 17。

当 xx 坐标为 4 至 9 时,危险值再次为 0,因为对于这些坐标,不存在满足上述条件的 y2y_2。

因此,总危险值为 17+17=3417 + 17 = 34。

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

首页