結果

問題 No.854 公平なりんご分配
ユーザー 👑 emthrmemthrm
提出日時 2019-07-26 23:14:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,150 ms / 3,153 ms
コード長 2,788 bytes
コンパイル時間 1,551 ms
コンパイル使用メモリ 141,604 KB
実行使用メモリ 241,476 KB
最終ジャッジ日時 2023-09-15 04:22:28
合計ジャッジ時間 27,756 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 7 ms
4,380 KB
testcase_24 AC 11 ms
5,408 KB
testcase_25 AC 5 ms
4,376 KB
testcase_26 AC 11 ms
5,336 KB
testcase_27 AC 10 ms
5,284 KB
testcase_28 AC 6 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 6 ms
4,376 KB
testcase_31 AC 10 ms
5,064 KB
testcase_32 AC 172 ms
54,348 KB
testcase_33 AC 120 ms
29,832 KB
testcase_34 AC 276 ms
73,568 KB
testcase_35 AC 203 ms
57,728 KB
testcase_36 AC 69 ms
6,116 KB
testcase_37 AC 159 ms
50,468 KB
testcase_38 AC 118 ms
41,276 KB
testcase_39 AC 346 ms
77,180 KB
testcase_40 AC 127 ms
26,088 KB
testcase_41 AC 183 ms
46,916 KB
testcase_42 AC 257 ms
72,456 KB
testcase_43 AC 233 ms
49,340 KB
testcase_44 AC 280 ms
66,548 KB
testcase_45 AC 162 ms
15,276 KB
testcase_46 AC 316 ms
66,416 KB
testcase_47 AC 132 ms
37,528 KB
testcase_48 AC 251 ms
71,052 KB
testcase_49 AC 249 ms
72,492 KB
testcase_50 AC 154 ms
50,544 KB
testcase_51 AC 320 ms
68,648 KB
testcase_52 AC 203 ms
31,548 KB
testcase_53 AC 134 ms
30,892 KB
testcase_54 AC 212 ms
36,740 KB
testcase_55 AC 105 ms
30,992 KB
testcase_56 AC 97 ms
32,452 KB
testcase_57 AC 110 ms
26,888 KB
testcase_58 AC 150 ms
12,588 KB
testcase_59 AC 73 ms
23,648 KB
testcase_60 AC 138 ms
26,792 KB
testcase_61 AC 60 ms
7,468 KB
testcase_62 AC 150 ms
23,064 KB
testcase_63 AC 139 ms
24,472 KB
testcase_64 AC 48 ms
10,928 KB
testcase_65 AC 215 ms
63,912 KB
testcase_66 AC 99 ms
17,996 KB
testcase_67 AC 195 ms
41,284 KB
testcase_68 AC 156 ms
19,044 KB
testcase_69 AC 235 ms
77,132 KB
testcase_70 AC 93 ms
26,336 KB
testcase_71 AC 107 ms
28,520 KB
testcase_72 AC 92 ms
6,428 KB
testcase_73 AC 177 ms
51,720 KB
testcase_74 AC 276 ms
62,788 KB
testcase_75 AC 124 ms
28,592 KB
testcase_76 AC 228 ms
49,244 KB
testcase_77 AC 270 ms
69,832 KB
testcase_78 AC 172 ms
20,860 KB
testcase_79 AC 231 ms
43,172 KB
testcase_80 AC 220 ms
45,652 KB
testcase_81 AC 196 ms
46,764 KB
testcase_82 AC 1,094 ms
241,272 KB
testcase_83 AC 1,137 ms
241,432 KB
testcase_84 AC 1,112 ms
241,476 KB
testcase_85 AC 1,144 ms
241,452 KB
testcase_86 AC 732 ms
241,432 KB
testcase_87 AC 1,109 ms
241,368 KB
testcase_88 AC 1,106 ms
241,452 KB
testcase_89 AC 1,112 ms
241,368 KB
testcase_90 AC 1,107 ms
241,336 KB
testcase_91 AC 1,144 ms
241,328 KB
testcase_92 AC 1,144 ms
241,368 KB
testcase_93 AC 1,150 ms
241,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define int long long
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
vector<bool> sieve_of_eratosthenes(int num) {
  vector<bool> res(num + 1, true);
  if (num >= 0) {
    res[0] = false;
    if (num >= 1) res[1] = false;
  }
  for (int i = 2; i * i <= num; ++i) if (res[i]) {
    for (int j = i * i; j <= num; j += i) res[j] = false;
  }
  return res;
}

vector<int> primes;

vector<pair<int, int> > prime_factorization(int val) {
  vector<pair<int, int> > res;
  for (int e : primes) {
    if (val % e != 0) continue;
    int exponent = 0;
    while (val % e == 0) {
      ++exponent;
      val /= e;
    }
    res.emplace_back(e, exponent);
  }
  if (val != 1) {
    if (val > 2000) res.clear();
    res.emplace_back(val, 1);
  }
  return res;
}

signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<bool> sieve = sieve_of_eratosthenes(2000);
  FOR(i, 1, 2001) {
    if (sieve[i]) primes.emplace_back(i);
  }
  int sz = primes.size();
  map<int, int> mp;
  REP(i, sz) mp[primes[i]] = i;
  vector<vector<int> > a(sz, vector<int>(n + 1, 0));
  vector<int> zero(n + 1, 0);
  REP(i, n) {
    REP(j, sz) a[j][i + 1] = a[j][i];
    zero[i + 1] = zero[i];
    int ai; cin >> ai;
    if (ai == 0) {
      ++zero[i + 1];
    } else {
      auto p = prime_factorization(ai);
      for (auto pr : p) {
        a[mp[pr.first]][i + 1] += pr.second;
      }
    }
  }
  int q; cin >> q;
  while (q--) {
    int p, l, r; cin >> p >> l >> r; --l; --r;
    auto factor = prime_factorization(p);
    bool ok = true;
    if (zero[r + 1] - zero[l] == 0) {
      for (auto pr : factor) {
        if (pr.first > 2000) {
          ok = false;
          break;
        }
        if (a[mp[pr.first]][r + 1] - a[mp[pr.first]][l] < pr.second) {
          ok = false;
          break;
        }
      }
    }
    cout << (ok ? "Yes\n" : "NO\n");
  }
  return 0;
}
0