結果

問題 No.854 公平なりんご分配
ユーザー 👑 jupirojupiro
提出日時 2020-01-26 20:37:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 580 ms / 3,153 ms
コード長 3,311 bytes
コンパイル時間 1,202 ms
コンパイル使用メモリ 124,984 KB
実行使用メモリ 166,592 KB
最終ジャッジ日時 2023-10-12 12:36:23
合計ジャッジ時間 12,890 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,356 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 4 ms
4,352 KB
testcase_23 AC 4 ms
4,420 KB
testcase_24 AC 6 ms
5,048 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 7 ms
5,100 KB
testcase_27 AC 5 ms
5,112 KB
testcase_28 AC 4 ms
4,352 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 4 ms
4,352 KB
testcase_31 AC 6 ms
4,840 KB
testcase_32 AC 48 ms
37,744 KB
testcase_33 AC 59 ms
21,680 KB
testcase_34 AC 103 ms
50,880 KB
testcase_35 AC 72 ms
40,616 KB
testcase_36 AC 57 ms
5,624 KB
testcase_37 AC 47 ms
35,480 KB
testcase_38 AC 35 ms
29,556 KB
testcase_39 AC 162 ms
53,788 KB
testcase_40 AC 70 ms
19,040 KB
testcase_41 AC 73 ms
33,232 KB
testcase_42 AC 90 ms
50,064 KB
testcase_43 AC 115 ms
34,556 KB
testcase_44 AC 118 ms
46,352 KB
testcase_45 AC 128 ms
11,820 KB
testcase_46 AC 158 ms
45,828 KB
testcase_47 AC 56 ms
26,900 KB
testcase_48 AC 82 ms
49,260 KB
testcase_49 AC 77 ms
50,324 KB
testcase_50 AC 43 ms
35,212 KB
testcase_51 AC 155 ms
48,064 KB
testcase_52 AC 84 ms
22,856 KB
testcase_53 AC 42 ms
22,328 KB
testcase_54 AC 84 ms
26,420 KB
testcase_55 AC 29 ms
22,508 KB
testcase_56 AC 28 ms
23,440 KB
testcase_57 AC 47 ms
19,540 KB
testcase_58 AC 109 ms
10,052 KB
testcase_59 AC 24 ms
17,568 KB
testcase_60 AC 60 ms
19,696 KB
testcase_61 AC 30 ms
6,576 KB
testcase_62 AC 77 ms
17,168 KB
testcase_63 AC 43 ms
17,796 KB
testcase_64 AC 22 ms
8,912 KB
testcase_65 AC 56 ms
44,456 KB
testcase_66 AC 43 ms
13,644 KB
testcase_67 AC 63 ms
29,504 KB
testcase_68 AC 64 ms
14,456 KB
testcase_69 AC 56 ms
53,744 KB
testcase_70 AC 25 ms
19,248 KB
testcase_71 AC 29 ms
20,876 KB
testcase_72 AC 76 ms
5,828 KB
testcase_73 AC 43 ms
36,004 KB
testcase_74 AC 81 ms
43,464 KB
testcase_75 AC 48 ms
20,884 KB
testcase_76 AC 58 ms
34,404 KB
testcase_77 AC 67 ms
48,928 KB
testcase_78 AC 100 ms
15,636 KB
testcase_79 AC 77 ms
30,164 KB
testcase_80 AC 76 ms
31,932 KB
testcase_81 AC 51 ms
32,988 KB
testcase_82 AC 209 ms
166,504 KB
testcase_83 AC 540 ms
166,352 KB
testcase_84 AC 526 ms
166,416 KB
testcase_85 AC 571 ms
166,544 KB
testcase_86 AC 185 ms
166,472 KB
testcase_87 AC 206 ms
166,520 KB
testcase_88 AC 206 ms
166,580 KB
testcase_89 AC 209 ms
166,592 KB
testcase_90 AC 207 ms
166,404 KB
testcase_91 AC 206 ms
166,336 KB
testcase_92 AC 561 ms
166,472 KB
testcase_93 AC 580 ms
166,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 2050;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

bool IsPrime[MAX];
int MinFactor[MAX]; vector<int> preprocess(ll n = MAX) {
    vector<int> res;
    for (ll i = 0; i < n; ++i) IsPrime[i] = true, MinFactor[i] = -1;
    IsPrime[0] = false; IsPrime[1] = false;
    MinFactor[0] = 0; MinFactor[1] = 1;
    for (ll i = 2; i < n; ++i) {
        if (IsPrime[i]) {
            MinFactor[i] = i;
            res.push_back(i);
            for (ll j = i * 2; j < n; j += i) {
                IsPrime[j] = false;
                if (MinFactor[j] == -1) MinFactor[j] = i;
            }
        }
    }
    return res;
}

vector<pair<ll, ll> > fast_prime_factor(ll n) {
    vector<pair<ll, ll> > res;
    while (n != 1) {
        ll prime = MinFactor[n];
        ll exp = 0;
        while (MinFactor[n] == prime) {
            ++exp;
            n /= prime;
        }
        res.push_back(make_pair(prime, exp));
    }
    return res;
}
ll cnv[2001];
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
    preprocess();
    vector<ll> pr;
    {
        ll idx = 0;
        for (ll i = 2; i <= 2000; i++) {
            if (IsPrime[i]) {
                pr.push_back(i);
                cnv[i] = idx++;
            }
        }
    }
    ll n; scanf("%lld", &n);
    vector<ll> a(n); for (ll i = 0; i < n; i++) scanf("%lld", &a[i]);
    vector<vector<int>> psum(n + 1, vector<int>(pr.size() + 100));
    vector<ll> z(n + 1);
    for (ll i = 0; i < n; i++) {
        if (a[i] == 0) z[i + 1] = z[i] + 1;
        else {
            z[i + 1] = z[i];
            if (a[i] != 1) {
                vector<pair<ll, ll>> vp = fast_prime_factor(a[i]);
                for (auto p : vp) {
                    psum[i + 1][cnv[p.first]] += p.second;
                }
            }
   
        }
        for (ll j = 0; j < psum[i].size(); j++) {
            psum[i + 1][j] += psum[i][j];
        }
    }
    ll Q; scanf("%lld", &Q);
    while (Q--) {
        ll x, l, r; scanf("%lld %lld %lld", &x, &l, &r);
        if (z[r] - z[l - 1] > 0) puts("Yes");
        else {

            if (x == 1) puts("Yes");
            else {
                for (ll e: pr) {
                    if (x % e != 0) continue;
                    ll cnt = psum[r][cnv[e]] - psum[l - 1][cnv[e]];
                    for (ll i = 0; i < cnt && (x % e == 0); i++) {
                        x /= e;
                    }
                }
                if (x == 1) puts("Yes");
                else puts("NO");
            }
        }
    }
	return 0;
}
0