結果

問題 No.854 公平なりんご分配
ユーザー apricityapricity
提出日時 2023-02-03 17:32:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 4,441 bytes
コンパイル時間 1,323 ms
コンパイル使用メモリ 136,008 KB
実行使用メモリ 122,572 KB
最終ジャッジ日時 2023-09-15 12:57:43
合計ジャッジ時間 28,068 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 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,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
testcase_69 RE -
testcase_70 RE -
testcase_71 RE -
testcase_72 RE -
testcase_73 RE -
testcase_74 RE -
testcase_75 RE -
testcase_76 RE -
testcase_77 RE -
testcase_78 RE -
testcase_79 RE -
testcase_80 RE -
testcase_81 RE -
testcase_82 RE -
testcase_83 RE -
testcase_84 RE -
testcase_85 RE -
testcase_86 AC 89 ms
122,104 KB
testcase_87 RE -
testcase_88 RE -
testcase_89 RE -
testcase_90 RE -
testcase_91 RE -
testcase_92 RE -
testcase_93 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<utility>
#include<tuple>
#include<cstdint>
#include<cstdio>
#include<iomanip>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<chrono>
#include<random>
#include<cctype>
#include<cassert>
#include<cstddef>
#include<iterator>
#include<string_view>
#include<type_traits>

#ifdef LOCAL
#  include "debug_print.hpp"
#  define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define debug(...) (static_cast<void>(0))
#endif

using namespace std;
#define rep(i,n) for(decltype(n) i=0; i<(n); i++)
#define rrep(i,n) for(decltype(n) i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(decltype(a) i=(a); i<(b); i++)
#define RFOR(i,a,b) for(decltype(b) i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<typename T> using PQ = priority_queue<T,vector<T>>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void yesno(bool flag) {cout << (flag?"Yes":"NO") << "\n";}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << p.first << " " << p.second;
    return os;
}
template<typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
    is >> p.first >> p.second;
    return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    int s = (int)v.size();
    for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i];
    return os;
}
template<typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (auto &x : v) is >> x;
    return is;
}
void in() {}
template<typename T, class... U>
void in(T &t, U &...u) {
    cin >> t;
    in(u...);
}
void out() { cout << "\n"; }
template<typename T, class... U, char sep = ' '>
void out(const T &t, const U &...u) {
    cout << t;
    if (sizeof...(u)) cout << sep;
    out(u...);
}
void outr() {}
template<typename T, class... U, char sep = ' '>
void outr(const T &t, const U &...u) {
    cout << t;
    outr(u...);
}

struct nsieve{ // [1,n]
    vector<int> minfactor;
    vector<bool> isprime;
    
    nsieve(int n): isprime(n+1,true), minfactor(n+1,-1){
        isprime[1] = false;
        minfactor[1] = 1;

        for(int i=2; i<=n; i++){
            if(!isprime[i]) continue;
            minfactor[i] = i;
            for(int j=i+i; j<=n; j+=i){
                isprime[j] = false;
                if(minfactor[j] == -1) minfactor[j] = i;
            }
        }
    }

    vector<P> factorize(int n){
        vector<P> res;
        while(n > 1){
            int p = minfactor[n];
            int e = 0;
            while(minfactor[n] == p){
                e++;
                n /= p;
            }
            res.pb({p,e});
        }
        return res;
    }
};

int cs[100001][303];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; in(n);
    vector<int> a(n); in(a);
    nsieve f(2001);
    vector<int> pr(2001,-1);
    int cnt = 0;
    FOR(i,1,2001){
        if(f.isprime[i]) pr[i] = cnt++;
    }
    rep(i,n+1)rep(j,cnt) cs[i][j] = 0;
    vector<int> zeros(n+1);
    rep(i,n){
        if(a[i]){
            auto v = f.factorize(a[i]);
            for (auto& [p,e] : v){
                cs[i+1][pr[p]] += e;
            }
        }
        else{
            zeros[i+1] = zeros[i]+1;
        }
        rep(j,cnt) cs[i+1][j] += cs[i][j];
    }
    int q; in(q);
    while(q--){
        int x,l,r; in(x,l,r); l--;
        if(zeros[r]-zeros[l] > 0){
            out("Yes");
            continue;
        }
        auto v = f.factorize(x);
        int ok = 1;
        for(auto& [p,e] : v){
            if(p > 2000){
                ok = 0;
                break;
            }
            else{
                int idx = pr[p];
                if(cs[r][idx]-cs[l][idx] < e){
                    ok = 0;
                    break;
                }
            }
        }
        yesno(ok);
    }
}
0