A16105 | Fast Travel Text Editor
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a string $s$ , consisting of lowercase Latin letters.
There's a cursor, initially placed between two adjacent letters of the string. The cursor can't be placed before the first or after the last letter.
In one move, you can perform one of three actions:
- move a cursor one position to the left (if that doesn't place it before the first letter);
- move a cursor one position to the right (if that doesn't place it after the last letter);
- let $x$ be the letter immediately to the left of the cursor, and $y$ be the letter immediately to the right of the cursor. Choose any pair of adjacent letters in the string such that the left of them is $x$ and the right of them is $y$ , and move the cursor to the position between these two letters.
You are asked $m$ queries. In each query, you are given two integers $f$ and $t$ , which correspond to two valid positions of the cursor in the string. In response to the query, you have to calculate the minimum number of operations required to move the cursor from position $f$ to position $t$ .
There's a cursor, initially placed between two adjacent letters of the string. The cursor can't be placed before the first or after the last letter.
In one move, you can perform one of three actions:
- move a cursor one position to the left (if that doesn't place it before the first letter);
- move a cursor one position to the right (if that doesn't place it after the last letter);
- let $x$ be the letter immediately to the left of the cursor, and $y$ be the letter immediately to the right of the cursor. Choose any pair of adjacent letters in the string such that the left of them is $x$ and the right of them is $y$ , and move the cursor to the position between these two letters.
You are asked $m$ queries. In each query, you are given two integers $f$ and $t$ , which correspond to two valid positions of the cursor in the string. In response to the query, you have to calculate the minimum number of operations required to move the cursor from position $f$ to position $t$ .
输入格式
The first line contains a string $s$ ( $2 \le |s| \le 5 \cdot 10^4$ ), consisting of lowercase Latin letters.
The second line contains a single integer $m$ ( $1 \le m \le 5 \cdot 10^4$ ) — the number of queries.
The $i$ -th of the next $m$ lines contains two integers $f$ and $t$ ( $1 \le f, t \le |s| - 1$ ) — the initial and the target positions of the cursor in the $i$ -th query. Position $x$ means that the cursor is between the $x$ -th and the $(x+1)$ -st letters of the string ( $1$ -indexed).
The second line contains a single integer $m$ ( $1 \le m \le 5 \cdot 10^4$ ) — the number of queries.
The $i$ -th of the next $m$ lines contains two integers $f$ and $t$ ( $1 \le f, t \le |s| - 1$ ) — the initial and the target positions of the cursor in the $i$ -th query. Position $x$ means that the cursor is between the $x$ -th and the $(x+1)$ -st letters of the string ( $1$ -indexed).
输出格式
For each query, print the minimum number of actions required to move the cursor from position $f$ to position $t$ .
输入输出样例
输入 #1
codecode 3 1 7 3 5 3 6
输出 #1
3 2 2
输入 #2
abcdefghij 3 1 9 9 1 5 5
输出 #2
8 8 0
输入 #3
aaaaaaaaaaaa 4 10 8 3 7 6 1 11 11
输出 #3
1 1 1 0
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted