Advertisement
Guest User

N22

a guest
Jan 15th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int n, m, l, r;
  9.     cin >> n >>m;
  10.     string a;
  11.     cin >> a;
  12.     for (int i = 0; i < m; i++)
  13.     {
  14.         cin >> l >> r;
  15.         for (int j = l - 1; j < r; j++)
  16.         {
  17.             if (a[j] == '1') a[j] = '0';
  18.             else if (a[j] == '0') a[j] = '1';
  19.         }
  20.     }
  21.     int counter = 0;
  22.     int tempcounter = 0;
  23.     for (int i = 0; i < n; i++)
  24.     {
  25.         if (a[i] != a[i+1]) tempcounter++;
  26.         else if (a[i] == a[i+1] && counter < tempcounter)
  27.         {
  28.             counter = tempcounter + 1;
  29.             tempcounter = 0;
  30.         }
  31.     }
  32.     cout << counter;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement