1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| #include <bits/stdc++.h>
using namespace std;
#define int long long using ll = long long; using ull = unsigned long long; using vvi = vector<vector<int>>; using vi = vector<int>;
ll mypow(ll a, ll b, ll mod = LLONG_MAX) { if (b == 0) return 1; if (b % 2 == 0) { return mypow((a * a) % mod, b / 2, mod); } return (a * mypow((a * a) % mod, b / 2, mod)) % mod; }
void solve(){ int n, mod = 1e9+7, b = 3, q; cin >> n >> q; string s1, s2; cin >> s1; s2 = s1; reverse(s2.begin(), s2.end()); s1 = ' ' + s1; s2 = ' ' + s2; vector<int> t1(n+1, 0), t2(n+1, 0); auto lowbit = [](int x) { return x & (-x); }; auto get = [&](vi& t, int x){ int ret = 0; while(x > 0){ ret += t[x]; ret %= mod; x-= lowbit(x); } return ret; }; auto set = [&](vi& t, int x, int v){ while(x < t.size()){ t[x] += v; t[x] = (t[x] % mod + mod) % mod; x += lowbit(x); } }; auto build = [&](vi& t, string& s){ for(int i=1;i<=n;i++) set(t, i, (s[i] * mypow(b, i, mod)) % mod); }; build(t1, s1); build(t2, s2); while(q--){ int type; cin >> type; if(type == 1){ int x; char c; cin >> x >> c; set(t1, x, ((c - s1[x]) * mypow(b, x, mod)) % mod); s1[x] = c; set(t2, n+1-x, ((c - s2[n+1-x]) * mypow(b, n+1-x, mod)) % mod); s2[n+1-x] = c; } else{ int l, r; cin >> l >> r; int d1 = ((get(t1, r) - get(t1, l-1)) % mod + mod) % mod; d1 = (d1 * mypow(mypow(b, l, mod), mod - 2, mod)) % mod; int d2 = ((get(t2, n + 1 - l) - get(t2, n + 1 - r - 1)) % mod + mod) % mod; d2 = (d2 * mypow(mypow(b, n + 1 - r, mod), mod - 2, mod)) % mod; if(d1 == d2 && s1[l] == s1[r]) cout << "Yes" << endl; else cout << "No" << endl; } } }
signed main() { int fast_io = [](){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; }(); int t = 1; while(t--) { solve(); } return 0; }
|