Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main()
- {
- string s; cin >> s;
- int n = s.size();
- vector <int> x(n + 1), y(n + 1), z(n + 1);
- for (int i = 1; i <= n; i++)
- {
- if (s[i - 1] == 'x')x[i]++;
- else if (s[i - 1] == 'y')y[i]++;
- else if (s[i - 1] == 'z')z[i]++;
- x[i] += x[i - 1];
- y[i] += y[i - 1];
- z[i] += z[i - 1];
- }
- int l, r, t, x2, y2, z2; cin >> t;
- while (t--)
- {
- cin >> l >> r;
- x2 = x[r] - x[l - 1];
- y2 = y[r] - y[l - 1];
- z2 = z[r] - z[l - 1];
- n = max(abs(x2 - y2), max(abs(x2 - z2), abs(y2 - z2)));
- if (n > 1 && r - l >= 2)cout << "NO\n";
- else cout << "YES\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement