#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, matrix(2, 2)) {}
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";
while (q--) {
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 |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 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 |
504 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 |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 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 |
504 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
5 ms |
848 KB |
Output is correct |
17 |
Correct |
5 ms |
848 KB |
Output is correct |
18 |
Correct |
5 ms |
848 KB |
Output is correct |
19 |
Correct |
4 ms |
1088 KB |
Output is correct |
20 |
Correct |
4 ms |
1248 KB |
Output is correct |
21 |
Correct |
4 ms |
968 KB |
Output is correct |
22 |
Correct |
4 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 |
1092 KB |
Output is correct |
26 |
Correct |
4 ms |
892 KB |
Output is correct |
27 |
Correct |
4 ms |
848 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 |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 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 |
504 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
5 ms |
848 KB |
Output is correct |
17 |
Correct |
5 ms |
848 KB |
Output is correct |
18 |
Correct |
5 ms |
848 KB |
Output is correct |
19 |
Correct |
4 ms |
1088 KB |
Output is correct |
20 |
Correct |
4 ms |
1248 KB |
Output is correct |
21 |
Correct |
4 ms |
968 KB |
Output is correct |
22 |
Correct |
4 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 |
1092 KB |
Output is correct |
26 |
Correct |
4 ms |
892 KB |
Output is correct |
27 |
Correct |
4 ms |
848 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 |
546 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 |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 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 |
504 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
74 ms |
1104 KB |
Output is correct |
17 |
Correct |
75 ms |
1104 KB |
Output is correct |
18 |
Correct |
74 ms |
1096 KB |
Output is correct |
19 |
Correct |
85 ms |
1096 KB |
Output is correct |
20 |
Correct |
75 ms |
1096 KB |
Output is correct |
21 |
Correct |
75 ms |
1048 KB |
Output is correct |
22 |
Correct |
108 ms |
1096 KB |
Output is correct |
23 |
Correct |
74 ms |
1112 KB |
Output is correct |
24 |
Correct |
85 ms |
1096 KB |
Output is correct |
25 |
Correct |
80 ms |
1096 KB |
Output is correct |
26 |
Correct |
76 ms |
968 KB |
Output is correct |
27 |
Correct |
74 ms |
1020 KB |
Output is correct |
28 |
Correct |
74 ms |
980 KB |
Output is correct |
29 |
Correct |
82 ms |
1096 KB |
Output is correct |
30 |
Correct |
73 ms |
1000 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 |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 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 |
504 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
5 ms |
848 KB |
Output is correct |
17 |
Correct |
5 ms |
848 KB |
Output is correct |
18 |
Correct |
5 ms |
848 KB |
Output is correct |
19 |
Correct |
4 ms |
1088 KB |
Output is correct |
20 |
Correct |
4 ms |
1248 KB |
Output is correct |
21 |
Correct |
4 ms |
968 KB |
Output is correct |
22 |
Correct |
4 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 |
1092 KB |
Output is correct |
26 |
Correct |
4 ms |
892 KB |
Output is correct |
27 |
Correct |
4 ms |
848 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 |
74 ms |
1104 KB |
Output is correct |
32 |
Correct |
75 ms |
1104 KB |
Output is correct |
33 |
Correct |
74 ms |
1096 KB |
Output is correct |
34 |
Correct |
85 ms |
1096 KB |
Output is correct |
35 |
Correct |
75 ms |
1096 KB |
Output is correct |
36 |
Correct |
75 ms |
1048 KB |
Output is correct |
37 |
Correct |
108 ms |
1096 KB |
Output is correct |
38 |
Correct |
74 ms |
1112 KB |
Output is correct |
39 |
Correct |
85 ms |
1096 KB |
Output is correct |
40 |
Correct |
80 ms |
1096 KB |
Output is correct |
41 |
Correct |
76 ms |
968 KB |
Output is correct |
42 |
Correct |
74 ms |
1020 KB |
Output is correct |
43 |
Correct |
74 ms |
980 KB |
Output is correct |
44 |
Correct |
82 ms |
1096 KB |
Output is correct |
45 |
Correct |
73 ms |
1000 KB |
Output is correct |
46 |
Correct |
268 ms |
1864 KB |
Output is correct |
47 |
Correct |
250 ms |
1864 KB |
Output is correct |
48 |
Correct |
249 ms |
1864 KB |
Output is correct |
49 |
Correct |
246 ms |
1868 KB |
Output is correct |
50 |
Correct |
309 ms |
2120 KB |
Output is correct |
51 |
Correct |
269 ms |
1872 KB |
Output is correct |
52 |
Correct |
291 ms |
1864 KB |
Output is correct |
53 |
Correct |
258 ms |
1728 KB |
Output is correct |
54 |
Correct |
248 ms |
1864 KB |
Output is correct |
55 |
Correct |
245 ms |
1708 KB |
Output is correct |
56 |
Correct |
261 ms |
1828 KB |
Output is correct |
57 |
Correct |
250 ms |
1864 KB |
Output is correct |
58 |
Correct |
247 ms |
1864 KB |
Output is correct |
59 |
Correct |
251 ms |
1724 KB |
Output is correct |
60 |
Correct |
261 ms |
1864 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 |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 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 |
504 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
5 ms |
848 KB |
Output is correct |
17 |
Correct |
5 ms |
848 KB |
Output is correct |
18 |
Correct |
5 ms |
848 KB |
Output is correct |
19 |
Correct |
4 ms |
1088 KB |
Output is correct |
20 |
Correct |
4 ms |
1248 KB |
Output is correct |
21 |
Correct |
4 ms |
968 KB |
Output is correct |
22 |
Correct |
4 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 |
1092 KB |
Output is correct |
26 |
Correct |
4 ms |
892 KB |
Output is correct |
27 |
Correct |
4 ms |
848 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 |
546 ms |
524288 KB |
Execution killed with signal 9 |
32 |
Halted |
0 ms |
0 KB |
- |