CF1572F.Stations

NOI/NOI+/CTSC

通过率:0%

时间限制:2.50s

内存限制:256MB

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:

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

In other words, the station in city ii can broadcast information to city jj if j≥ij \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 li≤j≤ril_i \le j \le r_i.

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

有 nn 座城市排成一行,编号从 11 到 nn。

这些城市将建造广播站。第 ii 座城市的广播站高度为 hih_i,覆盖范围为 wiw_i。该广播站可向城市 jj 发送信息,当且仅当满足以下条件:

  • i≤j≤wii \le j \le w_i,且
  • 对每个满足 i<k≤ji < k \le j 的 kk,均有 hk<hih_k < h_i。

换言之,第 ii 座城市的广播站可向城市 jj 发送信息,当且仅当 j≥ij \ge i、jj 在第 ii 座广播站的覆盖范围内,且在区间 [i,j][i, j](包含端点)内,第 ii 座城市的广播站严格最高。

初始时,对每座城市 ii,均有 hi=0h_i = 0 且 wi=iw_i = i。

随后将发生 qq 个事件。在第 ii 个事件中,以下两种操作之一将发生:

  • 城市 cic_i 将重建其广播站,使其高度成为所有广播站中严格最高者,同时将其覆盖范围设为 wci=giw_{c_i} = g_i;
  • 记 bjb_j 为能向城市 jj 发送信息的广播站数量。输出所有满足 li≤j≤ril_i \le j \le r_i 的 bjb_j 之和。

你的任务是响应所有事件,并对所有查询输出对应答案。

输入格式

The first line contains two integers nn and qq (1≤n,q≤2⋅1051 \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 (1≤ci≤gi≤n1 \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 (1≤li≤ri≤n1 \le l_i \le r_i \le n) follow — the range of cities in the query.

第一行包含两个整数 nn 和 qq(1≤n,q≤2⋅1051 \le n, q \le 2\cdot10^5)——分别为城市数量和事件数量。

接下来是 qq 行。第 ii 行以一个整数 pip_i(pi=1p_i = 1 或 pi=2p_i = 2)开头。

若 pi=1p_i = 1,表示将重建一座广播站。随后给出两个整数 cic_i 和 gig_i(1≤ci≤gi≤n1 \le c_i \le g_i \le n)——分别表示重建广播站的城市编号及其新的广播覆盖范围。

若 pi=2p_i = 2,表示一个查询。随后给出两个整数 lil_i 和 rir_i(1≤li≤ri≤n1 \le l_i \le r_i \le n)——表示该查询所涉及的城市范围。

输出格式

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

对于每个查询,在一行中输出给定区间内所有 bjb_j 的和。

输入输出样例

  • 输入#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].

在第一个测试用例中,只有车站 11 在重建前和重建后均能到达城市 11。

在第二个测试用例中,每次重建后,数组 bb 的状态如下:

  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]。

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

首页