Submission #1105517

# Submission time Handle Problem Language Result Execution time Memory
1105517 2024-10-26T15:59:14 Z _callmelucian Bliskost (COI23_bliskost) C++14
44 / 100
401 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;

#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())

int add (int a, int b) {
    assert(0 <= a && a < 26 && 0 <= b && b < 26);
    return a + b - (a + b < 26 ? 0 : 26);
}

int sub (int a, int b) {
    assert(0 <= a && a < 26 && 0 <= b && b < 26);
    return a - b + (a - b >= 0 ? 0 : 26);
}

int mul (int a, int b) {
    assert(0 <= a && a < 26 && 0 <= b && b < 26);
    return 1LL * a * b % 26;
}

struct matrix {
    vector<vector<int>> v;
    int n, m;

    matrix (int n, int m) :
        v(n, vector<int>(m)), n(n), m(m) {}
    matrix (vector<vector<int>> init) :
        v(init), n(v.size()), m(v.size() ? v[0].size() : 0) {}

    vector<int>& operator[] (int x) { return v[x]; }

    matrix operator * (matrix o) {
        assert(m == o.n);
        matrix ans(n, o.m);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < o.m; j++)
                for (int k = 0; k < m; k++)
                    ans[i][j] = add(ans[i][j], mul(v[i][k], o[k][j]));
        return ans;
    }
};

const matrix iden2({{1, 0}, {0, 1}});

struct IT {
    vector<matrix> tr;
    IT (int sz) : tr(4 * sz, iden2) {}

    void update (int pos, matrix val, int k, int l, int r) {
        if (pos < l || r < pos) return;
        if (l == r) return tr[k] = val, void();
        int mid = (l + r) >> 1;
        update(pos, val, 2 * k, l, mid);
        update(pos, val, 2 * k + 1, mid + 1, r);
        tr[k] = tr[2 * k] * tr[2 * k + 1];
    }

