比赛 2025暑期集训第6场 评测结果 AWWWWWWWWW
题目名称 Cow Operations 最终得分 10
用户昵称 LikableP 运行时间 0.302 s
代码语言 C++ 内存使用 3.03 MiB
提交时间 2025-07-12 10:05:54
显示代码纯文本
#include <cstdio>
#include <cstring>

template <typename T> T read();
template <typename T> void write(T, char);
template <typename T> T abs(T);
void read(char *);

const int MAXN = 2e5 + 10;

char str[MAXN];
char ans[MAXN];
int pos;
int Q;
int cnt[3][MAXN];

int main() {
  freopen("operation.in", "r", stdin);
  freopen("operation.out", "w", stdout);
  read(str + 1);
  int n = strlen(str + 1);
  for (int i = 1; i <= n; ++i) {
    cnt[0][i] = cnt[0][i - 1];
    cnt[1][i] = cnt[1][i - 1];
    cnt[2][i] = cnt[2][i - 1];
    if (str[i] == 'C') cnt[0][i]++;
    if (str[i] == 'O') cnt[1][i]++;
    if (str[i] == 'W') cnt[2][i]++;
  }

  Q = read<int>();
  while (Q--) {
    int l = read<int>(), r = read<int>();
    int C = cnt[0][r] - cnt[0][l - 1];
    int O = cnt[1][r] - cnt[1][l - 1];
    int W = cnt[2][r] - cnt[2][l - 1];
    if ([](int C, int O, int W) -> bool {
          if (!O && !W && C & 1) return true;
          if (O == W && (((O + W) >> 1) + C) & 1) return true;
          if (!O && C & 1 && !(W & 1)) return true;
          if (!W && C & 1 && !(O & 1)) return true;
          return false;
        }(C, O, W)) {
      ans[++pos] = 'Y';
    } else {
      ans[++pos] = 'N';
    }
  }

  fwrite(ans + 1, sizeof(char), pos, stdout);
  return 0;
}

template <typename T> T abs(T x) {
  return x < 0 ? -x : x;
}

#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