A11281 | Pinball
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There is a one-dimensional grid of length $n$ . The $i$ -th cell of the grid contains a character $s_i$ , which is either '<' or '>'.
When a pinball is placed on one of the cells, it moves according to the following rules:
- If the pinball is on the $i$ -th cell and $s_i$ is '<', the pinball moves one cell to the left in the next second. If $s_i$ is '>', it moves one cell to the right.
- After the pinball has moved, the character $s_i$ is inverted (i. e. if $s_i$ used to be '<', it becomes '>', and vice versa).
- The pinball stops moving when it leaves the grid: either from the left border or from the right one.
You need to answer $n$ independent queries. In the $i$ -th query, a pinball will be placed on the $i$ -th cell. Note that we always place a pinball on the initial grid.
For each query, calculate how many seconds it takes the pinball to leave the grid. It can be shown that the pinball will always leave the grid within a finite number of steps.
When a pinball is placed on one of the cells, it moves according to the following rules:
- If the pinball is on the $i$ -th cell and $s_i$ is '<', the pinball moves one cell to the left in the next second. If $s_i$ is '>', it moves one cell to the right.
- After the pinball has moved, the character $s_i$ is inverted (i. e. if $s_i$ used to be '<', it becomes '>', and vice versa).
- The pinball stops moving when it leaves the grid: either from the left border or from the right one.
You need to answer $n$ independent queries. In the $i$ -th query, a pinball will be placed on the $i$ -th cell. Note that we always place a pinball on the initial grid.
For each query, calculate how many seconds it takes the pinball to leave the grid. It can be shown that the pinball will always leave the grid within a finite number of steps.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $t$ ( $1 \le t \le 10^5$ ). The description of the test cases follows.
The first line of each test case contains an integer $n$ ( $1 \le n \le 5 \cdot 10^5$ ).
The second line of each test case contains a string $s_1s_2 \ldots s_{n}$ of length $n$ consisting of characters '<' and '>'.
It is guaranteed that the sum of $n$ over all test cases does not exceed $5 \cdot 10^5$ .
The first line of each test case contains an integer $n$ ( $1 \le n \le 5 \cdot 10^5$ ).
The second line of each test case contains a string $s_1s_2 \ldots s_{n}$ of length $n$ consisting of characters '<' and '>'.
It is guaranteed that the sum of $n$ over all test cases does not exceed $5 \cdot 10^5$ .
输出格式
For each test case, for each $i$ ( $1 \le i \le n$ ) output the answer if a pinball is initially placed on the $i$ -th cell.
输入输出样例
输入 #1
3 3 ><< 4 <<<< 6 <><<<>
输出 #1
3 6 5 1 2 3 4 1 4 7 10 8 1
In the first test case, the movement of the pinball for $i=1$ is shown in the following pictures. It takes the pinball $3$ seconds to leave the grid.
The movement of the pinball for $i=2$ is shown in the following pictures. It takes the pinball $6$ seconds to leave the grid.

The movement of the pinball for $i=2$ is shown in the following pictures. It takes the pinball $6$ seconds to leave the grid.

C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted