Codeforces——914F Substrings in a String

大致题意:给一个字符串str,再给n次操作,其中1操作是改变str中pos位置的字符,2操作是查询 [l,r] 中字符串s出现的次数。第一次用bitset,感觉真是个好东西。真好用。

洛谷上面有人写了题解,但是没有写的很具体,所以从来没写过bitset的我就只能一直猜他代码的意思,花了一点时间才搞懂了bitset,其实就是先暴力统计每种字符的位置,然后再用一个temp(bitset类型)去统计每次要查询的字符串。就是代码中 位运算的部分。那里就是整道题的精髓了。

最后,代码:(有空我再用其他方法把他过了)。

 

#include
using namespace std;
bitset<101000>bitset1[27],temp;
int main()
{
    int n;
    string str;
    string s;
    cin>>str;
    for(int i=0;i>n;
    int opt;
    int pos;
    int l,r;
    char ch;
    for(int i=0;i>opt;
        if(opt==1)
        {
            cin>>pos>>ch;
            bitset1[str[pos-1]-'a'][pos-1]=0;
            bitset1[ch-'a'][pos-1]=1;
            str[pos-1]=ch;
        }
        else
        {
            cin>>l>>r>>s;
            temp.set();
            for(int j=0;j>j);
            }
            int Left=(temp>>l-1).count();
            
            int Right=(temp>>r-s.size()+1).count();
            if(Left(r-l+1)的时候,如果没有这句话,那么就会有错误
            cout<

 

你可能感兴趣的:(字符串)