結果

問題 No.854 公平なりんご分配
ユーザー ei1333333ei1333333
提出日時 2019-07-26 21:54:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,274 bytes
コンパイル時間 2,476 ms
コンパイル使用メモリ 213,272 KB
実行使用メモリ 41,028 KB
最終ジャッジ日時 2023-09-15 01:16:40
合計ジャッジ時間 50,387 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 5 ms
4,376 KB
testcase_24 AC 11 ms
4,736 KB
testcase_25 AC 5 ms
4,380 KB
testcase_26 AC 11 ms
4,680 KB
testcase_27 AC 6 ms
4,640 KB
testcase_28 AC 5 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 10 ms
4,560 KB
testcase_32 AC 222 ms
29,132 KB
testcase_33 AC 559 ms
17,308 KB
testcase_34 AC 931 ms
38,748 KB
testcase_35 AC 560 ms
31,540 KB
testcase_36 AC 165 ms
5,092 KB
testcase_37 AC 222 ms
27,644 KB
testcase_38 AC 136 ms
23,124 KB
testcase_39 AC 1,857 ms
40,752 KB
testcase_40 AC 695 ms
15,520 KB
testcase_41 AC 667 ms
25,808 KB
testcase_42 AC 719 ms
38,112 KB
testcase_43 AC 1,333 ms
26,864 KB
testcase_44 AC 1,226 ms
35,464 KB
testcase_45 AC 1,157 ms
9,696 KB
testcase_46 AC 1,860 ms
34,956 KB
testcase_47 AC 471 ms
21,224 KB
testcase_48 AC 601 ms
37,684 KB
testcase_49 AC 493 ms
38,112 KB
testcase_50 AC 153 ms
27,476 KB
testcase_51 AC 1,807 ms
36,536 KB
testcase_52 AC 1,613 ms
18,108 KB
testcase_53 AC 727 ms
17,880 KB
testcase_54 AC 1,573 ms
20,692 KB
testcase_55 AC 350 ms
17,940 KB
testcase_56 AC 210 ms
18,664 KB
testcase_57 AC 587 ms
15,772 KB
testcase_58 AC 768 ms
8,332 KB
testcase_59 AC 215 ms
14,092 KB
testcase_60 AC 934 ms
15,732 KB
testcase_61 AC 166 ms
5,740 KB
testcase_62 AC 1,052 ms
13,932 KB
testcase_63 AC 985 ms
14,356 KB
testcase_64 AC 146 ms
7,592 KB
testcase_65 AC 415 ms
33,992 KB
testcase_66 AC 511 ms
11,188 KB
testcase_67 AC 1,188 ms
23,068 KB
testcase_68 AC 1,162 ms
11,704 KB
testcase_69 AC 138 ms
41,028 KB
testcase_70 AC 300 ms
15,508 KB
testcase_71 AC 380 ms
16,828 KB
testcase_72 AC 256 ms
5,108 KB
testcase_73 AC 438 ms
27,820 KB
testcase_74 AC 1,525 ms
33,352 KB
testcase_75 AC 637 ms
16,828 KB
testcase_76 AC 1,378 ms
26,760 KB
testcase_77 AC 1,097 ms
37,368 KB
testcase_78 AC 1,411 ms
12,880 KB
testcase_79 AC 1,585 ms
23,648 KB
testcase_80 AC 1,381 ms
24,916 KB
testcase_81 AC 985 ms
25,896 KB
testcase_82 TLE -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return (ret);
}

int64_t mod_pow(int64_t x, int64_t n, int64_t mod) {
  int64_t ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}

int main() {
  int N;
  cin >> N;
  vector< int64 > A(N);
  cin >> A;

  vector< int > id(202020, -1);
  int ptr = 0;
  vector< vector< int > > sum;
  vector< int > uku;

  for(int i = 0; i < N; i++) {
    auto p = prime_factor(A[i]);
    for(auto &t : p) {
      if(id[t.first] == -1) {
        id[t.first] = ptr++;
        uku.emplace_back(t.first);
        sum.emplace_back(A.size() + 1);
      }
      sum[id[t.first]][i + 1] += t.second;
    }
  }
  for(auto &vs : sum) {
    for(int i = 1; i < vs.size(); i++) vs[i] += vs[i - 1];
  }


  int Q;
  cin >> Q;
  for(int i = 0; i < Q; i++) {
    int p, l, r;
    cin >> p >> l >> r;
    --l;
    int64 ret = 1;
    for(int j = 0; j < sum.size(); j++) {
      ret *= mod_pow(uku[j], sum[j][r] - sum[j][l], p);
      ret %= p;
    }
    if(ret % p == 0) cout << "Yes" << endl;
    else cout << "NO" << endl;
  }
}
0