QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#560776 | #6836. A Plus B Problem | cyj888 | WA | 221ms | 10076kb | C++11 | 2.0kb | 2024-09-12 17:51:42 | 2024-09-12 17:51:43 |
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, val, sum = 0; bool fl = 0; scanf ("%d %d %d", &x, &y, &val);
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] = val; else b[y] = val;
z = y + 1;
if (a[y] + b[y] > 10) fl ^= 1;
else {
if (a[y] + b[y] == 9) add (y, 1);
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;
}
if (a[y] + b[y] == 9) fl ^= (a[z] + b[z] > 10);
}
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: 100
Accepted
time: 1ms
memory: 10076kb
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: 0
Accepted
time: 1ms
memory: 10032kb
input:
1 1 1 1 1 1 9
output:
0 2
result:
ok single line: '0 2'
Test #3:
score: -100
Wrong Answer
time: 221ms
memory: 9972kb
input:
10 1000000 6869373857 3130626142 1 9 2 1 10 0 2 7 6 1 1 0 1 7 6 2 10 4 2 3 9 2 4 2 2 4 4 2 7 0 1 2 4 1 9 8 1 3 7 1 7 1 1 1 5 2 1 6 1 3 5 2 5 8 2 6 5 1 6 3 1 3 8 2 4 2 2 6 3 2 2 6 1 10 9 2 1 1 2 5 4 1 1 8 2 4 0 1 9 1 1 1 8 2 4 2 2 9 2 1 10 3 1 8 9 1 4 6 2 3 0 1 1 6 1 7 1 1 10 9 2 4 4 2 5 9 2 1 8 1 9 ...
output:
6 2 2 2 9 2 3 2 2 8 4 2 5 2 1 2 3 2 6 5 6 3 2 4 7 2 2 2 8 2 1 3 5 2 1 3 2 3 8 3 8 2 2 2 6 2 1 2 3 3 6 3 7 3 9 2 9 3 6 4 9 2 1 3 4 2 7 3 0 2 8 3 8 3 7 2 1 2 3 3 0 2 2 3 4 3 9 2 3 2 7 2 2 3 5 3 2 2 5 2 3 2 3 3 1 3 4 3 7 2 0 2 5 2 6 2 0 3 4 2 4 2 3 2 5 3 6 3 3 2 8 2 9 3 9 3 0 3 1 4 7 2 5 2 5 2 4 2 0 3 ...
result:
wrong answer 3rd lines differ - expected: '9 0', found: '9 2'