QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#560727 | #6836. A Plus B Problem | cyj888 | WA | 1ms | 7840kb | C++11 | 1.9kb | 2024-09-12 17:33:22 | 2024-09-12 17:33:22 |
Judging History
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, sum = 0; bool fl = 0; scanf ("%d %d %d", &x, &y, &z);
if (a[y] + b[y] > 10) 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] > 10);
add (y, -1);
}
if (x == 1) a[y] = z; else b[y] = z;
if (a[y] + b[y] > 10) 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] > 10);
add (y, 1);
}
printf ("%d ", (a[y] + b[y] + (a[z] + b[z] > 10)) % 10);
z = y;
if (fl) {
l = 0, r = y;
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;
}
}
printf ("%d\n", y - z + 2);
//ott (j, 1, n) printf ("%d ", a[j] + b[j]); puts ("");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7840kb
input:
5 5 01234 56789 2 1 0 2 2 1 2 3 2 2 4 3 2 5 4
output:
0 2 2 2 7 3 6 3 8 3
result:
wrong answer 2nd lines differ - expected: '3 2', found: '2 2'