CF1572F.Stations

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

There are nn cities in a row numbered from 11 to nn .

The cities will be building broadcasting stations. The station in the ii -th city has height hih_i and range wiw_i . It can broadcast information to city jj if the following constraints are met:

  • ijwii \le j \le w_i , and
  • for each kk such that i<kji < k \le j , the following condition holds: hk<hih_k < h_i .

In other words, the station in city ii can broadcast information to city jj if jij \ge i , jj is in the range of ii -th station, and ii is strictly highest on the range from ii to jj (including city jj ).At the beginning, for every city ii , hi=0h_i = 0 and wi=iw_i = i .

Then qq events will take place. During ii -th event one of the following will happen:

  • City cic_i will rebuild its station so that its height will be strictly highest among all stations and wciw_{c_i} will be set to gig_i .
  • Let bjb_j be the number of stations that can broadcast information to city jj . Print the sum of bjb_j over all jj satisfying lijril_i \le j \le r_i .

Your task is to react to all events and print answers to all queries.

输入格式

The first line contains two integers nn and qq ( 1n,q21051 \le n, q \le 2\cdot10^5 ) — number of cities and number of events.

Then qq lines follow. The ii -th line begins with an integer pip_i ( pi=1p_i = 1 or pi=2p_i = 2 ).

If pi=1p_i = 1 a station will be rebuilt. Then two integers cic_i and gig_i ( 1cigin1 \le c_i \le g_i \le n ) follow — the city in which the station is rebuilt and its new broadcasting range.

If pi=2p_i = 2 you are given a query. Then two integers lil_i and rir_i ( 1lirin1 \le l_i \le r_i \le n ) follow — the range of cities in the query.

输出格式

For each query, print in a single line the sum of bjb_j over the given interval.

输入输出样例

  • 输入#1

    1 3
    2 1 1
    1 1 1
    2 1 1

    输出#1

    1
    1
  • 输入#2

    5 10
    1 3 4
    2 3 5
    1 1 5
    2 1 5
    1 4 5
    2 2 4
    1 2 3
    2 1 3
    1 5 5
    2 2 5

    输出#2

    4
    10
    5
    4
    5

说明/提示

In the first test case, only station 11 reaches city 11 before and after it is rebuilt.

In the second test case, after each rebuild, the array bb looks as follows:

  1. [1,1,1,2,1][1, 1, 1, 2, 1] ;
  2. [1,2,2,3,2][1, 2, 2, 3, 2] ;
  3. [1,2,2,1,2][1, 2, 2, 1, 2] ;
  4. [1,1,2,1,2][1, 1, 2, 1, 2] ;
  5. [1,1,2,1,1][1, 1, 2, 1, 1] .
首页