QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#400767#7782. Ursa MinorXiaohubaWA 2ms11012kbC++237.1kb2024-04-27 15:58:012024-04-27 15:58:01

Judging History

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

  • [2024-04-27 15:58:01]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11012kb
  • [2024-04-27 15:58:01]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

// #define LOCK_GETCHAR
#define USE_INT_128

#if __cplusplus < 201400
#warning "Please use c++14 or higher."
#define CONSTEXPR_FUNC
#define ENABLE_IF_INT
#else
#define CONSTEXPR_FUNC constexpr
#define ENABLE_IF_INT , enable_if_t<_is_integer<T>, int> = 0
template <class T> constexpr bool _is_integer = numeric_limits<T>::is_integer;
template <> constexpr bool _is_integer<bool> = false;
template <> constexpr bool _is_integer<char> = false;
#ifdef USE_INT_128
template <> constexpr bool _is_integer<__int128> = true;
template <> constexpr bool _is_integer<__uint128_t> = true;
#endif
template <class T ENABLE_IF_INT>
constexpr T INF = numeric_limits<T>::max() >> 1;
#endif

#if !defined(_WIN32) && !defined(LOCK_GETCHAR)
#define getchar getchar_unlocked
#endif

#define il inline
#define mkp make_pair
#define fi first
#define se second
#define For(i, j, k) for (decltype(j - k) i = (j); i <= (k); ++i)     // NOLINT
#define ForDown(i, j, k) for (decltype(j - k) i = (j); i >= (k); --i) // NOLINT
#define pb push_back
#define eb emplace_back
#ifndef ONLINE_JUDGE
#define FileIO(filename)                                                       \
  freopen(filename ".in", "r", stdin);                                         \
  freopen(filename ".out", "w", stdout)
#else
#define FileIO(filename) void(0)
#endif

using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using db = double;
using ldb = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#ifdef USE_INT_128
using lll = __int128_t;
using ulll = __uint128_t;
#endif

// clang-format off
template<typename T> constexpr il T sq(const T & x){ return x * x; }
template<typename T> CONSTEXPR_FUNC il void cmin(T & x, const T &y){ x = min(x, y); }
template<typename T> CONSTEXPR_FUNC il void cmax(T & x, const T &y){ x = max(x, y);}
template<typename T> CONSTEXPR_FUNC il T qpow(T x, ull y, T mod){T ans = 1; x %= mod; while (y) { if(y & 1)(ans *= x) %= mod;(x *= x) %= mod; y >>= 1;} return ans;}
template<typename T> CONSTEXPR_FUNC il T qpow(T x, ull y){T ans = 1; while (y) {if(y & 1) ans *= x;x *= x;y >>= 1;} return ans;}
template<typename T ENABLE_IF_INT> il void read(T &x){ x = 0; int f = 1; int c = getchar(); while(!isdigit(c)) {if (c == '-') f = -1;c = getchar();} while(isdigit(c)) {x = x * 10 + c - '0';c = getchar();} x *= f;}
template<typename T, typename ... Args> il void read(T &x, Args &... y){ read(x); read(y...); }
// clang-format on

// File head end

