QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#21856 | #2831. Game Theory | 1145141919810# | TL | 4ms | 7848kb | C++14 | 4.4kb | 2022-03-08 16:58:06 | 2022-05-08 04:10:07 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<queue>
#include<vector>
#include<map>
#include<bitset>
#include<set>
#include<cmath>
#include<ctime>
#include<random>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define bc(x) __builtin_popcount(x)
#define re register
#define il inline
#define pii pair<int,int>
#define pil pair<int,long long>
#define pll pair<long long,long long>
#define mem0(x) memset(x,0,sizeof(x))
#define mem0x3f(x) memset(x,0x3f,sizeof(x))
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n';
// #pragma GCC optimize(3)
#define int long long
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
namespace IO_BUFF{
mt19937 rnd(time(0)^(ll)(new char));
int rend(int x){
return rnd()%x+1;
}
void rendom_shuffle(int *a,int len){
shuffle(a+1,a+len+1,rnd);
}
const int BS=(1<<24)+5;char Buffer[BS],*HD,*TL;
inline int gc(){
if(HD==TL) TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);
return (HD==TL)?EOF:*HD++;
}
inline int inn(){
int x,ch,s=1;while((ch=gc())<'0'||ch>'9')if(ch=='-')s=-1;x=ch^'0';
while((ch=gc())>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^'0');return x*s;
}
char ssss[19999999],tttt[20];int ssl,ttl;
inline int print(int x)
{
if(x<0)ssss[++ssl]='-',x=(-x);
if(!x) ssss[++ssl]='0';for(ttl=0;x;x/=10) tttt[++ttl]=char(x%10+'0');
for(;ttl;ttl--) ssss[++ssl]=tttt[ttl];return ssss[++ssl]='\n';
}
inline int Flush(){return fwrite(ssss+1,sizeof(char),ssl,stdout),ssl=0,0;}
int read(){
char c=getchar();int x=1;int s=0;
while(c<'0' || c>'9'){if(c=='-')x=-1;c=getchar();}
while(c>='0' && c<='9'){
s=s*10+c-'0';c=getchar();
}
return s*x;
}
}using namespace IO_BUFF;
namespace CFConTest{
const int mod=998244353;
inline int add(const int &x,const int &y){
return (x+y>=mod?x+y-mod:x+y);
}
inline int del(const int &x,const int &y){
return (x-y<0?x-y+mod:x-y);
}
int ksm(int x,int k){
int base=1;
while(k){
if(k&1)base=1ll*base*x%mod;
k>>=1;
x=1ll*x*x%mod;
}
return base;
}
};
using namespace CFConTest;
const int N=4e5+5;
int n,m,a[N],l[N],r[N];
char c[N];
int sa[N*4],sb[N*4],tag[N*4];
int ta[N*4],tb[N*4];
#define ls (u<<1)
#define rs (u<<1|1)
#define mid ((l+r)>>1)
void pushdown(int u){
if(!tag[u])return ;
tag[ls]^=tag[u];
tag[rs]^=tag[u];
swap(sa[ls],sb[ls]);
swap(sa[rs],sb[rs]);
int x=ta[ls],y=tb[ls];
ta[ls]=(mod-y);
tb[ls]=(mod-x);
int xx=ta[rs],yy=tb[rs];
ta[rs]=(mod-yy);
tb[rs]=(mod-xx);
tag[u]=0;
}
void update(int u){
sa[u]=add(sa[ls],sa[rs]);
sb[u]=add(sb[ls],sb[rs]);
ta[u]=add(ta[ls],ta[rs]);
tb[u]=add(tb[ls],tb[rs]);
}
void add(int u,int l,int r,int L,int R){
if(L<=l && R>=r){
tag[u]^=1;
swap(sa[u],sb[u]);
int x=ta[u]; // \sum -i
int y=tb[u]; // \sum u
tb[u]=mod-x;
ta[u]=mod-y;
return ;
}
pushdown(u);
if(L<=mid)add(ls,l,mid,L,R);
if(R>mid)add(rs,mid+1,r,L,R);
update(u);
}
int querya(int u,int l,int r,int L,int R){
if(L>R)return 0;
if(L<=l && R>=r){
return ta[u];
}
pushdown(u);
if(R<=mid)return querya(ls,l,mid,L,R);
if(L>mid)return querya(rs,mid+1,r,L,R);
return add(querya(ls,l,mid,L,R),querya(rs,mid+1,r,L,R));
}
int queryb(int u,int l,int r,int L,int R){
if(L>R)return 0;
if(L<=l && R>=r){
return tb[u];
}
pushdown(u);
if(R<=mid)return queryb(ls,l,mid,L,R);
if(L>mid)return queryb(rs,mid+1,r,L,R);
return add(queryb(ls,l,mid,L,R),queryb(rs,mid+1,r,L,R));
}
void build(int u,int l,int r){
tag[u]=sa[u]=sb[u]=ta[u]=tb[u]=0;
if(l==r){
ta[u]=tb[u]=sa[u]=sb[u]=0;
if(a[l]==0)sa[u]=1,ta[u]=-l;
else sb[u]=1,tb[u]=l;
return ;
}
build(ls,l,mid);
build(rs,mid+1,r);
update(u);
}
signed main(){
#ifdef newbiewzs
freopen("data.in","r",stdin);
// freopen("std.out","w",stdout);
#else
#endif
int cnt=0;
while(cin>>n){
cnt++;
// cout<<cnt<<'\n';
scanf("%d",&m);
scanf("%s",c+1);
for(int i=1;i<=n;i++)a[i]=c[i]-'0';
build(1,1,n);
for(int i=1;i<=m;i++){
scanf("%d%d",&l[i],&r[i]);
if(i==4){
new char;
}
add(1,1,n,l[i],r[i]);
int u=sb[1];
if(u>n || u+1<1){
cerr<<"fck";
return 0;
}
int ans=add(add(querya(1,1,n,1,u),queryb(1,1,n,u+1,n))*2ll%mod,u);
cout<<(ans%mod+mod)%mod<<'\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 7848kb
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: 7644kb
input:
1 1 0 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Time Limit Exceeded
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 ...
output:
0 3 1 3 0 1 0 1 2 0 0 2 0 1 2 0 1 3 1 0 1 2 1 0 0 1 3 2 1 0 1 3 3 2 1 0 1 0 0 1 0 1 0 2 2 1 0 1 2 1 1 0 2 0 2 3 1 0 0 1 2 0 0 1 0 1 0 1 1 0 1 2 2 0 0 2 0 1 0 1 1 0 1 0 1 0 0 1 0 1 0 1 2 0 3 0 1 0 0 1 1 0 1 0 1 2 0 2 1 0 0 3 1 2 0 1 3 2 1 0 0 1 2 0 2 0 0 1 0 1 1 0 1 0 1 0 1 0 1 2 1 0 3 1 0 3 0 1 0 1 ...