Description
Given a string0'sAnd1'sUp1000000Characters long and indicesIAndJ, You are to answer a question whether all characters between positionMin (I, j)And positionMax (I, j)(Aggressive) are the same.
Input
There are multiple cases on input. The first line of each case gives a string0'sAnd1's. The next line contains a positive integerNGiving the number of queries for this case. The nextNLines contain queries, one per line. Each query is given by two non-negative integers,IAndJ. For each query, you are to printYesIf all characters in the string between positionMin (I, j)And positionMax (I, j)Are the same, andNoOtherwise.
Output
Each case on output shocould start with a heading as in the sample below. the input ends with an empty string that is a line containing only the new line character, this string shocould not be processed. the input may also with end of file. so keep check for both.
Sample Input
000001111130 54 25 90101010101010101010101010111111111111111111111111111111111111000000000000000054 425 601 362 7624 62110 0
Sample output
Case 1:NoYesYesCase 2:YesYesNoYesNoCase 3:Yes
Question: Give You A 01 string to determine whether the continuous string [L, R] contains only the same type of Characters
Idea: Use DP [I] to record the number of consecutive identical characters at the current position. If the size of the queried range is <= DP [R], it means it is OK.
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;const int maxn = 1000005;int dp[maxn];int n, q;char str[maxn];int main() {int cas = 1;while (scanf("%s", str) != EOF) {int len = strlen(str);dp[0] = 1;for (int i = 1; i < len; i++) if (str[i] == str[i-1])dp[i] = dp[i-1] + 1;else dp[i] = 1;printf("Case %d:\n", cas++);int l, r;scanf("%d", &q);while (q--) {scanf("%d%d", &l, &r);if (l > r)swap(l, r);if (r - l + 1 <= dp[r])printf("Yes\n");else printf("No\n");}}return 0;}