QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#428778#7782. Ursa MinorzlxFTHWA 546ms29616kbC++143.5kb2024-06-01 21:39:452024-06-01 21:39:45

Judging History

你现在查看的是最新测评结果

  • [2024-06-01 21:39:45]
  • 评测
  • 测评结果:WA
  • 用时:546ms
  • 内存:29616kb
  • [2024-06-01 21:39:45]
  • 提交

answer

#include <algorithm>
#include <cctype>
#include <cstdio>

#define debug(...) fprintf(stderr, __VA_ARGS__)

inline int read() {
  int x = 0, f = 1, c;
  while (!isdigit(c = getchar()))
    if (c == '-') f = -1;
  do x = x * 10 + c - '0';
  while (isdigit(c = getchar()));
  return x * f;
}

using LL = long long;
const int N = 2e5 + 5;
const int B = 300;
const int P = 998244353, bas = 19260817;

namespace BIT {
int n;
LL a[N];
void mdf(int x, LL v) {
  for (int i = x; i <= n; i += i & -i)
    a[i] += v;
}
LL qry(int x) {
  LL res = 0;
  for (int i = x; i > 0; i -= i & -i)
    res += a[i];
  return res;
}
}

inline LL qp(LL a, LL b = P - 2) {
  LL c = 1;
  while (b) {
    if (b & 1) c = LL(c) * a % P;
    a = LL(a) * a % P;
    b /= 2;
  }
  return c;
}

int n, m, q;
int a[N];
int st[20][N], b[N];

struct Small {
  LL s[N / B + 5];
  void mdf(int i, LL v) {
    (s[i / B] += v) %= P;
  }
  LL qry(int i) {
    LL res = 0;
    for (int j = 0; j < i / B; ++j) {
      (res += s[j]) %= P;
    }
    return res;
  }
} sm[B + 5];
struct Big {
  LL s1[N], s2[N];
  void mdf(int i, LL v) {
    for (int j = i / B + 1; j <= n / B; ++j)
      (s1[j] += v) %= P;
    for (int j = i; j / B == i / B; ++j)
      (s2[j] += v) %= P;
  }
  LL qry(int i) {
    return (s1[i / B] + s2[i]) % P;
  }
} bg;
LL tar[N], pw[N], ipw[N];
void init() {
  ipw[0] = pw[0] = 1;
  LL s = 0;
  for (int i = 0; i <= n; ++i) {
    ipw[i] = qp(pw[i]);
    s = (s + pw[i]) % P;
    tar[i] = s;
    pw[i + 1] = pw[i] * bas % P;
  }
  for (int i = 1; i <= n; ++i) {
    bg.mdf(i, pw[i] * a[i] % P);
    for (int j = 1; j <= B; ++j) {
      sm[j].mdf(i, pw[i % j] * a[i] % P);
    }
  }
}
void mdf(int p, LL v) {
  bg.mdf(p, LL(pw[p]) * v % P);
  for (int i = 1; i <= B; ++i) {
    sm[i].mdf(p, LL(pw[p % i]) * v % P);
  }
}
bool chk(int l, int r, int bv, LL s) {
  if (bv <= B) {
    LL var = (sm[bv].qry(r) + P - sm[bv].qry(l - 1)) % P;
    for (int i = r / B * B; i <= r; ++i)
      var = (var + pw[i % bv] * a[i]) % P;
    for (int i = (l - 1) / B * B; i < l; ++i)
      var = (var + P - pw[i % bv] * a[i] % P) % P;
    return var == (s / bv) % P * tar[bv - 1] % P;
  } else {
    LL res = 0;
    for (int i = l; i <= r; i += bv) {
      LL var = (bg.qry(i + bv - 1)
          + P - bg.qry(i - 1)) * ipw[i] % P;
      res = (res + var) % P;
    }
    return res == (s / bv) % P * tar[bv - 1] % P;
  }
}

inline int get_gcd(int l, int r) {
  int h = std::__lg(r - l + 1);
  return std::__gcd(st[h][l], st[h][r - (1 << h) + 1]);
}

int main() {
  n = read(), m = read(), q = read();
  BIT::n = n;
  for (int i = 1; i <= n; ++i)
    BIT::mdf(i, a[i] = read());
  init();
  for (int i = 1; i <= m; ++i)
    st[0][i] = b[i] = read();
  for (int j = 1; j <= std::__lg(m); ++j)
    for (int i = 1; i + (1 << j) - 1 <= m; ++i)
      st[j][i] = std::__gcd(st[j - 1][i], st[j - 1][i + (1 << j - 1)]);
  while (q--) {
    char op = getchar();
    while (!isupper(op)) op = getchar();
    if (op == 'U') {
      int p = read(), v = read();
      BIT::mdf(p, v - a[p]);
      mdf(p, v - a[p]);
      a[p] = v;
    } else {
      int l1 = read(), r1 = read(), l2 = read(), r2 = read();
      int av = r1 - l1 + 1, bv = get_gcd(l2, r2);
      LL s = BIT::qry(r1) - BIT::qry(l1 - 1);
      bv = std::__gcd(bv, av);
      if (s % bv) puts("No");
      else
        printf(chk(l1, r1, bv, s) ? "Yes\n" : "No\n");
    }
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 10804kb

input:

6 4 5
1 1 4 5 1 4
3 3 2 4
Q 1 5 1 2
Q 2 5 3 4
U 5 2
Q 1 6 1 2
Q 2 5 3 4

output:

Yes
No
No
Yes

result:

ok 4 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 8760kb

input:

1 1 1
0
1
Q 1 1 1 1

output:

Yes

result:

ok "Yes"

Test #3:

score: 0
Accepted
time: 216ms
memory: 17104kb

input:

2000 2000 200000
1 1 2 0 0 2 0 2 0 0 0 0 0 2 2 1 2 0 0 2 2 2 1 0 1 2 1 2 0 0 1 1 1 2 0 0 2 2 2 2 0 2 0 0 2 1 2 0 0 1 2 2 1 0 2 0 0 0 1 2 2 1 2 2 0 0 1 1 1 0 0 2 0 0 1 1 0 2 2 2 1 0 0 1 0 1 2 2 2 1 1 2 2 1 2 1 0 2 2 3 1 3 2 3 1 0 1 2 0 1 1 1 0 2 2 3 2 0 3 2 3 3 1 2 3 1 2 0 1 0 3 1 0 0 2 0 1 2 1 3 2 2...

output:

Yes
Yes
No
Yes
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
No
Yes
Yes
No
No
No
No
No
Yes
No
No
No
Yes
Yes
No
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
Yes
Yes
No
No
Yes
No
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
No...

result:

ok 100554 tokens

Test #4:

score: 0
Accepted
time: 158ms
memory: 24700kb

input:

1 200000 200000
998244353
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
...

result:

ok 100240 tokens

Test #5:

score: 0
Accepted
time: 150ms
memory: 23408kb

input:

6 131072 200000
0 0 0 0 1000000000 1000000000
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ...

output:

Yes
Yes
Yes
No
No
No
Yes
No
No
No
No
No
Yes
Yes
No
Yes
No
Yes
Yes
Yes
No
No
No
No
No
No
No
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
No
Yes
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
Yes
Yes
No
Yes
N...

result:

ok 100021 tokens

Test #6:

score: -100
Wrong Answer
time: 546ms
memory: 29616kb

input:

200000 200000 200000
490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
Yes
Yes
Yes
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
No
Yes
Yes
No
No
No
No
No
No
No
No
N...

result:

wrong answer 104751st words differ - expected: 'Yes', found: 'No'