Codeforces Round 743 (Div. 1)
F
Stations
Codeforces
3400
原题
← E→
翻译中…

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 $h_i$ and range $w_i$. It can broadcast information to city $j$ if the following constraints are met:

翻译中…
  • $i \le j \le w_i$, and
  • for each $k$ such that $i \lt k \le j$, the following condition holds: $h_k \lt h_i$.
翻译中…

In other words, the station in city $i$ can broadcast information to city $j$ if $j \ge 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$, $h_i = 0$ and $w_i = i$.

翻译中…

Then $q$ events will take place. During $i$-th event one of the following will happen:

翻译中…
  • City $c_i$ will rebuild its station so that its height will be strictly highest among all stations and $w_{c_i}$ will be set to $g_i$.
  • Let $b_j$ be the number of stations that can broadcast information to city $j$. Print the sum of $b_j$ over all $j$ satisfying $l_i \le j \le r_i$.
翻译中…

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

翻译中…

Input

翻译中…

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

翻译中…

Then $q$ lines follow. The $i$-th line begins with an integer $p_i$ ($p_i = 1$ or $p_i = 2$).

翻译中…

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

翻译中…

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

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

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, 1, 2, 1]$;
  2. $[1, 2, 2, 3, 2]$;
  3. $[1, 2, 2, 1, 2]$;
  4. $[1, 1, 2, 1, 2]$;
  5. $[1, 1, 2, 1, 1]$.
翻译中…

样例

Input #1
1 3
2 1 1
1 1 1
2 1 1
Output #1
1
1
InputCopy OutputCopy
Input #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
Output #2
4
10
5
4
5
InputCopy OutputCopy
题目信息
题号
1572F
时间限制
2.5 s
内存限制
256 MB
标签
数据结构

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。