結果

問題 No.854 公平なりんご分配
ユーザー やむなくやむなく
提出日時 2019-07-26 21:53:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,210 bytes
コンパイル時間 2,000 ms
コンパイル使用メモリ 179,440 KB
実行使用メモリ 434,772 KB
最終ジャッジ日時 2023-09-15 01:15:21
合計ジャッジ時間 34,346 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 2 ms
4,376 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,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 14 ms
4,380 KB
testcase_23 AC 14 ms
6,524 KB
testcase_24 AC 32 ms
6,972 KB
testcase_25 AC 10 ms
5,280 KB
testcase_26 AC 36 ms
6,980 KB
testcase_27 AC 19 ms
7,052 KB
testcase_28 AC 15 ms
4,380 KB
testcase_29 AC 6 ms
4,376 KB
testcase_30 AC 11 ms
5,120 KB
testcase_31 AC 31 ms
6,892 KB
testcase_32 AC 512 ms
107,320 KB
testcase_33 AC 1,249 ms
56,716 KB
testcase_34 AC 1,988 ms
116,788 KB
testcase_35 AC 1,234 ms
109,408 KB
testcase_36 AC 648 ms
9,576 KB
testcase_37 AC 526 ms
105,796 KB
testcase_38 AC 308 ms
62,464 KB
testcase_39 TLE -
testcase_40 AC 1,589 ms
54,796 KB
testcase_41 AC 1,460 ms
103,884 KB
testcase_42 AC 1,527 ms
116,320 KB
testcase_43 AC 2,892 ms
105,036 KB
testcase_44 AC 2,629 ms
113,716 KB
testcase_45 AC 2,788 ms
28,676 KB
testcase_46 TLE -
testcase_47 AC 1,042 ms
60,616 KB
testcase_48 AC 1,321 ms
115,864 KB
testcase_49 AC 1,086 ms
116,804 KB
testcase_50 AC 383 ms
105,560 KB
testcase_51 TLE -
testcase_52 AC 1,780 ms
57,540 KB
testcase_53 AC 574 ms
57,464 KB
testcase_54 AC 1,760 ms
60,360 KB
testcase_55 AC 238 ms
57,576 KB
testcase_56 AC 238 ms
58,048 KB
testcase_57 AC 882 ms
55,192 KB
testcase_58 AC 1,993 ms
17,544 KB
testcase_59 AC 241 ms
53,584 KB
testcase_60 AC 1,194 ms
55,200 KB
testcase_61 AC 303 ms
10,416 KB
testcase_62 AC 1,655 ms
53,496 KB
testcase_63 AC 638 ms
53,888 KB
testcase_64 AC 282 ms
16,796 KB
testcase_65 AC 548 ms
112,016 KB
testcase_66 AC 717 ms
30,444 KB
testcase_67 AC 997 ms
62,532 KB
testcase_68 AC 1,132 ms
30,776 KB
testcase_69 AC 194 ms
119,292 KB
testcase_70 AC 224 ms
54,964 KB
testcase_71 AC 270 ms
55,904 KB
testcase_72 AC 1,144 ms
9,880 KB
testcase_73 AC 273 ms
106,280 KB
testcase_74 AC 1,240 ms
111,476 KB
testcase_75 AC 926 ms
56,040 KB
testcase_76 AC 608 ms
105,188 KB
testcase_77 AC 618 ms
115,600 KB
testcase_78 AC 2,184 ms
31,816 KB
testcase_79 AC 1,530 ms
101,852 KB
testcase_80 AC 1,483 ms
103,100 KB
testcase_81 AC 572 ms
103,904 KB
testcase_82 MLE -
testcase_83 TLE -
testcase_84 -- -
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(){
    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]++;
            }
        }
    }
    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) CYES;
        else CNO;
        next:;
    }
    return 0;
}
0