fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5.  
  6. const int N = 1e5 + 1;
  7. char s[N];
  8.  
  9. int main(int argc, char **argv) {
  10. int T;
  11. scanf("%d", &T);
  12. while (T-- != 0) {
  13. int n, m;
  14. scanf("%d%d%s", &n, &m, s);
  15. int ok = 0, need = (n + 1) >> 1;
  16. for (int i = 0; i * 2 < n; ++i)
  17. if (s[i] == s[n - i - 1])
  18. ++ok;
  19. int res = 0, p;
  20. char c;
  21. for (int i = 0; i < m; ++i) {
  22. scanf("%d %c", &p, &c);
  23. --p;
  24. if (p != n - p - 1 && s[p] != s[n - p - 1] && s[n - p - 1] == c)
  25. ++ok;
  26. if (p != n - p - 1 && s[p] == s[n - p - 1] && s[n - p - 1] != c)
  27. --ok;
  28. s[p] = c;
  29. if (ok == need)
  30. ++res;
  31. }
  32. printf("%d\n", res);
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0s 4516KB
stdin
1
10 7
abcdefdcba
5 x
6 x
4 d
2 d
3 y
8 y
9 d
stdout
3