#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 IT {
vector<pii> tr;
IT (int sz) : tr(4 * sz) {}
pii opr (pii a, pii b) {
return {mul(a.first, b.first), add(mul(a.first, b.second), a.second)};
}
void update (int pos, pii 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] = opr(tr[2 * k], tr[2 * k + 1]);
}
bool valid() { return tr[1].second == 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, make_pair(sub(0, 1), val), 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, make_pair(sub(0, 1), val), 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 |
336 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 |
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 |
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 |
336 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 |
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 |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
504 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
372 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
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 |
336 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 |
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 |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
504 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
372 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
227 ms |
35724 KB |
Output is correct |
32 |
Correct |
220 ms |
35688 KB |
Output is correct |
33 |
Correct |
222 ms |
35604 KB |
Output is correct |
34 |
Correct |
236 ms |
35560 KB |
Output is correct |
35 |
Correct |
231 ms |
35536 KB |
Output is correct |
36 |
Correct |
225 ms |
36168 KB |
Output is correct |
37 |
Correct |
251 ms |
36248 KB |
Output is correct |
38 |
Correct |
228 ms |
35816 KB |
Output is correct |
39 |
Correct |
223 ms |
35916 KB |
Output is correct |
40 |
Correct |
238 ms |
36264 KB |
Output is correct |
41 |
Correct |
231 ms |
35552 KB |
Output is correct |
42 |
Correct |
223 ms |
35536 KB |
Output is correct |
43 |
Correct |
220 ms |
36052 KB |
Output is correct |
44 |
Correct |
220 ms |
35576 KB |
Output is correct |
45 |
Correct |
212 ms |
35556 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 |
336 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 |
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 |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
15 ms |
592 KB |
Output is correct |
17 |
Correct |
10 ms |
592 KB |
Output is correct |
18 |
Correct |
10 ms |
516 KB |
Output is correct |
19 |
Correct |
11 ms |
752 KB |
Output is correct |
20 |
Correct |
10 ms |
592 KB |
Output is correct |
21 |
Correct |
10 ms |
592 KB |
Output is correct |
22 |
Correct |
10 ms |
592 KB |
Output is correct |
23 |
Correct |
10 ms |
592 KB |
Output is correct |
24 |
Correct |
10 ms |
596 KB |
Output is correct |
25 |
Correct |
10 ms |
604 KB |
Output is correct |
26 |
Correct |
10 ms |
592 KB |
Output is correct |
27 |
Correct |
12 ms |
592 KB |
Output is correct |
28 |
Correct |
11 ms |
592 KB |
Output is correct |
29 |
Correct |
10 ms |
592 KB |
Output is correct |
30 |
Correct |
10 ms |
592 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 |
336 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 |
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 |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
504 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
372 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
15 ms |
592 KB |
Output is correct |
32 |
Correct |
10 ms |
592 KB |
Output is correct |
33 |
Correct |
10 ms |
516 KB |
Output is correct |
34 |
Correct |
11 ms |
752 KB |
Output is correct |
35 |
Correct |
10 ms |
592 KB |
Output is correct |
36 |
Correct |
10 ms |
592 KB |
Output is correct |
37 |
Correct |
10 ms |
592 KB |
Output is correct |
38 |
Correct |
10 ms |
592 KB |
Output is correct |
39 |
Correct |
10 ms |
596 KB |
Output is correct |
40 |
Correct |
10 ms |
604 KB |
Output is correct |
41 |
Correct |
10 ms |
592 KB |
Output is correct |
42 |
Correct |
12 ms |
592 KB |
Output is correct |
43 |
Correct |
11 ms |
592 KB |
Output is correct |
44 |
Correct |
10 ms |
592 KB |
Output is correct |
45 |
Correct |
10 ms |
592 KB |
Output is correct |
46 |
Correct |
20 ms |
772 KB |
Output is correct |
47 |
Correct |
22 ms |
592 KB |
Output is correct |
48 |
Correct |
22 ms |
592 KB |
Output is correct |
49 |
Correct |
20 ms |
724 KB |
Output is correct |
50 |
Correct |
20 ms |
592 KB |
Output is correct |
51 |
Correct |
23 ms |
592 KB |
Output is correct |
52 |
Correct |
25 ms |
720 KB |
Output is correct |
53 |
Correct |
21 ms |
592 KB |
Output is correct |
54 |
Correct |
21 ms |
576 KB |
Output is correct |
55 |
Correct |
22 ms |
592 KB |
Output is correct |
56 |
Correct |
21 ms |
592 KB |
Output is correct |
57 |
Correct |
22 ms |
592 KB |
Output is correct |
58 |
Correct |
22 ms |
592 KB |
Output is correct |
59 |
Correct |
24 ms |
592 KB |
Output is correct |
60 |
Correct |
26 ms |
592 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 |
336 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 |
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 |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
504 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
372 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
227 ms |
35724 KB |
Output is correct |
32 |
Correct |
220 ms |
35688 KB |
Output is correct |
33 |
Correct |
222 ms |
35604 KB |
Output is correct |
34 |
Correct |
236 ms |
35560 KB |
Output is correct |
35 |
Correct |
231 ms |
35536 KB |
Output is correct |
36 |
Correct |
225 ms |
36168 KB |
Output is correct |
37 |
Correct |
251 ms |
36248 KB |
Output is correct |
38 |
Correct |
228 ms |
35816 KB |
Output is correct |
39 |
Correct |
223 ms |
35916 KB |
Output is correct |
40 |
Correct |
238 ms |
36264 KB |
Output is correct |
41 |
Correct |
231 ms |
35552 KB |
Output is correct |
42 |
Correct |
223 ms |
35536 KB |
Output is correct |
43 |
Correct |
220 ms |
36052 KB |
Output is correct |
44 |
Correct |
220 ms |
35576 KB |
Output is correct |
45 |
Correct |
212 ms |
35556 KB |
Output is correct |
46 |
Correct |
15 ms |
592 KB |
Output is correct |
47 |
Correct |
10 ms |
592 KB |
Output is correct |
48 |
Correct |
10 ms |
516 KB |
Output is correct |
49 |
Correct |
11 ms |
752 KB |
Output is correct |
50 |
Correct |
10 ms |
592 KB |
Output is correct |
51 |
Correct |
10 ms |
592 KB |
Output is correct |
52 |
Correct |
10 ms |
592 KB |
Output is correct |
53 |
Correct |
10 ms |
592 KB |
Output is correct |
54 |
Correct |
10 ms |
596 KB |
Output is correct |
55 |
Correct |
10 ms |
604 KB |
Output is correct |
56 |
Correct |
10 ms |
592 KB |
Output is correct |
57 |
Correct |
12 ms |
592 KB |
Output is correct |
58 |
Correct |
11 ms |
592 KB |
Output is correct |
59 |
Correct |
10 ms |
592 KB |
Output is correct |
60 |
Correct |
10 ms |
592 KB |
Output is correct |
61 |
Correct |
20 ms |
772 KB |
Output is correct |
62 |
Correct |
22 ms |
592 KB |
Output is correct |
63 |
Correct |
22 ms |
592 KB |
Output is correct |
64 |
Correct |
20 ms |
724 KB |
Output is correct |
65 |
Correct |
20 ms |
592 KB |
Output is correct |
66 |
Correct |
23 ms |
592 KB |
Output is correct |
67 |
Correct |
25 ms |
720 KB |
Output is correct |
68 |
Correct |
21 ms |
592 KB |
Output is correct |
69 |
Correct |
21 ms |
576 KB |
Output is correct |
70 |
Correct |
22 ms |
592 KB |
Output is correct |
71 |
Correct |
21 ms |
592 KB |
Output is correct |
72 |
Correct |
22 ms |
592 KB |
Output is correct |
73 |
Correct |
22 ms |
592 KB |
Output is correct |
74 |
Correct |
24 ms |
592 KB |
Output is correct |
75 |
Correct |
26 ms |
592 KB |
Output is correct |
76 |
Correct |
699 ms |
47368 KB |
Output is correct |
77 |
Correct |
686 ms |
47668 KB |
Output is correct |
78 |
Correct |
734 ms |
47388 KB |
Output is correct |
79 |
Correct |
696 ms |
47312 KB |
Output is correct |
80 |
Correct |
720 ms |
47332 KB |
Output is correct |
81 |
Correct |
642 ms |
47460 KB |
Output is correct |
82 |
Correct |
646 ms |
47320 KB |
Output is correct |
83 |
Correct |
652 ms |
47324 KB |
Output is correct |
84 |
Correct |
719 ms |
47320 KB |
Output is correct |
85 |
Correct |
622 ms |
47484 KB |
Output is correct |
86 |
Correct |
707 ms |
47832 KB |
Output is correct |
87 |
Correct |
715 ms |
47668 KB |
Output is correct |
88 |
Correct |
748 ms |
47636 KB |
Output is correct |
89 |
Correct |
676 ms |
47320 KB |
Output is correct |
90 |
Correct |
733 ms |
47668 KB |
Output is correct |