#pragma optimize ("g",on)
#pragma GCC optimize ("inline")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("03")
#include <bits/stdc++.h>
#define pb push_back
#define SS ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
// #define int long long
#define all(v) v.begin(),v.end()
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5 + 1, inf = 1e9, mod = 998244353;
void solve(){
int n, q;
cin >> n >> q;
string a, b;
cin >> a >> b;
a = '!' + a;
b = '!' + b;
int c[n + 1] = {}, d[n + 1] = {};
for(int i = 1; i <= n; i++){
c[i] = ((b[i] - 'a') - (a[i] - 'a') + 26) % 26;
d[i] = ((a[i] - 'a') - (b[i] - 'a') + 26) % 26;
}
bool ok = 0;
for(int i = 1; i <= n; i++){
c[i] -= c[i - 1];
d[i] -= d[i - 1];
// cout << c[i] << ' ';
if((i < n && c[i + 1] < c[i]) && (i < n && d[i + 1] < d[i])){
ok = 1;
break;
}
}
cout << (ok || (c[n] > 0 && d[n] > 0) ? "ne\n" : "da\n");
while(q--){
int p;
char x;
cin >> p >> x;
a[p] = x;
for(int i = 1; i <= n; i++){
c[i] = ((b[i] - 'a') - (a[i] - 'a') + 26) % 26;
d[i] = ((a[i] - 'a') - (b[i] - 'a') + 26) % 26;
}
ok = 0;
for(int i = 1; i <= n; i++){
d[i] -= d[i - 1];
// cout << c[i] << ' ';
if((i < n && c[i + 1] < c[i]) && (i < n && d[i + 1] < d[i])){
ok = 1;
break;
}
}
cout << (ok || (c[n] > 0 && d[n] > 0) ? "ne\n" : "da\n");
}
}
signed main(){
SS
// freopen("trains.in", "r", stdin);
// freopen("trains.out", "w", stdout);
int t = 1;
// cin >> t;
while(t--){
solve();
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |