結果

問題 No.2592 おでぶなおばけさん 2
ユーザー 👑 hos.lyrichos.lyric
提出日時 2023-12-20 00:25:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 2,500 ms
コード長 3,432 bytes
コンパイル時間 2,165 ms
コンパイル使用メモリ 123,792 KB
実行使用メモリ 21,508 KB
最終ジャッジ日時 2023-12-20 11:14:56
合計ジャッジ時間 15,467 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 31 ms
11,052 KB
testcase_02 AC 42 ms
9,356 KB
testcase_03 AC 17 ms
6,676 KB
testcase_04 AC 17 ms
6,676 KB
testcase_05 AC 77 ms
20,392 KB
testcase_06 AC 42 ms
9,808 KB
testcase_07 AC 52 ms
9,696 KB
testcase_08 AC 51 ms
12,832 KB
testcase_09 AC 18 ms
6,676 KB
testcase_10 AC 22 ms
6,676 KB
testcase_11 AC 53 ms
13,084 KB
testcase_12 AC 12 ms
6,676 KB
testcase_13 AC 97 ms
14,908 KB
testcase_14 AC 98 ms
15,116 KB
testcase_15 AC 78 ms
11,240 KB
testcase_16 AC 98 ms
15,076 KB
testcase_17 AC 107 ms
17,020 KB
testcase_18 AC 77 ms
11,284 KB
testcase_19 AC 66 ms
8,944 KB
testcase_20 AC 74 ms
11,588 KB
testcase_21 AC 60 ms
8,296 KB
testcase_22 AC 91 ms
15,780 KB
testcase_23 AC 108 ms
17,228 KB
testcase_24 AC 88 ms
13,104 KB
testcase_25 AC 60 ms
7,424 KB
testcase_26 AC 60 ms
7,552 KB
testcase_27 AC 128 ms
21,508 KB
testcase_28 AC 128 ms
21,508 KB
testcase_29 AC 130 ms
21,508 KB
testcase_30 AC 128 ms
21,508 KB
testcase_31 AC 131 ms
21,508 KB
testcase_32 AC 130 ms
21,508 KB
testcase_33 AC 130 ms
21,508 KB
testcase_34 AC 127 ms
21,508 KB
testcase_35 AC 129 ms
21,508 KB
testcase_36 AC 129 ms
21,508 KB
testcase_37 AC 130 ms
21,508 KB
testcase_38 AC 129 ms
21,508 KB
testcase_39 AC 127 ms
21,508 KB
testcase_40 AC 126 ms
21,508 KB
testcase_41 AC 134 ms
21,508 KB
testcase_42 AC 129 ms
21,508 KB
testcase_43 AC 130 ms
21,508 KB
testcase_44 AC 132 ms
21,508 KB
testcase_45 AC 127 ms
21,508 KB
testcase_46 AC 124 ms
21,508 KB
testcase_47 AC 121 ms
21,508 KB
testcase_48 AC 122 ms
21,508 KB
testcase_49 AC 120 ms
21,508 KB
testcase_50 AC 124 ms
21,508 KB
testcase_51 AC 121 ms
21,508 KB
testcase_52 AC 126 ms
21,508 KB
testcase_53 AC 129 ms
21,508 KB
testcase_54 AC 127 ms
21,508 KB
testcase_55 AC 128 ms
21,508 KB
testcase_56 AC 125 ms
21,508 KB
testcase_57 AC 62 ms
20,724 KB
testcase_58 AC 128 ms
21,508 KB
testcase_59 AC 124 ms
21,508 KB
testcase_60 AC 126 ms
21,508 KB
testcase_61 AC 128 ms
21,508 KB
testcase_62 AC 128 ms
21,508 KB
testcase_63 AC 127 ms
21,508 KB
testcase_64 AC 128 ms
21,508 KB
testcase_65 AC 123 ms
21,508 KB
testcase_66 AC 124 ms
21,508 KB
testcase_67 AC 125 ms
21,508 KB
testcase_68 AC 125 ms
21,508 KB
testcase_69 AC 126 ms
21,508 KB
testcase_70 AC 122 ms
21,508 KB
testcase_71 AC 126 ms
21,508 KB
testcase_72 AC 126 ms
21,508 KB
testcase_73 AC 125 ms
21,508 KB
testcase_74 AC 2 ms
6,676 KB
testcase_75 AC 127 ms
21,508 KB
testcase_76 AC 129 ms
21,508 KB
testcase_77 AC 129 ms
21,508 KB
testcase_78 AC 130 ms
21,508 KB
testcase_79 AC 132 ms
21,508 KB
testcase_80 AC 129 ms
21,508 KB
testcase_81 AC 130 ms
21,508 KB
testcase_82 AC 131 ms
21,508 KB
testcase_83 AC 133 ms
21,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#include <chrono>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


template<class T> T power(T a, Int e, T m) {
  T b = 1;
  for (; e; e >>= 1) {
    if (e & 1) b = (b * a) % m;
    a = (a * a) % m;
  }
  return b;
}

// Checks if n is a prime using Miller-Rabin test
bool isPrime(Int n) {
  if (n <= 1 || n % 2 == 0) return (n == 2);
  const int s = __builtin_ctzll(n - 1);
  const Int d = (n - 1) >> s;
  // http://miller-rabin.appspot.com/
  for (const Int base : {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) {
    __int128 a = base % n;
    if (a == 0) continue;
    a = power<__int128>(a, d, n);
    if (a == 1 || a == n - 1) continue;
    bool ok = false;
    for (int i = 0; i < s - 1; ++i) {
      a = (a * a) % n;
      if (a == n - 1) {
        ok = true;
        break;
      }
    }
    if (!ok) return false;
  }
  return true;
}


#ifdef LOCAL
mt19937_64 rng(58);
#else
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#endif

// [l, r]
Int randLong(Int l, Int r) {
  return uniform_int_distribution<Int>(l, r)(rng);
}


constexpr int H = 10;
Int M[H];

int N, Q;
Int K;
vector<Int> A;
vector<int> L, R;

int main() {
  for (int h = 0; h < H; ++h) {
    for (; ; ) {
      M[h] = randLong(1LL << 30, 1LL << 31);
      if (isPrime(M[h])) {
        break;
      }
    }
  }
cerr<<"M = ";pv(M,M+H);
  
  for (; ~scanf("%d%d%lld", &N, &Q, &K); ) {
    A.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%lld", &A[i]);
    }
    L.resize(Q);
    R.resize(Q);
    for (int q = 0; q < Q; ++q) {
      scanf("%d%d", &L[q], &R[q]);
      --L[q];
    }
    
    vector<vector<Int>> KK(H, vector<Int>(N + 1));
    vector<vector<Int>> fss(H, vector<Int>(N + 1, 0));
    for (int h = 0; h < H; ++h) {
      const Int k = K % M[h];
      KK[h][0] = 1;
      for (int i = 1; i <= N; ++i) {
        KK[h][i] = (KK[h][i - 1] * k) % M[h];
      }
      for (int i = N; --i >= 0; ) {
        fss[h][i] = (A[i] + k * fss[h][i + 1]) % M[h];
      }
    }
    
    for (int q = 0; q < Q; ++q) {
      bool ans = false;
      for (int h = 0; h < H; ++h) {
        Int f = (fss[h][L[q]] - KK[h][R[q] - L[q]] * fss[h][R[q]]) % M[h];
        ans = ans || f;
      }
      puts(ans ? "Yes" : "No");
    }
  }
  return 0;
}
0