307546: CF1371F. Raging Thunder

Memory Limit:512 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Raging Thunder

题意翻译

有一条长度为 $n$ 的传送带链,它们的方向不尽相同,且从左到右编号为 $1, \dots, n$。相邻的两个传送带之间有缝隙,缝隙共有 $n+1$ 个,分别是编号为 $1$ 的传送带左边的一个(编号 $0$),相邻两个传送带之间的 $n-1$ 个(从左到右编号 $1, \dots, n-1$),编号为 $n$ 的传送带右边的一个(编号 $n$)。 当一个球放在一个传送带上,若这个传送带的方向上的第一个传送带与其同向,这个球将会被输送到方向上第一个传送带上。若不同向或其方向上没有传送带($1$ 向左,或 $n$ 向右),这个球会在这个传送带方向上的第一个缝隙掉下去。 现在有 $q$ 次操作,每次操作给出 $[l,r]$,你需要执行下面的任务: 1. 将编号在 $[l,r]$ 中的传送带全部反向; 2. 计算在编号在 $[l,r]$ 中的传送带上分别放一个球,最后掉入球最多的缝隙中将会有几个球。 每次回答完后这次操作的球立即消失,不计入下一个操作的询问。但是传送带方向将会保留。

题目描述

You are a warrior fighting against the machine god Thor. Thor challenge you to solve the following problem: There are $ n $ conveyors arranged in a line numbered with integers from $ 1 $ to $ n $ from left to right. Each conveyor has a symbol "<" or ">". The initial state of the conveyor $ i $ is equal to the $ i $ -th character of the string $ s $ . There are $ n+1 $ holes numbered with integers from $ 0 $ to $ n $ . The hole $ 0 $ is on the left side of the conveyor $ 1 $ , and for all $ i \geq 1 $ the hole $ i $ is on the right side of the conveyor $ i $ . When a ball is on the conveyor $ i $ , the ball moves by the next rules: If the symbol "<" is on the conveyor $ i $ , then: - If $ i=1 $ , the ball falls into the hole $ 0 $ . - If the symbol "<" is on the conveyor $ i-1 $ , the ball moves to the conveyor $ i-1 $ . - If the symbol ">" is on the conveyor $ i-1 $ , the ball falls into the hole $ i-1 $ . If the symbol ">" is on the conveyor $ i $ , then: - If $ i=n $ , the ball falls into the hole $ n $ . - If the symbol ">" is on the conveyor $ i+1 $ , the ball moves to the conveyor $ i+1 $ . - If the symbol "<" is on the conveyor $ i+1 $ , the ball falls into the hole $ i $ . You should answer next $ q $ queries, each query is defined by the pair of integers $ l, r $ ( $ 1 \leq l \leq r \leq n $ ): - First, for all conveyors $ l,l+1,...,r $ , the symbol "<" changes to ">" and vice versa. These changes remain for the next queries. - After that, put one ball on each conveyor $ l,l+1,...,r $ . Then, each ball falls into some hole. Find the maximum number of balls in one hole. After the query all balls disappear and don't considered in the next queries.

输入输出格式

输入格式


The first line contains two integers $ n $ , $ q $ ( $ 1 \le n \le 5 \times 10^5 , 1 \le q \le 10^5 $ ). The second line contains a string $ s $ of length $ n $ . It consists of characters "<" and ">". Next $ q $ lines contain the descriptions of the queries, $ i $ -th of them contains two integers $ l $ , $ r $ $ (1 \le l \le r \le n) $ , describing the $ i $ -th query.

输出格式


Print $ q $ lines, in the $ i $ -th of them print the answer to the $ i $ -th query.

输入输出样例

输入样例 #1

5 6
><>><
2 4
3 5
1 5
1 3
2 4
1 5

输出样例 #1

3
3
5
3
2
3

说明

- In the first query, the conveyors change to "&gt;&gt;&lt;&lt;&lt;". After that, put a ball on each conveyor $ \{2,3,4\} $ . All three balls fall into the hole $ 2 $ . So the answer is $ 3 $ . - In the second query, the conveyors change to "&gt;&gt;&gt;&gt;&gt;". After that, put a ball on each conveyor $ \{3,4,5\} $ . All three balls fall into the hole $ 5 $ . So the answer is $ 3 $ . - In the third query, the conveyors change to "&lt;&lt;&lt;&lt;&lt;". After that, put a ball on each conveyor $ \{1,2,3,4,5\} $ . All five balls fall into the hole $ 0 $ . So the answer is $ 5 $ . - In the fourth query, the conveyors change to "&gt;&gt;&gt;&lt;&lt;". After that, put a ball on each conveyor $ \{1,2,3\} $ . All three balls fall into the hole $ 3 $ . So the answer is $ 3 $ . - In the fifth query, the conveyors change to "&gt;&lt;&lt;&gt;&lt;". After that, put a ball on each conveyor $ \{2,3,4\} $ . Two balls fall into the hole $ 1 $ , and one ball falls into the hole $ 4 $ . So, the answer is $ 2 $ . - In the sixth query, the conveyors change to "&lt;&gt;&gt;&lt;&gt;". After that, put a ball on each conveyor $ \{1,2,3,4,5\} $ . Three balls fall into the hole $ 3 $ , one ball falls into the hole $ 0 $ and one ball falls into the hole $ 5 $ . So, the answer is $ 3 $ .

Input

题意翻译

有一条长度为 $n$ 的传送带链,它们的方向不尽相同,且从左到右编号为 $1, \dots, n$。相邻的两个传送带之间有缝隙,缝隙共有 $n+1$ 个,分别是编号为 $1$ 的传送带左边的一个(编号 $0$),相邻两个传送带之间的 $n-1$ 个(从左到右编号 $1, \dots, n-1$),编号为 $n$ 的传送带右边的一个(编号 $n$)。 当一个球放在一个传送带上,若这个传送带的方向上的第一个传送带与其同向,这个球将会被输送到方向上第一个传送带上。若不同向或其方向上没有传送带($1$ 向左,或 $n$ 向右),这个球会在这个传送带方向上的第一个缝隙掉下去。 现在有 $q$ 次操作,每次操作给出 $[l,r]$,你需要执行下面的任务: 1. 将编号在 $[l,r]$ 中的传送带全部反向; 2. 计算在编号在 $[l,r]$ 中的传送带上分别放一个球,最后掉入球最多的缝隙中将会有几个球。 每次回答完后这次操作的球立即消失,不计入下一个操作的询问。但是传送带方向将会保留。

加入题单

算法标签: