Advertisement
JouJoy

J

Dec 12th, 2021
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     string s; cin >> s;
  8.     int n = s.size();
  9.     vector <int> x(n + 1), y(n + 1), z(n + 1);
  10.     for (int i = 1; i <= n; i++)
  11.     {
  12.         if (s[i - 1] == 'x')x[i]++;
  13.         else if (s[i - 1] == 'y')y[i]++;
  14.         else if (s[i - 1] == 'z')z[i]++;
  15.         x[i] += x[i - 1];
  16.         y[i] += y[i - 1];
  17.         z[i] += z[i - 1];
  18.     }
  19.     int l, r, t, x2, y2, z2; cin >> t;
  20.     while (t--)
  21.     {
  22.         cin >> l >> r;
  23.         x2 = x[r] - x[l - 1];
  24.         y2 = y[r] - y[l - 1];
  25.         z2 = z[r] - z[l - 1];
  26.         n = max(abs(x2 - y2), max(abs(x2 - z2), abs(y2 - z2)));
  27.         if (n > 1 && r - l >= 2)cout << "NO\n";
  28.         else cout << "YES\n";
  29.     }
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement