結果

問題 No.854 公平なりんご分配
ユーザー やむなくやむなく
提出日時 2019-07-26 21:56:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 3,278 bytes
コンパイル時間 1,997 ms
コンパイル使用メモリ 178,568 KB
実行使用メモリ 439,428 KB
最終ジャッジ日時 2023-09-15 01:17:22
合計ジャッジ時間 38,222 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
11,488 KB
testcase_01 MLE -
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,388 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 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,380 KB
testcase_22 AC 11 ms
4,380 KB
testcase_23 AC 9 ms
6,284 KB
testcase_24 AC 19 ms
6,748 KB
testcase_25 AC 7 ms
4,852 KB
testcase_26 AC 21 ms
6,804 KB
testcase_27 AC 12 ms
6,800 KB
testcase_28 AC 10 ms
4,380 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 9 ms
4,856 KB
testcase_31 AC 19 ms
6,828 KB
testcase_32 AC 260 ms
107,316 KB
testcase_33 AC 545 ms
56,772 KB
testcase_34 AC 885 ms
116,832 KB
testcase_35 AC 570 ms
109,504 KB
testcase_36 AC 332 ms
9,716 KB
testcase_37 AC 271 ms
105,768 KB
testcase_38 AC 163 ms
62,544 KB
testcase_39 AC 1,710 ms
118,920 KB
testcase_40 AC 670 ms
54,752 KB
testcase_41 AC 640 ms
103,964 KB
testcase_42 AC 679 ms
116,360 KB
testcase_43 AC 1,193 ms
104,964 KB
testcase_44 AC 1,095 ms
113,676 KB
testcase_45 AC 1,236 ms
28,720 KB
testcase_46 AC 1,662 ms
113,396 KB
testcase_47 AC 448 ms
60,668 KB
testcase_48 AC 565 ms
115,868 KB
testcase_49 AC 483 ms
116,540 KB
testcase_50 AC 205 ms
105,812 KB
testcase_51 AC 1,609 ms
114,924 KB
testcase_52 AC 765 ms
57,464 KB
testcase_53 AC 281 ms
57,224 KB
testcase_54 AC 759 ms
60,252 KB
testcase_55 AC 135 ms
57,416 KB
testcase_56 AC 126 ms
58,052 KB
testcase_57 AC 406 ms
55,188 KB
testcase_58 AC 891 ms
17,520 KB
testcase_59 AC 139 ms
53,704 KB
testcase_60 AC 534 ms
55,132 KB
testcase_61 AC 147 ms
10,188 KB
testcase_62 AC 726 ms
53,200 KB
testcase_63 AC 309 ms
53,848 KB
testcase_64 AC 125 ms
16,764 KB
testcase_65 AC 273 ms
112,132 KB
testcase_66 AC 338 ms
30,120 KB
testcase_67 AC 455 ms
62,512 KB
testcase_68 AC 521 ms
30,832 KB
testcase_69 AC 133 ms
119,200 KB
testcase_70 AC 124 ms
55,020 KB
testcase_71 AC 148 ms
56,120 KB
testcase_72 AC 405 ms
9,656 KB
testcase_73 AC 167 ms
106,252 KB
testcase_74 AC 552 ms
111,748 KB
testcase_75 AC 389 ms
56,152 KB
testcase_76 AC 326 ms
105,008 KB
testcase_77 AC 312 ms
115,472 KB
testcase_78 AC 952 ms
31,612 KB
testcase_79 AC 680 ms
101,748 KB
testcase_80 AC 645 ms
103,264 KB
testcase_81 AC 308 ms
103,852 KB
testcase_82 MLE -
testcase_83 MLE -
testcase_84 MLE -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
権限があれば一括ダウンロードができます

ソースコード

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<int> 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){
            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