记录编号 603460 评测结果 AAAAAAAAAA
题目名称 3807.[USACO22 Open Silver]Cow Operations 最终得分 100
用户昵称 GravatarLikableP 是否通过 通过
代码语言 C++ 运行时间 0.301 s
提交时间 2025-07-12 16:40:42 内存使用 2.11 MiB
显示代码纯文本
#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