不会bitset求助
查看原帖
不会bitset求助
315205
Kniqht楼主2023/11/15 09:15

应该就是加注释的地方的问题,因为这里改成题解的就过了。但是问题是我不理解题解的位移,而且我觉得这个好像没问题啊(虽然肯定是有问题的

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,q;
char s[N],b[N];
bitset<N> a[26],ans;
signed main(){
	scanf("%s",s);
	n=strlen(s);
	scanf("%d",&q);
	for(int i=0;i<n;i++) a[s[i]-'a'].flip(i);
	int op,l,r;
	char y[4];
	while(q--){
		scanf("%d%d",&op,&l);
		if(op==1){
			scanf("%s",y);
			a[s[l-1]-'a'].flip(l-1);
			s[l-1]=*y;
			a[*y-'a'].flip(l-1);
		}
		else{
			scanf("%d%s",&r,b);
			int len=strlen(b);ans.set();
			if(len>r-l+1){
				printf("0\n");
				continue;
			}
			for(int i=0;i<len;i++) ans&=(a[b[i]-'a']>>i);
			printf("%d\n",(ans>>l-1).count()-(ans>>l+len-1).count());
          //就是这里,左移l-1位 - 左移 l-1+len 位(bitset左右移反的
         
		}
	} 
	return 0;
}

题解的写法: cout<<(ans>>l).count()-(ans>>(r-n+2)).count()<<'\n'; 理解不了这是什么意思

2023/11/15 09:15
加载中...