fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n, q, t, l, r;
  4. deque<int> e; char c;
  5. long long tong;
  6.  
  7. int main()
  8. {
  9. cin >> n >> q;
  10. for(int i = 0; i < n; i++)
  11. {
  12. cin >> c;
  13. if(c == 'c') e.push_back(1);
  14. else e.push_back(0);
  15. }
  16. while(q--)
  17. {
  18. cin >> t >> l >> r;
  19. l--; r--;
  20. if(t == 1) for(int i = l; i <= r; i++) e[i] = 1-e[i];
  21. else
  22. {
  23. tong = 0;
  24. for(int i = l; i <= r; i++)
  25. {
  26. if(e[i])
  27. {
  28. while(e[i] && i >= l)
  29. {
  30. i--;
  31. tong += e[i];
  32. e.pop_back();
  33. r--;
  34. }
  35. tong++;
  36. }
  37. }
  38. cout << tong << '\n';
  39. }
  40. }
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty