1
0

CodeForces-914F.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #include <bitset>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. using namespace std;
  6. int main() {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9. constexpr int max_n = 100000;
  10. string s; cin >> s;
  11. vector<bitset<max_n>> position(26);
  12. for (int i = 0; i < static_cast<int>(s.size()); ++i) position[s[i] - 'a'].set(i);
  13. int q; cin >> q;
  14. while (q--) {
  15. int type; cin >> type;
  16. if (type == 1) {
  17. int i; char c; cin >> i >> c; --i;
  18. position[s[i] - 'a'].reset(i);
  19. s[i] = c;
  20. position[s[i] - 'a'].set(i);
  21. } else {
  22. int l, r; string y; cin >> l >> r >> y; --l; --r;
  23. int valid = r - l - static_cast<int>(y.size()) + 2;
  24. if (valid <= 0) { cout << "0\n"; continue; }
  25. bitset<max_n> match;
  26. match.set();
  27. for (int j = 0; j < static_cast<int>(y.size()); ++j) {
  28. match &= position[y[j] - 'a'] >> j;
  29. }
  30. match >>= l;
  31. match <<= max_n - valid; // 只保留移位后下标 [0, valid-1]
  32. cout << match.count() << '\n';
  33. }
  34. }
  35. }