fork download
  1. #include <bits/stdc++.h>
  2. #define mp make_pair
  3. #define pii pair<int, int>
  4.  
  5. using namespace std;
  6.  
  7. int val[100001] = {0}, n, ans = 0, start[100001] = {0}, last[100001] = {0};
  8.  
  9. void add(int pos){
  10. val[pos] = 1;
  11. start[pos] = last[pos] = pos;
  12. if(val[pos - 1] == 1){
  13. last[start[pos - 1]] = pos;
  14. start[pos] = start[pos - 1];
  15. }
  16. if(pos < n && val[pos+1] == 1){
  17. start[last[pos+1]] = start[pos];
  18. last[pos] = last[pos+1];
  19. last[start[pos]] = last[pos+1];
  20. }
  21. int cur = last[pos] - start[pos] + 1;
  22. ans = max(ans, cur);
  23. }
  24.  
  25. int main(){
  26. int q;
  27. cin >> n >> q;
  28. string s;
  29. cin >> s;
  30. for(int j = 1; j <= n; j++)
  31. if(s[j-1] == '0') val[j] = 0;
  32. else{
  33. val[j] = 1;
  34. add(j);
  35. }
  36.  
  37. while(q--){
  38. int t;
  39. cin >> t;
  40. if(t == 1) cout << ans << endl;
  41. else{
  42. int x;
  43. cin >> x;
  44. if(val[x] == 1) continue;
  45. val[x] = 1;
  46. add(x);
  47. }
  48. }
  49. return 0;
  50. }
Success #stdin #stdout 0s 4448KB
stdin
5 7
00000
1
2 3
1
2 5
1
2 4
1
stdout
0
1
1
3