namespace {

constexpr uint64_t seed() {
  auto rnd_str = __FILE__ __DATE__ __TIME__;
  uint64_t hash = 0;
  for (int i = 0, len = strlen(rnd_str); i < len; i++)
    (hash *= 131) += rnd_str[i];
  return hash * 0x2545F4914F6CDD1D;
}
constexpr uint64_t xorshift64(uint64_t state) {
  uint64_t x = state;
  x ^= x >> 12;
  x ^= x << 25;
  x ^= x >> 27;
  return x;
}
template <unsigned iter>
constexpr inline uint64_t random_value = xorshift64(random_value<iter - 1>);
template <> constexpr inline uint64_t random_value<0> = seed();
template <unsigned iter, uint64_t l, uint64_t r> constexpr uint64_t rnd() {
  static_assert(l <= r);
  return random_value<iter> % (r - l + 1) + l;
}

constexpr ll MAXN = 2e5 + 5, B = 512, mod = 100000000001647,
             base = rnd<233, 233333333333, mod - 233333333333>();
constexpr db rp = 1.0 / mod;
int n, q;
ll a[MAXN], sum[B + 1][B + 1], sum2[MAXN], pw[MAXN], pw_inv[MAXN],
    sum0[B + 1][B + 1], dlt2[B + 1];
constexpr il void add(ll &x, ll y) { ((x += y) >= mod) ? (x -= mod) : 0ll; }
constexpr il void reduce(ll &x) { (x >= mod) ? (x -= mod) : 0ll; }
constexpr il ll mul(ll x, ll y) {
  reduce(x);
  auto c = x * y - ll(rp * x * y + 0.5) * mod;
  (c < 0) ? (c += mod) : 0ll;
  return c;
}

il ll calc1(int x) {
  constexpr ll inv = qpow(ulll(base - 1), mod - 2, ulll(mod));
  return mul(pw[x] - 1, inv);
}
il ll qry0(int L, int R, int x) {
  int u = L / B, v = R / B;
  ll ans1 = 0, ans2 = 0, ans3 = 0;
  if (u == v) {
    For(i, L, R) if (!(i % x)) add(ans1, a[i]);
    return ans1;
  }
  For(i, L, (u + 1) * B - 1) if (!(i % x)) add(ans1, a[i]);
  For(i, v * B, R) if (!(i % x)) add(ans2, a[i]);
  For(i, u + 1, v - 1) add(ans3, sum0[x][i]);
  return (ans1 + ans2 + ans3) % mod;
}
il ll qry1(int L, int R, int x) {
  int u = L / B, v = R / B;
  ll ans1 = 0, ans2 = 0, ans3 = 0;
  if (u == v) {
    For(i, L, R) add(ans1, mul(a[i], pw[i % x]));
    return ans1;
  }
  For(i, L, (u + 1) * B - 1) add(ans1, mul(a[i], pw[i % x]));
  For(i, v * B, R) add(ans2, mul(a[i], pw[i % x]));
#pragma GCC unroll(8)
  For(i, u + 1, v - 1) add(ans3, sum[x][i]);
  return (ans1 + ans2 + ans3) % mod;
}
il ll sum0_brute(int L, int R, int x) {
  L = ((L - 1) / x + 1) * x;
  ll ans = 0;
#pragma GCC unroll(8)
  for (int i = L; i <= R; i += x)
    add(ans, a[i]);
  return ans;
}
#define unlikely(cond) (__builtin_expect((cond), 0))
il ll qry2(int L, int R, int x) {
  int p = ((L - 1) / x + 1) * x;
  auto preSum = [&](int pos) {
    return unlikely(!pos) ? 0ll : (dlt2[pos / B] + sum2[pos]) % mod;
  };
  ll ans = mul(mod + preSum(p - 1) - preSum(L - 1), pw_inv[L - L % x]);

  for (int i = p; i <= R; i += x)
    add(ans, mul(mod + preSum(min(i + x - 1, R)) - preSum(i - 1),
                 pw_inv[i - i % x]));
  return ans;
}

il void Main() {
  FileIO("circle");
  read(n, q);
  For(i, 1, n) read(a[i]), (a[i] += mod) %= mod;

  constexpr ll inv0 = qpow(ulll(base), mod - 2, ulll(mod));
  pw[0] = pw_inv[0] = 1;
  For(i, 1, n) pw[i] = mul(pw[i - 1], base),
               pw_inv[i] = mul(pw_inv[i - 1], inv0);

  cerr << "Finish init1 " << 1. * clock() / CLOCKS_PER_SEC << '\n';

  For(i, 1, B) {
    For(j, 1, n) { add(sum[i][j / B], mul(a[j], pw[j % i])); }
    For(j, 1, n / i) { add(sum0[i][(j * i) / B], a[j * i]); }
  }

  cerr << "Finish init2 " << 1. * clock() / CLOCKS_PER_SEC << '\n';

  For(i, 0, n / B) {
    sum2[i * B] = mul(a[i * B], pw[i * B]);
    dlt2[i] = (!i ? 0ll : (dlt2[i - 1] + sum2[i * B - 1]));
    For(j, i * B + 1, min(1ll * n, (i + 1) * B - 1)) sum2[j] =
        (sum2[j - 1] + mul(a[j], pw[j])) % mod;
  }

  cerr << "Finish init3 " << 1. * clock() / CLOCKS_PER_SEC << '\n';

  while (q--) {
    ll op, x, y, z;
    read(op, x, y);
    if (op == 1) {
      (y += mod) %= mod;
      For(i, 1, B) {
        add(sum[i][x / B], mul(y - a[x] + mod, pw[x % i]));
        if (!(x % i))
          add(sum0[i][x / B], y - a[x] + mod);
      }
      For(i, x, min(1ll * n, (x / B + 1) * B - 1))
          add(sum2[i], mul(y - a[x] + mod, pw[x]));
      For(i, x / B + 1, n / B) add(dlt2[i], mul(y - a[x] + mod, pw[x]));
      a[x] = y;
    } else {
      read(z);
      int g = y - x + 1, tmp = 0;
      For(i, 1, z) read(tmp), g = gcd(g, tmp);
      if (g <= B) {
        ll v1 = qry1(x, y, g), v2 = mul(qry0(x, y, g), calc1(g));
        puts(v1 == v2 ? "YES" : "NO");
      } else {
        ll v1 = qry2(x, y, g), v2 = mul(sum0_brute(x, y, g), calc1(g));
        puts(v1 == v2 ? "YES" : "NO");
      }
    }
  }
}
} // namespace

signed main() { return Main(), 0; }

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 11012kb

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
YES
YES

result:

wrong answer 1st words differ - expected: 'Yes', found: 'YES'