結果

問題 No.854 公平なりんご分配
ユーザー やむなくやむなく
提出日時 2019-07-26 22:26:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 724 ms / 3,153 ms
コード長 3,362 bytes
コンパイル時間 2,169 ms
コンパイル使用メモリ 180,900 KB
実行使用メモリ 279,968 KB
最終ジャッジ日時 2023-09-15 02:17:12
合計ジャッジ時間 18,229 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 5 ms
5,408 KB
testcase_24 AC 7 ms
5,504 KB
testcase_25 AC 4 ms
4,416 KB
testcase_26 AC 7 ms
5,456 KB
testcase_27 AC 6 ms
5,444 KB
testcase_28 AC 5 ms
4,380 KB
testcase_29 AC 3 ms
4,384 KB
testcase_30 AC 5 ms
4,384 KB
testcase_31 AC 7 ms
5,440 KB
testcase_32 AC 95 ms
68,600 KB
testcase_33 AC 76 ms
36,212 KB
testcase_34 AC 150 ms
78,080 KB
testcase_35 AC 116 ms
70,528 KB
testcase_36 AC 50 ms
7,196 KB
testcase_37 AC 96 ms
66,956 KB
testcase_38 AC 56 ms
41,944 KB
testcase_39 AC 207 ms
80,164 KB
testcase_40 AC 84 ms
34,124 KB
testcase_41 AC 122 ms
65,120 KB
testcase_42 AC 135 ms
77,524 KB
testcase_43 AC 160 ms
66,100 KB
testcase_44 AC 164 ms
74,968 KB
testcase_45 AC 123 ms
19,028 KB
testcase_46 AC 200 ms
74,584 KB
testcase_47 AC 74 ms
39,996 KB
testcase_48 AC 127 ms
76,888 KB
testcase_49 AC 122 ms
77,764 KB
testcase_50 AC 91 ms
66,912 KB
testcase_51 AC 195 ms
76,208 KB
testcase_52 AC 123 ms
36,888 KB
testcase_53 AC 73 ms
36,672 KB
testcase_54 AC 124 ms
39,648 KB
testcase_55 AC 55 ms
36,828 KB
testcase_56 AC 52 ms
37,384 KB
testcase_57 AC 71 ms
34,400 KB
testcase_58 AC 114 ms
12,748 KB
testcase_59 AC 48 ms
32,956 KB
testcase_60 AC 90 ms
34,840 KB
testcase_61 AC 37 ms
7,768 KB
testcase_62 AC 103 ms
32,684 KB
testcase_63 AC 84 ms
33,212 KB
testcase_64 AC 27 ms
12,088 KB
testcase_65 AC 109 ms
73,196 KB
testcase_66 AC 61 ms
20,180 KB
testcase_67 AC 101 ms
42,000 KB
testcase_68 AC 97 ms
21,004 KB
testcase_69 AC 103 ms
80,336 KB
testcase_70 AC 52 ms
34,208 KB
testcase_71 AC 58 ms
35,600 KB
testcase_72 AC 67 ms
7,192 KB
testcase_73 AC 97 ms
67,292 KB
testcase_74 AC 149 ms
72,740 KB
testcase_75 AC 74 ms
35,540 KB
testcase_76 AC 130 ms
66,220 KB
testcase_77 AC 133 ms
76,812 KB
testcase_78 AC 119 ms
21,764 KB
testcase_79 AC 147 ms
62,920 KB
testcase_80 AC 140 ms
64,300 KB
testcase_81 AC 116 ms
65,288 KB
testcase_82 AC 493 ms
279,644 KB
testcase_83 AC 724 ms
279,644 KB
testcase_84 AC 697 ms
279,768 KB
testcase_85 AC 513 ms
279,712 KB
testcase_86 AC 453 ms
279,712 KB
testcase_87 AC 521 ms
279,712 KB
testcase_88 AC 520 ms
279,640 KB
testcase_89 AC 523 ms
279,716 KB
testcase_90 AC 523 ms
279,792 KB
testcase_91 AC 523 ms
279,748 KB
testcase_92 AC 717 ms
279,968 KB
testcase_93 AC 722 ms
279,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//
// Created by yamunaku on 2019/07/26.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"NO"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

struct SegmentTree {
private:
    int n;
    vector<short> node;

public:
    void init(vi &v) {
        int sz=v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[2*i+1]+node[2*i+2];
    }

    int getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return node[k];
        int vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        int vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl+vr;
    }
};

struct SegmentTree2{
private:
    int n;
    vector<int> node;

public:
    void init(vi &v) {
        int sz=v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, IINF);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = min(node[2*i+1],node[2*i+2]);
    }

    int getmin(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        if(r <= a || b <= l) return IINF;
        if(a <= l && r <= b) return node[k];
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl,vr);
    }
};


int main(){
    CFS;
    vi isp(2001,1);
    isp[0]=isp[1]=0;
    rep(i,2001){
        if(isp[i]){
            for(int j=i+i;j<2001;j+=i){
                isp[j]=0;
            }
        }
    }
    vi prime;
    rep(i,2001) if(isp[i]) prime.push_back(i);
    int pn=prime.size();
    vector<SegmentTree> seg(pn);
    int n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a[i];
    mti paa(pn,vi(n,0));
    rep(i,n){
        if(a[i]==0) continue;
        rep(j,pn){
            while(a[i]%prime[j]==0){
                a[i]/=prime[j];
                paa[j][i]++;
            }
            if(a[i]==1) break;
        }
    }
    rep(i,pn){
        seg[i].init(paa[i]);
    }
    SegmentTree2 seg2;
    seg2.init(a);
    int q;
    cin >> q;
    rep(_,q){
        int p,l,r;
        cin >> p >> l >> r;
        if(seg2.getmin(l-1,r)==0){
            CYES;
            continue;
        }
        rep(i,pn){
            if(p%prime[i]==0){
                int cnt=0;
                while(p%prime[i]==0){
                    p/=prime[i];
                    cnt++;
                }
                if(cnt>seg[i].getsum(l-1,r)){
                    CNO;
                    goto next;
                }
                if(p==1) break;
            }
        }
        if(p==1) CYES;
        else CNO;
        next:;
    }
    return 0;
}
0