啊我爆零了,求助!
查看原帖
啊我爆零了,求助!
556895
Holder_Lee楼主2022/1/22 21:16
#include "cstdio"
#include "iostream"
typedef unsigned U;
typedef long long LL;
#define CH getchar()
#define INL inline
const int N_=500005;
const int M_=1000000007;
using namespace std;
const int pow_2[31]={0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912}; 
bool a[N_];
int sum[N_];

INL int read(){char c=CH;int s=0,k=1;while (!isdigit(c)){if (c=='-')k=-1;c=CH;}while (isdigit(c)){s=s*10+c-'0';c=CH;}return s*k;}

INL int lowbit(int x)
{
	int bitnum=1;
	while(!(x&1))
	{
		x>>=1;
		bitnum<<=1;
	}
	return bitnum;
}

INL int highbit(int x)
{
	int i=0;
	while(pow_2[i++]<=x);
	return pow_2[i-2];
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen ("B.in","r",stdin);
	freopen ("B.out","w",stdout);
	#endif
	int n=read(),q=read();
	char c=CH;
	if (c-'0')
	{
		a[1]=1;
	}
	for(int i=2;i<=n;++i)
	{
		char c=CH;
		if (c-'0')
		{
			a[i]=1;
		}
	}
	for(int i=1,l,r,x;i<=q;++i)
	{
		l=read();r=read();x=read();
		for(int j=l;j<=r;++j)
		{
			if(a[j])
			{
				x+=highbit(x);
			}
			else
			{
				x+=lowbit(x);
			}
			x%=M_;
		}
		printf("%d\n",x);
	}
	return 0;
}
2022/1/22 21:16
加载中...