CF1572F.Stations
NOI/NOI+/CTSC
通过率:0%
时间限制:2.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n cities in a row numbered from 1 to n.
The cities will be building broadcasting stations. The station in the i-th city has height hi and range wi. It can broadcast information to city j if the following constraints are met:
- i≤j≤wi, and
- for each k such that i<k≤j, the following condition holds: hk<hi.
In other words, the station in city i can broadcast information to city j if j≥i, j is in the range of i-th station, and i is strictly highest on the range from i to j (including city j).
At the beginning, for every city i, hi=0 and wi=i.
Then q events will take place. During i-th event one of the following will happen:
- City ci will rebuild its station so that its height will be strictly highest among all stations and wci will be set to gi.
- Let bj be the number of stations that can broadcast information to city j. Print the sum of bj over all j satisfying li≤j≤ri.
Your task is to react to all events and print answers to all queries.
有 n 座城市排成一行,编号从 1 到 n。
这些城市将建造广播站。第 i 座城市的广播站高度为 hi,覆盖范围为 wi。该广播站可向城市 j 发送信息,当且仅当满足以下条件:
- i≤j≤wi,且
- 对每个满足 i<k≤j 的 k,均有 hk<hi。
换言之,第 i 座城市的广播站可向城市 j 发送信息,当且仅当 j≥i、j 在第 i 座广播站的覆盖范围内,且在区间 [i,j](包含端点)内,第 i 座城市的广播站严格最高。
初始时,对每座城市 i,均有 hi=0 且 wi=i。
随后将发生 q 个事件。在第 i 个事件中,以下两种操作之一将发生:
- 城市 ci 将重建其广播站,使其高度成为所有广播站中严格最高者,同时将其覆盖范围设为 wci=gi;
- 记 bj 为能向城市 j 发送信息的广播站数量。输出所有满足 li≤j≤ri 的 bj 之和。
你的任务是响应所有事件,并对所有查询输出对应答案。
输入格式
The first line contains two integers n and q (1≤n,q≤2⋅105) — number of cities and number of events.
Then q lines follow. The i-th line begins with an integer pi (pi=1 or pi=2).
If pi=1 a station will be rebuilt. Then two integers ci and gi (1≤ci≤gi≤n) follow — the city in which the station is rebuilt and its new broadcasting range.
If pi=2 you are given a query. Then two integers li and ri (1≤li≤ri≤n) follow — the range of cities in the query.
第一行包含两个整数 n 和 q(1≤n,q≤2⋅105)——分别为城市数量和事件数量。
接下来是 q 行。第 i 行以一个整数 pi(pi=1 或 pi=2)开头。
若 pi=1,表示将重建一座广播站。随后给出两个整数 ci 和 gi(1≤ci≤gi≤n)——分别表示重建广播站的城市编号及其新的广播覆盖范围。
若 pi=2,表示一个查询。随后给出两个整数 li 和 ri(1≤li≤ri≤n)——表示该查询所涉及的城市范围。
输出格式
For each query, print in a single line the sum of bj over the given interval.
对于每个查询,在一行中输出给定区间内所有 bj 的和。
输入输出样例
输入#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 1 reaches city 1 before and after it is rebuilt.
In the second test case, after each rebuild, the array b looks as follows:
- [1,1,1,2,1];
- [1,2,2,3,2];
- [1,2,2,1,2];
- [1,1,2,1,2];
- [1,1,2,1,1].
在第一个测试用例中,只有车站 1 在重建前和重建后均能到达城市 1。
在第二个测试用例中,每次重建后,数组 b 的状态如下:
- [1,1,1,2,1];
- [1,2,2,3,2];
- [1,2,2,1,2];
- [1,1,2,1,2];
- [1,1,2,1,1]。
输入解题思路,AI测评打分。不知道怎么写?