QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#103135#2831. Game TheorySham_DevourWA 3ms3628kbC++111.8kb2023-05-04 16:17:172023-05-04 16:17:20

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-04 16:17:20]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3628kb
  • [2023-05-04 16:17:17]
  • 提交

answer

#include <cstdio>
#include <iostream>
#include <cstring>
#define ll long long
#define lson p << 1
#define rson p << 1 | 1
using namespace std;
const int N = 2e5 + 5;
const ll mod = 998244353;

int n, q, a[N];

struct node {
	int l, r, len, cnt, lazy;
	ll s0, s1;
} t[N << 2];
void pushup(int p) {
	t[p].cnt = (t[lson].cnt + t[rson].cnt) % mod;
	t[p].s0 = t[lson].s0 + t[rson].s0;
	t[p].s1 = t[lson].s1 + t[rson].s1;
}
void build(int p, int l, int r) {
	t[p].l = l, t[p].r = r, t[p].len = r - l + 1;
	if (l == r) {
		if (a[l]) t[p].cnt = 1, t[p].s1 = l;
		else t[p].s0 = l;
		return;
	}
	int mid = l + r >> 1;
	build(lson, l, mid), build(rson, mid + 1, r);
	pushup(p);
}
void pushdown(int p) {
	if (!t[p].lazy) return;
	t[lson].cnt = t[lson].len - t[lson].cnt;
	swap(t[lson].s0, t[lson].s1);
	t[lson].lazy ^= 1;
	t[rson].cnt = t[rson].len - t[rson].cnt;
	swap(t[rson].s0, t[rson].s1);
	t[rson].lazy ^= 1;
	t[p].lazy = 0;
}
void update(int p, int l, int r) {
	if (l <= t[p].l && r >= t[p].r) {
		t[p].cnt = t[p].len - t[p].cnt;
		swap(t[p].s0, t[p].s1);
		t[p].lazy ^= 1;
		return;
	}
	pushdown(p);
	int mid = t[p].l + t[p].r >> 1;
	if (l <= mid) update(lson, l, r);
	if (r > mid) update(rson, l, r);
	pushup(p);
}
ll query(int p, int l, int r, int type) {
	if (l <= t[p].l && r >= t[p].r) return type ? t[p].s1 : t[p].s0;
	pushdown(p);
	int mid = t[p].l + t[p].r >> 1;
	ll res = 0;
	if (l <= mid) res = (res + query(lson, l, r, type)) % mod;
	if (r > mid) res = (res + query(rson, l, r, type)) % mod;
	return res;
}

int main() {
	scanf("%d %d", &n, &q);
	for (int i = 1; i <= n; i++) scanf("%1d", &a[i]);
	build(1, 1, n);
	while (q--) {
		int l, r, c;
		scanf("%d %d", &l, &r);
		update(1, l, r), c = t[1].cnt;
		printf("%lld\n", ((query(1, c + 1, n, 1) - query(1, 1, c, 0) + mod) * 2 + c) % mod);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 3628kb

input:

3 2
010
1 2
2 3
5 1
00000
1 5

output:

1
3

result:

wrong answer 3rd lines differ - expected: '5', found: ''