QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#103862#2831. Game Theorygisfire#Compile Error//C++112.0kb2023-05-07 18:46:282023-05-07 18:46:40

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-07 18:46:40]
  • 评测
  • [2023-05-07 18:46:28]
  • 提交

answer

#include<bitsdc++.h>
#define LL long long
using namespace std;
const int N=2e5+9,mod=998244353;
int n,q;
int sum[N<<3][2],lazy[N<<3],o[N<<3];
char s[N];
int add(int x,int y)
{
	return (x+y)%mod;
}
void pushup(int x)
{
	o[x]=o[x<<1]+o[x<<1|1];
	sum[x][0]=add(sum[x<<1][0],sum[x<<1|1][0]);
	sum[x][1]=add(sum[x<<1][1],sum[x<<1|1][1]);
}
void build(int x,int l,int r)
{
	lazy[x]=0;
	if(l==r)
	{
		o[x]=(s[l]=='1');
		sum[x][(s[l]-'0')]=l;
		sum[x][(s[l]-'0')^1]=0;
		return;
	}
	int mid=(l+r)>>1;
	build(x<<1,l,mid);
	build(x<<1|1,mid+1,r);
	pushup(x);
}
void pushdown(int x,int l,int r)
{
	if(!lazy[x]) return;
	int mid=(l+r)>>1;
	o[x<<1]=mid-l+1-o[x<<1];
	o[x<<1|1]=r-mid-o[x<<1|1];
	swap(sum[x<<1][0],sum[x<<1][1]);
	swap(sum[x<<1|1][0],sum[x<<1|1][1]);
	lazy[x<<1]^=1;
	lazy[x<<1|1]^=1;
	lazy[x]=0;
}
void update(int x,int l,int r,int L,int R)
{
	if(L<=l&&r<=R)
	{
		swap(sum[x][0],sum[x][1]);
		o[x]=(r-l+1)-o[x];
		lazy[x]^=1;
		return;
	}
	pushdown(x,l,r);
	int mid=(l+r)>>1;
	if(mid>=L) update(x<<1,l,mid,L,R);
	if(mid+1<=R) update(x<<1|1,mid+1,r,L,R);
	pushup(x);
}
int findo(int x,int l,int r,int k)
{
	if(l==r) return o[x];
	pushdown(x,l,r);
	int mid=(l+r)>>1;
	if(k<=mid) return findo(x<<1,l,mid,k);
	else return findo(x<<1|1,mid+1,r,k);
}
int findsum(int x,int l,int r,int L,int R,int op)
{
	if(L<=l&&r<=R) return sum[x][op];
	pushdown(x,l,r);
	int mid=(l+r)>>1;
	LL res=0;
	if(mid>=L) res=add(res,findsum(x<<1,l,mid,L,R,op));
	if(mid+1<=R) res=add(res,findsum(x<<1|1,mid+1,r,L,R,op));
	return res;
}
void solve()
{
	cin>>s+1;
	build(1,1,n);
	while(q--)
	{
		int l,r;
		cin>>l>>r;
		update(1,1,n,l,r);
		int k=o[1];
		int flag=findo(1,1,n,k);
		LL ans=2ll*findsum(1,1,n,k,n,1)-2ll*findsum(1,1,n,1,k,0);
		if(flag) ans-=findsum(1,1,n,k,k,1);
		else ans+=findsum(1,1,n,k,k,0);
		cout<<(ans%mod+mod)%mod<<endl;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	while(cin>>n>>q) solve();
	return 0;
}

Details

answer.code:1:9: fatal error: bitsdc++.h: No such file or directory
    1 | #include<bitsdc++.h>
      |         ^~~~~~~~~~~~
compilation terminated.