QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#561714#6836. A Plus B Problemcyj888WA 1ms7988kbC++112.3kb2024-09-13 09:30:082024-09-13 09:30:08

Judging History

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

  • [2024-09-13 09:30:08]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7988kb
  • [2024-09-13 09:30:08]
  • 提交

answer

#include <bits/stdc++.h>
#define ott(i,l,r) for (int i = l; i <= r; i ++)
#define tto(i,l,r) for (int i = r; i >= l; i --)
using namespace std;
using ll = long long;
int read () {
	int x = 0; bool f = 0; char c = getchar ();
	while (!isdigit (c)) f |= (c == '-'), c = getchar ();
	while (isdigit (c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar ();
	if (f) x = -x; return x;
}
const int N = 1e6 + 110;	
int n, q, ng;
int a[N], b[N];
char s[N];
int tr[N];
int lo (int x) {
	return x & (-x);
}
void add (int x, int v) {
	while (x <= n) {
		tr[x] += v;
		x += lo (x);
	}
	return ;
}
int ask (int x) {
	int v = 0;
	while (x) {
		v += tr[x];
		x -= lo (x);
	}
	return v;
}
int main () {
	scanf ("%d %d", &n, &q);
	scanf ("%s", s + 1); ott (i, 1, n) a[i] = s[i] - '0';
	scanf ("%s", s + 1); ott (i, 1, n) b[i] = s[i] - '0';
	ott (i, 1, n) if (a[i] + b[i] == 9) add (i, 1);
	while (q --) {
		int x, y, z, l, r, mid, val; bool fl = 0, fr = 0; scanf ("%d %d %d", &x, &y, &val);
		if (a[y] + b[y] > 9) fl ^= 1;
		else if (a[y] + b[y] == 9) {
			z = l = y + 1, r = n + 1;
			while (l <= r) {
				mid = l + r >> 1;
				if (ask (mid - 1) - ask (y) == mid - 1 - y) z = mid, l = mid + 1;
				else r = mid - 1;
			}
			fl ^= (a[z] + b[z] > 9);
			add (y, -1);
		}
		if (x == 1) fr = (a[y] == val), a[y] = val; else fr = (b[y] == val), b[y] = val;
		if (a[y] + b[y] > 9) fl ^= 1;
		else if (a[y] + b[y] == 9) {
			add (y, 1);
			z = l = y + 1, r = n + 1;
			while (l <= r) {
				mid = l + r >> 1;
				if (ask (mid - 1) - ask (y) == mid - 1 - y) z = mid, l = mid + 1;
				else r = mid - 1;
			}
			fl ^= (a[z] + b[z] > 9);
		}
		z = l = y + 1, r = n + 1;
		while (l <= r) {
			mid = l + r >> 1;
			if (ask (mid - 1) - ask (y) == mid - 1 - y) z = mid, l = mid + 1;
			else r = mid - 1;
		}
		printf ("%d ", (a[y] + b[y] + (a[z] + b[z] > 9)) % 10);
		if (fl) {
			l = 1, z = r = y - 1;
			while (l <= r) {
				mid = l + r >> 1;
				if (ask (y - 1) - ask (mid) == y - 1 - mid) z = mid, r = mid - 1;
				else l = mid + 1;
			}
		}
		else z = y;
		if (fr) z += 2;
		printf ("%d\n", y - z + 2);
		//ott (j, 1, n) printf ("%d ", a[j]); puts ("");
		//ott (j, 1, n) printf ("%d ", b[j]); puts ("");
		//ott (j, 1, n) printf ("%d ", a[j] + b[j]); puts ("");
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7908kb

input:

5 5
01234
56789
2 1 0
2 2 1
2 3 2
2 4 3
2 5 4

output:

0 2
3 2
5 3
7 3
8 3

result:

ok 5 lines

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 7988kb

input:

1 1
1
1
1 1 9

output:

0 3

result:

wrong answer 1st lines differ - expected: '0 2', found: '0 3'