比赛 期末考试0 评测结果 ATTTTTTTTT
题目名称 我能在摸鱼被发现的情况下躲避教练的视奸吗 最终得分 10
用户昵称 LikableP 运行时间 27.931 s
代码语言 C++ 内存使用 12.48 MiB
提交时间 2026-02-07 11:07:52
显示代码纯文本
#include <cstdio>
#include <cctype>

const int BUFSIZE = 1 << 25;

char buf[BUFSIZE], *p1, *p2;
char gc() {
  if (p1 == p2) {
    p2 = (p1 = buf) + fread(buf, 1, BUFSIZE, stdin);
    if (p1 == p2) return EOF;
  }
  return *p1++;
}

template <typename T> T read() {
  T res = 0;
  char ch = gc();
  for (; !isdigit(ch); ch = gc());
  for (; isdigit(ch); ch = gc()) res = (res << 3) + (res << 1) + (ch ^ 48);
  return res;
}

template <typename T> T GCD(T x, T y) {
  return y == 0 ? x : GCD(y, x % y);
}

#include <numeric>
#include <algorithm>

const int MAXN = 5e5 + 10;
const int MAXM = 5e6 + 10;

int n, m;
unsigned int a[MAXN], b[MAXN], c[MAXN];
unsigned int prea[MAXN], preb[MAXN], prec[MAXN];
bool special = true;

int main() {
#ifdef LOCAL
  freopen("!input.in", "r", stdin);
  freopen("!output.out", "w", stdout);
#else
  freopen("shijian.in", "r", stdin);
  freopen("shijian.out", "w", stdout);
#endif
  
  n = read<int>(), m = read<int>();
  for (int i = 1; i <= n; ++i) a[i] = read<unsigned int>();
  for (int i = 1; i <= n; ++i) b[i] = read<unsigned int>(), special &= (b[i] == 1);
  for (int i = 1; i <= n; ++i) c[i] = read<unsigned int>();

  prea[1] = a[1], preb[1] = b[1], prec[1] = c[1];
  for (int i = 2; i <= n; ++i) prea[i] = a[i] & prea[i - 1];
  for (int i = 2; i <= n; ++i) preb[i] = b[i] | preb[i - 1];
  for (int i = 2; i <= n; ++i) prec[i] = GCD(c[i], prec[i - 1]);
  
  while (m--) {
    int l = read<int>(), r = read<int>();
    unsigned int ans = 0;
    for (int ls = l; ls <= r; ++ls) for (int rs = ls; rs <= r; ++rs) {
      unsigned int op1 = std::accumulate(a + ls + 1, a + rs + 1, a[ls], [](unsigned int x, unsigned int y) -> unsigned int { return x & y; });
      unsigned int op2 = std::accumulate(b + ls + 1, b + rs + 1, b[ls], [](unsigned int x, unsigned int y) -> unsigned int { return x | y; });
      unsigned int op3 = std::accumulate(c + ls + 1, c + rs + 1, c[ls], [](unsigned int x, unsigned int y) -> unsigned int { return GCD(x, y); });
      ans += op1 * op2 * op3;
    }
    printf("%u\n", ans);
  }
  return 0;
}