Codeforces Round #616 (Div. 2) D. Irreducible Anagrams

Title Source: the Click
Here Insert Picture Description
Q substring of a string can split into a string of not the case.

First slowly to analyze the topic:
in fact, we must make it a no-strings at least re-constitute the same prefix.
1. When l == r when simply can not split two is definitely Yes.
2. If only one string of words is clearly No. (Here, excluding the case where l = r)
further Consideration: s and t, at the beginning and end of the same can not be fixed, self-contained once the same section other characters. Here Insert Picture Description
See, for example, in s [i] t it is in the future to find a scratch with the same corresponding thereto and not before the paired. From s [0] Start, with t s [0] should try to put back the same, so that it can not mess interleaved paired s and t, a lot of longitudinal lines to the end of t, need to be wired between the this ensures that out.
3. You can know, the same as when only two strings when the head and tail must be No.
4. When there are three or more may be necessary.

#include <bits/stdc++.h>
#define MAX_len 50100*4
using namespace std;
typedef long long ll;
char s[200100];
int dp[200100][26]={0};
int main()
{
    s[0]='a';
    scanf("%s",s+1);
    int len=strlen(s);
    len--;
    for(int i=1;i<=len;i++)
    {
        for(int j=0;j<26;j++)
            dp[i][j]=dp[i-1][j];
        dp[i][s[i]-'a']++;
    }
    int q;
    cin>>q;
    while(q--)
    {
        int l,r;
        scanf("%d %d",&l,&r);
        if(l==r)
        {
            printf("Yes\n");
            continue;
        }
        int cnt=0;
        for(int i=0;i<26;i++)
        {
            if(dp[r][i]-dp[l-1][i]>0)
                cnt++;
        }
        if(cnt==1||(s[l]==s[r]&&cnt==2))
        {
            printf("No\n");
            continue;
        }
        {
            printf("Yes\n");
            continue;
        }

    }
    return 0;
}

Published 72 original articles · won praise 19 · views 7507

Guess you like

Origin blog.csdn.net/weixin_43958964/article/details/104224289