CF855F.Nagini

普及/提高-

通过率:0%

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 11 to 10510^{5} . Nagini is launching various snakes at the Hogwarts entrance. Each snake lands parallel to the entrance, covering a segment at a distance kk from x=lx=l to x=rx=r . Formally, each snake can be imagined as being a line segment between points (l,k)(l,k) and (r,k)(r,k) . Note that kk can be both positive and negative, but not 00 .

Let, at some xx -coordinate x=ix=i , there be snakes at point (i,y1)(i,y_{1}) and point (i,y2)(i,y_{2}) , such that y_{1}>0 and y_{2}<0 . Then, if for any point (i,y3)(i,y_{3}) containing a snake such that y_{3}>0 , y1<=y3y_{1}<=y_{3} holds and for any point (i,y4)(i,y_{4}) containing a snake such that y_{4}<0 , y2<=y4|y_{2}|<=|y_{4}| holds, then the danger value at coordinate x=ix=i is y1+y2y_{1}+|y_{2}| . If no such y1y_{1} and y2y_{2} exist, danger value is 00 .

Harry wants to calculate the danger value of various segments of the Hogwarts entrance. Danger value for a segment [l,r)[l,r) of the entrance can be calculated by taking the sum of danger values for each integer xx -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=lx=l to x=rx=r at y-coordinate y=ky=k ( ll inclusive, rr exclusive).
  • 2 l r: you have to calculate the danger value of segment ll to rr ( ll inclusive, rr exclusive).

输入格式

First line of input contains a single integer qq ( 1<=q<=51041<=q<=5·10^{4} ) denoting the number of queries.

Next qq lines each describe a query. Each query description first contains the query type typeitype_{i} ( 1<=typei<=21<=type_{i}<=2 ). This is followed by further description of the query. In case of the type being 11 , it is followed by integers li,ril_{i},r_{i} and kik_{i} (, 109<=ki<=109-10^{9}<=k_{i}<=10^{9} , k0k≠0 ). Otherwise, it just contains two integers, lil_{i} and rir_{i} ( 1<=l_{i}<r_{i}<=10^{5} ).

输出格式

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

输入输出样例

  • 输入#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 xx -coordinates 11 is 00 as there is no y2y_{2} satisfying the above condition for x=1x=1 .

Danger values for xx -coordinates 22 and 33 is 10+7=1710+|-7|=17 .

Danger values for xx -coordinates 44 to 99 is again 00 as there is no y2y_{2} satisfying the above condition for these coordinates.

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

首页