A9189 | Sereja and Algorithm
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Sereja loves all sorts of algorithms. He has recently come up with a new algorithm, which receives a string as an input. Let's represent the input string of the algorithm as $q=q_{1}q_{2}...\ q_{k}$ . The algorithm consists of two steps:
1. Find any continuous subsequence (substring) of three characters of string $q$ , which doesn't equal to either string "zyx", "xzy", "yxz". If $q$ doesn't contain any such subsequence, terminate the algorithm, otherwise go to step 2.
2. Rearrange the letters of the found subsequence randomly and go to step 1.
Sereja thinks that the algorithm works correctly on string $q$ if there is a non-zero probability that the algorithm will be terminated. But if the algorithm anyway will work for infinitely long on a string, then we consider the algorithm to work incorrectly on this string.
Sereja wants to test his algorithm. For that, he has string $s=s_{1}s_{2}...\ s_{n}$ , consisting of $n$ characters. The boy conducts a series of $m$ tests. As the $i$ -th test, he sends substring $s_{li}s_{li}+1...\ s_{ri}$ $(1<=l_{i}<=r_{i}<=n)$ to the algorithm input. Unfortunately, the implementation of his algorithm works too long, so Sereja asked you to help. For each test $(l_{i},r_{i})$ determine if the algorithm works correctly on this test or not.
1. Find any continuous subsequence (substring) of three characters of string $q$ , which doesn't equal to either string "zyx", "xzy", "yxz". If $q$ doesn't contain any such subsequence, terminate the algorithm, otherwise go to step 2.
2. Rearrange the letters of the found subsequence randomly and go to step 1.
Sereja thinks that the algorithm works correctly on string $q$ if there is a non-zero probability that the algorithm will be terminated. But if the algorithm anyway will work for infinitely long on a string, then we consider the algorithm to work incorrectly on this string.
Sereja wants to test his algorithm. For that, he has string $s=s_{1}s_{2}...\ s_{n}$ , consisting of $n$ characters. The boy conducts a series of $m$ tests. As the $i$ -th test, he sends substring $s_{li}s_{li}+1...\ s_{ri}$ $(1<=l_{i}<=r_{i}<=n)$ to the algorithm input. Unfortunately, the implementation of his algorithm works too long, so Sereja asked you to help. For each test $(l_{i},r_{i})$ determine if the algorithm works correctly on this test or not.
输入格式
The first line contains non-empty string $s$ , its length ( $n$ ) doesn't exceed $10^{5}$ . It is guaranteed that string $s$ only contains characters: 'x', 'y', 'z'.
The second line contains integer $m$ $(1<=m<=10^{5})$ — the number of tests. Next $m$ lines contain the tests. The $i$ -th line contains a pair of integers $l_{i}$ , $r_{i}$ $(1<=l_{i}<=r_{i}<=n)$ .
The second line contains integer $m$ $(1<=m<=10^{5})$ — the number of tests. Next $m$ lines contain the tests. The $i$ -th line contains a pair of integers $l_{i}$ , $r_{i}$ $(1<=l_{i}<=r_{i}<=n)$ .
输出格式
For each test, print "YES" (without the quotes) if the algorithm works correctly on the corresponding test and "NO" (without the quotes) otherwise.
输入输出样例
输入 #1
zyxxxxxxyyz 5 5 5 1 3 1 11 1 4 3 6
输出 #1
YES YES NO YES NO
In the first example, in test one and two the algorithm will always be terminated in one step. In the fourth test you can get string "xzyx" on which the algorithm will terminate. In all other tests the algorithm doesn't work correctly.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted