QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#670670 | #6836. A Plus B Problem | wdw | WA | 244ms | 7904kb | C++20 | 5.1kb | 2024-10-23 22:54:41 | 2024-10-23 22:54:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
//#define int long long
const int N = 1e6 + 5;
struct node {
int l, r, pre[2], id, la;
} t[N * 6];
void pushup(node &ans, node zer, node yer) {
ans.id = zer.id;
ans.l = zer.l, ans.r = yer.r;
ans.pre[0] = zer.pre[0] + yer.pre[0];
ans.pre[1] = zer.pre[1] + yer.pre[1];
}
void pushup(int p) {
pushup(t[p], t[p * 2], t[p * 2 + 1]);
}
void f(int p, int x) {
if (x == 1) {
t[p].id = 0;
t[p].pre[0] = (t[p].r - t[p].l + 1);
t[p].pre[1] = 0;
} else if (x == 2) {
t[p].id = 9;
t[p].pre[1] = (t[p].r - t[p].l + 1);
t[p].pre[0] = 0;
}
}
void pushdown(int p) {
if (t[p].la) {
f(p * 2, t[p].la);
f(p * 2 + 1, t[p].la);
t[p].la = 0;
return;
}
}
int c[N], a[N], b[N];
void build(int p, int l, int r) {
t[p].l = l, t[p].r = r;
if (l == r) {
t[p].id = c[l];
if (t[p].id == 0) {
t[p].pre[0] = 1;
t[p].pre[1] = 0;
} else if (t[p].id == 9) {
t[p].pre[1] = 1;
t[p].pre[0] = 0;
}
return;
}
int mid = (l + r) / 2;
build(p * 2, l, mid);
build(p * 2 + 1, mid + 1, r);
pushup(p);
}//
void change(int p, int l, int r, int x) {
if (t[p].l >= l && t[p].r <= r) {
t[p].id = x;
if (t[p].id == 0) {
t[p].pre[0] = (t[p].r - t[p].l + 1);
t[p].pre[1] = 0;
t[p].la = 1;
} else if (t[p].id == 9) {
t[p].pre[1] = (t[p].r - t[p].l + 1);
t[p].pre[0] = 0;
t[p].la = 2;
} else {
t[p].pre[1] = 0;
t[p].pre[0] = 0;
t[p].la = 0;
}
return;
}
pushdown(p);
int mid = (t[p].r + t[p].l) / 2;
if (mid < r)change(p * 2 + 1, l, r, x);
if (mid >= l)change(p * 2, l, r, x);
pushup(p);
}
node ask(int p, int l, int r) {
if (t[p].l >= l && t[p].r <= r) {
return t[p];
}
pushdown(p);
int mid = (t[p].r + t[p].l) / 2;
if (r <= mid) {
return ask(p * 2, l, r);
} else if (l > mid) {
return ask(p * 2 + 1, l, r);
} else {
node res;
pushup(res, ask(p * 2, l, r), ask(p * 2 + 1, l, r));
return res;
}
}
int n, q;
int ql(int p, int x, int id) {
if (t[p].l == t[p].r)return t[p].l;
pushdown(p);
int mid = (t[p].l + t[p].r) / 2;
int sum = (t[p].r - mid) - t[p * 2 + 1].pre[id];
if (sum >= x) {
return ql(p * 2 + 1, x, id);
} else {
return ql(p * 2, x - sum, id);
}
}
void solve() {
cin >> n >> q;
string a1, a2;
cin >> a1 >> a2;
for (int i = 0; i < a1.size(); i++) {
a[i + 1] = (a1[i] - '0');
}
for (int i = 0; i < a2.size(); i++) {
b[i + 1] = (a2[i] - '0');
}
for (int i = n; i >= 1; i--) {
c[i] += (a[i] + b[i]);
if (c[i] >= 10) {
c[i] %= 10;
c[i - 1]++;
}
}
c[0] = 1e7;
build(1, 0, n);
for (int i = 1; i <= q; i++) {
int r, cc, d;
cin >> r >> cc >> d;
int f = 0;
auto p1 = ask(1, cc, cc);
int w = 0;
if (r == 1) {
w = d - a[cc];
a[cc] = d;
} else {
w = d - b[cc];
b[cc] = d;
}
int f1 = 0;
int px = 0;
int ans = 0;
if (w != 0) {
ans++;
}
if (p1.id + w >= 10) {
f1 = 1;
px = p1.id + w - 10;
} else if (p1.id + w < 0) {
f = 1;
px = p1.id + w + 10;
} else {
px = p1.id + w;
}
if (px != p1.id) {
ans++;
}
change(1, cc, cc, px);
if (f1) {
auto sum = ask(1, cc, n);
int val = (n - cc + 1 - sum.pre[1]) + 1;
int l = ql(1, val, 1);
if (l + 1 <= cc - 1) {
change(1, l + 1, cc - 1, 0);
ans += (cc - 1 - (l + 1) + 1);
}
auto p = ask(1, l, l);
change(1, l, l, p.id + 1);
if (l > 0)
ans++;
} else if (f) {
auto sum = ask(1, cc, n);
int val = (n - cc + 1 - sum.pre[0]) + 1;
int l = ql(1, val, 0);
if (l + 1 <= cc - 1) {
change(1, l + 1, cc - 1, 9);
ans += (cc - 1 - (l + 1) + 1);
}
auto p = ask(1, l, l);
change(1, l, l, p.id - 1);
if (l > 0)
ans++;
}
auto p3 = ask(1, cc, cc);
cout << p3.id << " " << ans << "\n";
// for (int i = 1; i <= n; i++) {
// cout << ask(1, i, i).id;
// }
// cout << '\n';
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
//cin >> T;
while (T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7692kb
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: 7624kb
input:
1 1 1 1 1 1 9
output:
0 2
result:
ok single line: '0 2'
Test #3:
score: -100
Wrong Answer
time: 244ms
memory: 7904kb
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 0 3 2 2 8 4 2 5 3 1 3 3 2 6 5 7 3 2 4 7 2 2 2 8 2 1 2 5 2 1 3 2 3 8 3 8 2 1 2 6 2 2 3 3 3 7 2 7 3 0 2 8 3 6 4 0 0 0 3 4 2 7 3 0 3 7 3 8 3 8 2 2 0 3 3 9 2 2 4 5 2 9 2 4 2 8 2 3 3 5 3 3 2 5 0 4 2 2 2 1 2 4 2 7 3 9 3 5 2 5 3 0 3 4 2 3 2 3 2 5 3 6 3 3 0 8 2 9 3 9 3 1 2 1 4 7 2 5 2 5 2 3 0 0 2 ...
result:
wrong answer 7th lines differ - expected: '6 2', found: '5 3'