QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#611935#6836. A Plus B ProblemwangcqRE 0ms3636kbC++235.0kb2024-10-05 00:28:142024-10-05 00:28:14

Judging History

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

  • [2024-10-05 00:28:14]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3636kb
  • [2024-10-05 00:28:14]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
const int N = 1000010;
typedef long long ll;
typedef pair<int, int> pii;
std::mt19937 rng {std::chrono::steady_clock::now().time_since_epoch().count()};

template <typename T>
void debug(T x) {
    cerr << x << '\n';
}

template <typename T, typename... Args>
void debug(T x, Args... args) {
    cerr << x << ' ';
    debug(args...);
}
int tmp[N];
struct node {
    int l, r, len;
    int val;
    int r0, r9;
    int lz0, lz9;
} tr[N * 4];

void change(int u) {
    tr[u].r0 = tr[u].r9 = 0;
    if (tr[u].val == 0) tr[u].r0 = 1;
    else if (tr[u].val == 9) tr[u].r9 = 1;
}

void pushup(node &t, node &le, node &ri) {
    t.r0 = (ri.r0 + (ri.r0 == ri.len ? le.r0 : 0));
    t.r9 = (ri.r9 + (ri.r9 == ri.len ? le.r9 : 0));
}

void pushup(int u) {
    pushup(tr[u], tr[u << 1], tr[u << 1 | 1]);
}

void build(int u, int l, int r) {
    tr[u] = {l, r, r - l + 1, 0, 0, 0, 0, 0};
    if (l == r) {
        tr[u].val = tmp[l];
        change(u);
        return ;
    }
    int mid = l + r >> 1;
    build(u << 1, l, mid);
    build(u << 1 | 1, mid + 1, r);
    pushup(u);
}

void change0(node &t) {
    t.lz0 = 1; t.lz9 = 0;
    t.r0 = t.len; 
    t.r9 = 0;
    t.val = 0;
}

void change9(node &t) {
    t.lz0 = 0; t.lz9 = 1;
    t.r9 = t.len; 
    t.r0 = 0;
    t.val = 9;
}

void pushdown(int u) {
    if (tr[u].lz0) {
        change0(tr[u << 1]);
        change0(tr[u << 1 | 1]);
        tr[u].lz0 = 0;
    } else if (tr[u].lz9) {
        change9(tr[u << 1]);
        change9(tr[u << 1 | 1]);
        tr[u].lz9 = 0;
    }
}

int fval(int u, int x) {
    if (tr[u].l == x && tr[u].r == x) {
        return tr[u].val;
    } else {
        pushdown(u);
        int mid = tr[u].l + tr[u].r >> 1;
        if (x <= mid) return fval(u << 1, x);
        else return fval(u << 1 | 1, x);
    }
}

void modify(int u, int x, int c) {
    if (tr[u].l == x && tr[u].r == x) {
        tr[u].val = (tr[u].val + c + 10) % 10;
        change(u);
        return ;
    }
    pushdown(u);
    int mid = tr[u].l + tr[u].r >> 1;
    if (x <= mid) modify(u << 1, x, c);
    else modify(u << 1 | 1, x, c);
    pushup(u);
}

int get (int p, int r, int w){
    if (!r) return 0;
    if (tr[p].r <= r) {
        if (w == 0) return tr[p].r0;
        return tr[p].r9;
    }
    pushdown(p);
    int mid = (tr[p].l + tr[p].r) >> 1;
    if(r <= mid) return get(p << 1, r, w);
    else {
        int x = get(p << 1 | 1, r, w);
        if (x == r - mid) x += get(p << 1, r, w);
        return x;
    }
}

void tp(int u, int l, int r, int w) {
    if (tr[u].l >= l && tr[u].r <= r) {
        if (w == 0) {
            change0(tr[u]);
        } else {
            change0(tr[u]);
        }
        return ;
    }
    pushdown(u);
    int mid = tr[u].l + tr[u].r >> 1;
    if (l <= mid) tp(u << 1, l, r, w);
    if (r > mid) tp(u << 1 | 1, l, r, w);
    pushup(u);
}

void solve() {
    int n, q;
    cin >> n >> q;
    string s1, s2;
    cin >> s1 >> s2; s1 = ' ' + s1; s2 = ' ' + s2;
    vector<int> a(n + 1), b(n + 1);
    for (int i = 1; i <= n; i ++ ) {
        a[i] = s1[i] - '0';
        b[i] = s2[i] - '0';
    }
    for (int i = n; i >= 1; i -- ) {
        int tt = (s1[i] - '0') + (s2[i] - '0');
        tmp[i - 1] += ((tt + tmp[i]) / 10);
        tmp[i] = (tmp[i] + tt) % 10;
    }
    build(1, 1, n);

    while (q -- ) {
        int r, c, d;
        cin >> r >> c >> d;
        int del = 0;
        if (r == 1) {
            del = d - a[c];
            a[c] = d;
        } else {
            del = d - b[c];
            b[c] = d;
        }
        int x = fval(1, c);
        if (! del) cout << x << " 0" << '\n';
        else if (del > 0) {
            modify(1, x, del);
            if (x + del >= 10) {
                int cnt = get(1, c - 1, 9);
                int idx = c - cnt - 1;
                int ans = c - idx + 1;
                if (idx == 0) ans --;
                if (idx + 1 <= c - 1) tp(1, idx + 1, c - 1, 0);
                if (idx) modify(1, idx, 1);
                cout << fval(1, c) << ' ' << ans + 1 << '\n';
            } else {
                cout << fval(1, c) << ' ' << 2 << '\n';
            }
        } else if(del < 0) {
            del = -del;
            modify(1, c, -del);
            if (x - del < 0) {
                int cnt = get(1, c - 1, 0);
                int idx = c - cnt - 1;
                int ans = c - idx + 1;
                if (idx == 0) ans --;
                if (idx + 1 <= c - 1) tp(1, idx + 1, c - 1, 9);
                if (idx) modify(1, idx, -1);
                cout << fval(1, c) << ' ' << ans + 1 << '\n';
            } else {
                cout << fval(1, c) << ' ' << 2 << '\n';
            }
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    // cin >> T;
    while (T -- ) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3636kb

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
Runtime Error

input:

1 1
1
1
1 1 9

output:


result: