QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#21936#2831. Game TheoryCCPSDCGK#TL 2ms11860kbC++203.2kb2022-03-08 18:26:402022-05-08 04:17:15

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 04:17:15]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:11860kb
  • [2022-03-08 18:26:40]
  • 提交

answer

#include<map>
#include<set>
#include<queue>
#include<deque>
#include<cmath>
#include<ctime>
#include<bitset>
#include<vector>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
#define mkp make_pair
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define fs fflush(stdout)
#define ump unordered_map
#define pq priority_queue
#define clz __builtin_clz
#define ctz __builtin_ctz
#define space putchar(' ')
#define enter putchar('\n')
#define sz(x) (int)x.size()
#define np next_permutation
#define clzl __builtin_clzll
#define par __builtin_parity
#define ctzl __builtin_ctzll
#define ppc __builtin_popcount
#define parl __builtin_parityll
#define all(x) x.begin(),x.end()
#define ppcl __builtin_popcountll
#define ms(x,y) memset(x,y,sizeof(x))
#define debug(x) cerr<<#x<<"= "<<(x)<<'\n'
template<class T> inline T &read(T &x){
	x=0;int f=1;char ch=getchar();
	while(ch<48||ch>57){if(ch=='-') f=-f;ch=getchar();}
	while(ch>=48&&ch<=57) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*=f;
}
template<class T> inline void print(T x){
	static char buf[40];static int cnt=0;
	if(x<0) putchar(45),x=-x;
	do buf[++cnt]=x%10^48;while(x/=10);
	do putchar(buf[cnt--]);while(cnt);
}
#define mod 998244353
#define inf 0x3f3f3f3f
#define fpi freopen("","r",stdin)
#define fpo freopen("","w",stdout)
char s[200005];
bool rev[400005];
int cnt[2][400005],tot,sum[2][400005],ls[400005],rs[400005];
inline int rmod(int x){return x-mod+(x-mod>>31&mod);}
inline int qmod(int x){if(x>=mod) return x-mod;if(x<0) return x+mod;return x;}
inline void pushup(int x){
	sum[0][x]=rmod(sum[0][ls[x]]+sum[0][rs[x]]),sum[1][x]=rmod(sum[1][ls[x]]+sum[1][rs[x]]);
	cnt[0][x]=cnt[0][ls[x]]+cnt[0][rs[x]],cnt[1][x]=cnt[1][ls[x]]+cnt[1][rs[x]];
}
void build(int &x,int l,int r){
	x=++tot;if(l==r){sum[s[l]&1][x]=l,cnt[s[l]&1][x]=1;return ;}
	int mid=l+r>>1;
	build(ls[x],l,mid),build(rs[x],mid+1,r);
	pushup(x);
}
inline void swap(int x){
	sum[0][x]^=sum[1][x]^=sum[0][x]^=sum[1][x];
	cnt[0][x]^=cnt[1][x]^=cnt[0][x]^=cnt[1][x];
	rev[x]^=1;
}
inline void pushdown(int x){
	if(rev[x]){swap(ls[x]),swap(rs[x]),rev[x]=0;}
}
void change(int x,int l,int r,int l1,int r1){
	if(l<=l1&&r1<=r){swap(x);return ;}
	pushdown(x);int mid=l1+r1>>1;
	if(l<=mid) change(ls[x],l,r,l1,mid);if(mid<r) change(rs[x],l,r,mid+1,r1);
	pushup(x);
}
int query(bool type,int x,int l,int r,int l1,int r1){
	if(l>r) return 0;
	if(l<=l1&&r1<=r) return sum[type][x];
	pushdown(x);int mid=l1+r1>>1,res=0;
	if(l<=mid) res=query(type,ls[x],l,r,l1,mid);if(mid<r) res=rmod(res+query(type,rs[x],l,r,mid+1,r1));
	return res;
}
void solve(int n,int q){
	int rt,i;tot=0;
	for(i=1;i<n<<1;i++) sum[0][i]=sum[1][i]=cnt[0][i]=cnt[1][i]=rev[i]=0;
	scanf("%s",s+1),build(rt,1,n);
	while(q--){
		int l=read(l),r=read(r);
		change(1,l,r,1,n);
		int sum1=query(0,1,1,cnt[1][1],1,n),sum2=query(1,1,cnt[1][1]+1,n,1,n);
		print(qmod(sum2-sum1+cnt[1][1])),enter;
	}
}
int main(){
	int n,q;
	while(cin>>n>>q) solve(n,q);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 11860kb

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: 2ms
memory: 9780kb

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
2
1
2
0
1
0
1
2
0
0
2
0
1
2
0
1
2
1
0
1
2
1
0
0
1
2
2
1
0
1
2
2
2
1
0
1
0
0
1
0
1
0
2
2
1
0
1
2
1
1
0
2
0
2
2
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
2
0
1
0
0
1
1
0
1
0
1
2
0
2
1
0
0
2
1
2
0
1
2
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
2
1
0
2
0
1
0
1
...

result: