zoukankan      html  css  js  c++  java
  • NITACMOJ144稳定串


    点我》》题目链接

    稳定串

    Time Limit: 1000ms
    Memory Limit: 65536KB
    64-bit integer IO format: %lld      Java class name: Main
    Type:   
    一个字符串被称为稳定串当且仅当它包含的字母出现的次数全是偶数次。现在小王遇到一个难题,他手中有一个字符长度不大于10W的字符串,你能帮助他判断是否为稳定串吗?

    Input

    首先输入一个t,代表t组数据,每组数据输入一个字符串s(1≤strlen(s)≤105,仅包含小写字母和大写字母),之后再输入一个m,代表着m次询问,每次询问输入两个数l,r,代表以l位置开头r位置结尾的字符串。(1≤m≤105,1≤l≤r≤105)。

    Output

    对于每次询问,如果该串是稳定串,输出"Yes",否则输出"No"。

    Sample Input

    2
    aaaabbbb
    2
    1 8
    1 7
    aaAA
    2
    1 4
    2 3

    Sample Output

    Yes
    No
    Yes
    No

    Source

    Author

    skymiange


    不错哟~
    卡掉了前缀和;
    然后各种方法?
    QAQ:
     比如子树的字母能不能凑成一个回文,树上的链能不能打乱凑一个回文。

    这里就是利用二进制的异或和奇偶对应起来搞;

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    
    const int N=1e5+10;
    map<int,LL>mp;
    LL f[55];
    
    char str[N];
    LL vis[N];
    int sum[N];
    
    void init()
    {
        f[0]=1;
        for(LL i=1;i<=52;i++)
            f[i]=f[i-1]*2;
        int num=0;
        for(int i='a';i<='z';i++)
            mp[i]=f[num++];
        for(int i='A';i<='Z';i++)
            mp[i]=f[num++];
    }
    
    int main()
    {
        init();
        int T,len;
        scanf("%d",&T);
        while(T--)
        {
            scanf("%s",str+1);
            len=strlen(str+1);
            LL temp=0;
            vis[0]=0;
            for(int i=1;i<=len;i++)
            {
                temp=temp^mp[str[i]];
                vis[i]=temp;
            }
    
            int Q,u,v;
            scanf("%d",&Q);
            while(Q--)
            {
                scanf("%d%d",&u,&v);
                if(u>v)
                    swap(u,v);
                if(vis[v]==vis[u-1])
                    puts("Yes");
                else
                    puts("No");
            }
        }
        return 0;
    }
    
    
    

  • 相关阅读:
    luogu P1075 质因数分解
    luogu P1146 硬币翻转
    [HEOI2013]SAO
    [HAOI2010]软件安装
    [CodeForces-763C]Timofey and remoduling
    [CodeForces-375E]Red and Black Tree
    [CodeForces-178F]Representative Sampling
    [CodeForces-55D]Beautiful Numbers
    [AHOI2009]同类分布
    [ZJOI2010]数字计数
  • 原文地址:https://www.cnblogs.com/keyboarder-zsq/p/6777523.html
Copyright © 2011-2022 走看看