QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#21811 | #2831. Game Theory | hy_zheng_zai_nei_juan# | RE | 4ms | 9832kb | C++20 | 3.4kb | 2022-03-08 16:02:19 | 2022-05-08 04:06:12 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<sstream>
#include<cctype>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<set>
#include<functional>
#define in(x) x=read()
#define qr read()
#define int ll
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
namespace fastIO
{
#define BUF_SIZE 100000
bool IOerror=0;
inline char nc()
{
static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
if (p1==pend){
p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin);
if (pend==p1){IOerror=1;return -1;}
}
return *p1++;
}
inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';}
inline ll read()
{
bool sign=0; char ch=nc();ll x=0;
for (;blank(ch);ch=nc());
if (IOerror)return 0;
if (ch=='-')sign=1,ch=nc();
for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0';
if (sign)x=-x;
return x;
}
#undef BUF_SIZE
};
using namespace fastIO;
#define mod 998244353
#define fi first
#define se second
#define pii pair<int,int>
pii operator + (pii a,pii b){return mp(a.fi+b.fi,a.se+b.se);}
int s[1000010],c1[1000010],c2[1000010],col[1000010];
void pushup(int x){c1[x]=c1[x<<1]+c1[x<<1|1],c2[x]=c2[x<<1]+c2[x<<1|1];}
void build(int l,int r,int x)
{
col[x]=0;
if(l==r)
{
c1[x]=s[l];
if(s[l])c2[x]=l;
else c2[x]=0;
return;
}
int mid=(l+r)/2;
build(l,mid,x<<1);
build(mid+1,r,x<<1|1);
pushup(x);
// cout<<l<<" "<<r<<":"<<c1[x]<<','<<c2[x]<<'\n';
}
int sum(int l,int r){return (l+r)*(r-l+1)/2;}
void pushdown(int x,int nl,int nr)
{
if(col[x])
{
int mid=(nl+nr)/2;
c1[x<<1]=mid-nl+1-c1[x<<1];
c1[x<<1|1]=nr-mid-c1[x<<1|1];
c2[x<<1]=sum(nl,mid)-c2[x<<1];
c2[x<<1|1]=sum(mid+1,nr)-c2[x<<1|1];
col[x<<1]^=1,col[x<<1|1]^=1;
col[x]=0;
}
}
void modify(int nl,int nr,int l,int r,int x)
{
if(l<=nl&&nr<=r)
{
c1[x]=nr-nl+1-c1[x];
// cout<<nl<<' '<<nr<<":"<<c2[x]<<'\n';
c2[x]=sum(nl,nr)-c2[x];
// cout<<nl<<' '<<nr<<":"<<c2[x]<<'\n';
col[x]^=1;
return;
}
int mid=(nl+nr)/2;
pushdown(x,nl,nr);
if(l<=mid)modify(nl,mid,l,r,x<<1);
if(r>mid)modify(mid+1,nr,l,r,x<<1|1);
pushup(x);
}
pii query(int nl,int nr,int l,int r,int x)
{
if(l>r)return mp(-1,-1);
if(l<=nl&&nr<=r)return mp(c1[x],c2[x]);
int mid=(nl+nr)/2;
pushdown(x,nl,nr);
pii ans=mp(0,0);
if(l<=mid)ans=ans+query(nl,mid,l,r,x<<1);
if(r>mid)ans=ans+query(mid+1,nr,l,r,x<<1|1);
return ans;
}
signed main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int n,q;
while(n=qr,q=qr)
{
for(int i=1;i<=n;i++)s[i]=nc()-'0';
// for(int i=1;i<=n;i++)cout<<s[i]<<' ';cout<<'\n';
build(1,n,1);
for(int i=1;i<=q;i++)
{
int l=qr,r=qr;
modify(1,n,l,r,1);
int pos=c1[1],ans=0;
pii w=query(1,n,pos,pos,1);
pii v1=query(1,n,1,pos-1,1),v2=query(1,n,pos+1,n,1);
// cout<<v1.fi<<' '<<v1.se<<"\t"<<v2.fi<<' '<<v2.se<<'\n';
if(v1.fi!=-1)
{
int x=pos-1-v1.fi,s=sum(1,pos-1)-v1.se;
ans+=2*x*pos-2*s,ans%=mod;
}
if(v2.fi!=-1)
{
ans+=2*v2.se-2*v2.fi*pos,ans%=mod;
}
ans+=pos,ans%=mod;
cout<<ans<<'\n';
}
n=0,q=0;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 9832kb
input:
3 2 010 1 2 2 3 5 1 00000 1 5
output:
1 3 5
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 4ms
memory: 9608kb
input:
1 1 0 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Runtime Error
input:
2 2 01 2 2 2 2 2 2 01 1 2 1 2 1 2 1 1 1 1 1 1 2 1 1 1 1 1 2 2 00 1 2 1 2 2 2 11 1 2 1 2 2 2 01 2 2 1 1 2 2 10 2 2 1 2 2 2 01 1 2 1 2 1 2 0 1 1 1 1 2 2 01 1 2 2 2 1 2 0 1 1 1 1 1 2 1 1 1 1 1 2 2 10 1 2 1 1 1 2 0 1 1 1 1 2 2 01 1 2 1 2 2 2 10 1 2 1 1 1 2 0 1 1 1 1 1 2 0 1 1 1 1 1 2 1 1 1 1 1 2 2 10 1 ...