    bool valid() { return tr[1][0][1] == 0; }
};

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, q; cin >> n >> q;
    string s, t; cin >> s >> t;
    s = " " + s, t = " " + t;

    IT tree(n);
    for (int i = 1; i <= n; i++) {
        int val = sub(t[i] - 'a', s[i] - 'a');
        tree.update(i, matrix({{sub(0, 1), val}, {0, 1}}), 1, 1, n);
    }

    cout << (tree.valid() ? "da" : "ne") << "\n";
    for (int i = 0; i < q; i++) {
        int p; char c; cin >> p >> c;
        int val = sub(t[p] - 'a', c - 'a');
        s[p] = c;
        tree.update(p, matrix({{sub(0, 1), val }, {0, 1}}), 1, 1, n);
        cout << (tree.valid() ? "da" : "ne") << "\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 4 ms 848 KB Output is correct
17 Correct 4 ms 848 KB Output is correct
18 Correct 4 ms 848 KB Output is correct
19 Correct 4 ms 1016 KB Output is correct
20 Correct 4 ms 1072 KB Output is correct
21 Correct 5 ms 1016 KB Output is correct
22 Correct 5 ms 848 KB Output is correct
23 Correct 4 ms 848 KB Output is correct
24 Correct 4 ms 848 KB Output is correct
25 Correct 4 ms 848 KB Output is correct
26 Correct 4 ms 848 KB Output is correct
27 Correct 4 ms 1028 KB Output is correct
28 Correct 4 ms 848 KB Output is correct
29 Correct 4 ms 848 KB Output is correct
30 Correct 4 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 4 ms 848 KB Output is correct
17 Correct 4 ms 848 KB Output is correct
18 Correct 4 ms 848 KB Output is correct
19 Correct 4 ms 1016 KB Output is correct
20 Correct 4 ms 1072 KB Output is correct
21 Correct 5 ms 1016 KB Output is correct
22 Correct 5 ms 848 KB Output is correct
23 Correct 4 ms 848 KB Output is correct
24 Correct 4 ms 848 KB Output is correct
25 Correct 4 ms 848 KB Output is correct
26 Correct 4 ms 848 KB Output is correct
27 Correct 4 ms 1028 KB Output is correct
28 Correct 4 ms 848 KB Output is correct
29 Correct 4 ms 848 KB Output is correct
30 Correct 4 ms 848 KB Output is correct
31 Runtime error 401 ms 524288 KB Execution killed with signal 9
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 73 ms 584 KB Output is correct
17 Correct 83 ms 584 KB Output is correct
18 Correct 73 ms 584 KB Output is correct
19 Correct 73 ms 576 KB Output is correct
20 Correct 74 ms 584 KB Output is correct
21 Correct 73 ms 592 KB Output is correct
22 Correct 74 ms 632 KB Output is correct
23 Correct 73 ms 584 KB Output is correct
24 Correct 92 ms 512 KB Output is correct
25 Correct 74 ms 584 KB Output is correct
26 Correct 74 ms 584 KB Output is correct
27 Correct 73 ms 592 KB Output is correct
28 Correct 73 ms 592 KB Output is correct
29 Correct 82 ms 584 KB Output is correct
30 Correct 73 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 4 ms 848 KB Output is correct
17 Correct 4 ms 848 KB Output is correct
18 Correct 4 ms 848 KB Output is correct
19 Correct 4 ms 1016 KB Output is correct
20 Correct 4 ms 1072 KB Output is correct
21 Correct 5 ms 1016 KB Output is correct
22 Correct 5 ms 848 KB Output is correct
23 Correct 4 ms 848 KB Output is correct
24 Correct 4 ms 848 KB Output is correct
25 Correct 4 ms 848 KB Output is correct
26 Correct 4 ms 848 KB Output is correct
27 Correct 4 ms 1028 KB Output is correct
28 Correct 4 ms 848 KB Output is correct
29 Correct 4 ms 848 KB Output is correct
30 Correct 4 ms 848 KB Output is correct
31 Correct 73 ms 584 KB Output is correct
32 Correct 83 ms 584 KB Output is correct
33 Correct 73 ms 584 KB Output is correct
34 Correct 73 ms 576 KB Output is correct
35 Correct 74 ms 584 KB Output is correct
36 Correct 73 ms 592 KB Output is correct
37 Correct 74 ms 632 KB Output is correct
38 Correct 73 ms 584 KB Output is correct
39 Correct 92 ms 512 KB Output is correct
40 Correct 74 ms 584 KB Output is correct
41 Correct 74 ms 584 KB Output is correct
42 Correct 73 ms 592 KB Output is correct
43 Correct 73 ms 592 KB Output is correct
44 Correct 82 ms 584 KB Output is correct
45 Correct 73 ms 604 KB Output is correct
46 Correct 261 ms 1360 KB Output is correct
47 Correct 251 ms 1120 KB Output is correct
48 Correct 259 ms 1352 KB Output is correct
49 Correct 255 ms 1336 KB Output is correct
50 Correct 273 ms 1352 KB Output is correct
51 Correct 262 ms 1340 KB Output is correct
52 Correct 268 ms 1352 KB Output is correct
53 Correct 270 ms 1128 KB Output is correct
54 Correct 262 ms 1352 KB Output is correct
55 Correct 261 ms 1348 KB Output is correct
56 Correct 261 ms 1344 KB Output is correct
57 Correct 256 ms 1356 KB Output is correct
58 Correct 259 ms 1308 KB Output is correct
59 Correct 260 ms 1364 KB Output is correct
60 Correct 270 ms 1352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 4 ms 848 KB Output is correct
17 Correct 4 ms 848 KB Output is correct
18 Correct 4 ms 848 KB Output is correct
19 Correct 4 ms 1016 KB Output is correct
20 Correct 4 ms 1072 KB Output is correct
21 Correct 5 ms 1016 KB Output is correct
22 Correct 5 ms 848 KB Output is correct
23 Correct 4 ms 848 KB Output is correct
24 Correct 4 ms 848 KB Output is correct
25 Correct 4 ms 848 KB Output is correct
26 Correct 4 ms 848 KB Output is correct
27 Correct 4 ms 1028 KB Output is correct
28 Correct 4 ms 848 KB Output is correct
29 Correct 4 ms 848 KB Output is correct
30 Correct 4 ms 848 KB Output is correct
31 Runtime error 401 ms 524288 KB Execution killed with signal 9
32 Halted 0 ms 0 KB -