Submission #954465

#TimeUsernameProblemLanguageResultExecution timeMemory
954465GrandTiger1729Bliskost (COI23_bliskost)C++17
57 / 100
1025 ms107864 KiB
#include <bits/stdc++.h>
using namespace std;

const int K = 26;
struct SegTree
{
    int l, r, mid;
    SegTree *lc, *rc;
    int val;
    SegTree(const vector<int> &a, int l_, int r_) : l(l_), r(r_)
    {
        mid = (l + r) / 2;
        if (l == r - 1)
        {
            val = a[l];
            return;
        }
        lc = new SegTree(a, l, mid);
        rc = new SegTree(a, mid, r);
        pull();
    }
    void pull()
    {
        val = (rc->val + ((r - mid) % 2 == 0 ? 1 : -1) * lc->val + K) % K;
    }
    void update(int i, int u)
    {
        if (l == r - 1)
        {
            val = u;
            return;
        }
        if (i < mid)
        {
            lc->update(i, u);
        }
        else
        {
            rc->update(i, u);
        }
        pull();
    }
};
int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    string a, b;
    cin >> a >> b;
    vector<int> c(n);
    for (int i = 0; i < n; i++)
    {
        c[i] = (b[i] - a[i] + K) % K;
    }
    SegTree st(c, 0, n);
    cout << (st.val == 0 ? "da" : "ne") << '\n';
    while (q--)
    {
        int j;
        char x;
        cin >> j >> x;
        j--;
        a[j] = x;
        st.update(j, (b[j] - a[j] + K) % K);
        cout << (st.val == 0 ? "da" : "ne") << '\n';
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...