結果

問題 No.854 公平なりんご分配
ユーザー ei1333333ei1333333
提出日時 2019-07-26 22:09:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,281 bytes
コンパイル時間 3,351 ms
コンパイル使用メモリ 214,668 KB
実行使用メモリ 41,044 KB
最終ジャッジ日時 2023-09-15 01:49:23
合計ジャッジ時間 42,541 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,504 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 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,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 4 ms
4,528 KB
testcase_24 AC 10 ms
4,764 KB
testcase_25 AC 5 ms
4,380 KB
testcase_26 AC 10 ms
4,764 KB
testcase_27 AC 6 ms
4,608 KB
testcase_28 AC 6 ms
4,376 KB
testcase_29 AC 3 ms
4,384 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 10 ms
4,568 KB
testcase_32 AC 202 ms
29,080 KB
testcase_33 AC 401 ms
17,312 KB
testcase_34 AC 872 ms
38,756 KB
testcase_35 AC 502 ms
31,316 KB
testcase_36 AC 165 ms
4,904 KB
testcase_37 AC 193 ms
27,500 KB
testcase_38 AC 115 ms
23,180 KB
testcase_39 AC 1,645 ms
40,700 KB
testcase_40 AC 442 ms
15,360 KB
testcase_41 AC 488 ms
25,764 KB
testcase_42 AC 607 ms
38,060 KB
testcase_43 AC 969 ms
26,812 KB
testcase_44 AC 1,018 ms
35,420 KB
testcase_45 AC 692 ms
9,632 KB
testcase_46 AC 1,689 ms
34,976 KB
testcase_47 AC 368 ms
21,164 KB
testcase_48 AC 553 ms
37,568 KB
testcase_49 AC 450 ms
38,144 KB
testcase_50 AC 136 ms
27,268 KB
testcase_51 AC 1,646 ms
36,656 KB
testcase_52 AC 1,165 ms
18,112 KB
testcase_53 AC 515 ms
17,732 KB
testcase_54 AC 1,182 ms
20,660 KB
testcase_55 AC 253 ms
18,104 KB
testcase_56 AC 167 ms
18,632 KB
testcase_57 AC 435 ms
15,660 KB
testcase_58 AC 592 ms
8,232 KB
testcase_59 AC 145 ms
14,064 KB
testcase_60 AC 636 ms
15,728 KB
testcase_61 AC 162 ms
5,620 KB
testcase_62 AC 679 ms
13,884 KB
testcase_63 AC 638 ms
14,540 KB
testcase_64 AC 109 ms
7,480 KB
testcase_65 AC 390 ms
33,996 KB
testcase_66 AC 359 ms
11,248 KB
testcase_67 AC 950 ms
23,168 KB
testcase_68 AC 738 ms
11,744 KB
testcase_69 AC 132 ms
41,044 KB
testcase_70 AC 202 ms
15,536 KB
testcase_71 AC 265 ms
16,716 KB
testcase_72 AC 243 ms
5,168 KB
testcase_73 AC 374 ms
27,800 KB
testcase_74 AC 1,211 ms
33,424 KB
testcase_75 AC 407 ms
16,788 KB
testcase_76 AC 1,068 ms
26,740 KB
testcase_77 AC 941 ms
37,260 KB
testcase_78 AC 870 ms
12,832 KB
testcase_79 AC 1,083 ms
23,660 KB
testcase_80 AC 1,043 ms
24,896 KB
testcase_81 AC 751 ms
25,796 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 && ret) {
    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