显示代码纯文本
#include <cstdio>
#include <cstring>
#define val(x) (x == 'C' ? 1 : (x == 'O' ? 2 : 3))
template <typename T> T read();
void read(char *);
const int MAXN = 2e5 + 10;
int n;
char str[MAXN], ans[MAXN];
int pos;
int xxor[MAXN];
int Q;
int main() {
freopen("operation.in", "r", stdin);
freopen("operation.out", "w", stdout);
read(str + 1);
n = strlen(str + 1);
for (int i = 1; i <= n; ++i) {
xxor[i] = xxor[i - 1] ^ val(str[i]);
}
Q = read<int>();
while (Q--) {
int l = read<int>(), r = read<int>();
ans[++pos] = "NY"[(xxor[r] ^ xxor[l - 1]) == 1];
}
fwrite(ans + 1, sizeof(char), pos, stdout);
return 0;
}
#define isspace(ch) (ch == ' ' || ch == '\n')
void read(char *str) {
char ch = getchar();
for (; isspace(ch); ch = getchar());
for (; !isspace(ch); ch = getchar()) *str++ = ch;
*str = 0;
}
#undef isspace
#define isdigit(ch) (ch >= '0' && ch <= '9')
template <typename T> T read() {
T res = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) res = (res << 3) + (res << 1) + (ch ^ 48);
return res * f;
}
#undef isdigit