結果

問題 No.854 公平なりんご分配
ユーザー やむなくやむなく
提出日時 2019-07-26 22:16:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,280 bytes
コンパイル時間 2,129 ms
コンパイル使用メモリ 180,600 KB
実行使用メモリ 279,796 KB
最終ジャッジ日時 2023-09-15 01:56:54
合計ジャッジ時間 35,461 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 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 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 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,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,384 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 10 ms
4,380 KB
testcase_23 AC 9 ms
5,320 KB
testcase_24 AC 17 ms
5,440 KB
testcase_25 AC 6 ms
4,384 KB
testcase_26 AC 18 ms
5,476 KB
testcase_27 AC 10 ms
5,420 KB
testcase_28 AC 11 ms
4,380 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 7 ms
4,380 KB
testcase_31 AC 17 ms
5,372 KB
testcase_32 AC 231 ms
68,520 KB
testcase_33 AC 490 ms
36,252 KB
testcase_34 AC 803 ms
78,040 KB
testcase_35 AC 500 ms
70,592 KB
testcase_36 AC 266 ms
7,232 KB
testcase_37 AC 227 ms
66,980 KB
testcase_38 AC 136 ms
41,864 KB
testcase_39 AC 1,564 ms
80,452 KB
testcase_40 AC 565 ms
34,244 KB
testcase_41 AC 584 ms
65,136 KB
testcase_42 AC 641 ms
77,456 KB
testcase_43 AC 1,147 ms
66,244 KB
testcase_44 AC 1,038 ms
74,968 KB
testcase_45 AC 929 ms
19,200 KB
testcase_46 AC 1,580 ms
74,592 KB
testcase_47 AC 398 ms
39,960 KB
testcase_48 AC 539 ms
76,964 KB
testcase_49 AC 455 ms
77,840 KB
testcase_50 AC 177 ms
66,940 KB
testcase_51 AC 1,550 ms
76,128 KB
testcase_52 AC 717 ms
36,912 KB
testcase_53 AC 245 ms
36,612 KB
testcase_54 AC 689 ms
39,652 KB
testcase_55 AC 109 ms
36,812 KB
testcase_56 AC 101 ms
37,420 KB
testcase_57 AC 335 ms
34,620 KB
testcase_58 AC 684 ms
12,772 KB
testcase_59 AC 109 ms
32,976 KB
testcase_60 AC 466 ms
34,540 KB
testcase_61 AC 139 ms
7,868 KB
testcase_62 AC 620 ms
32,676 KB
testcase_63 AC 257 ms
33,212 KB
testcase_64 AC 102 ms
12,124 KB
testcase_65 AC 244 ms
73,232 KB
testcase_66 AC 302 ms
20,156 KB
testcase_67 AC 406 ms
42,088 KB
testcase_68 AC 466 ms
20,944 KB
testcase_69 AC 109 ms
80,420 KB
testcase_70 AC 104 ms
34,144 KB
testcase_71 AC 124 ms
35,560 KB
testcase_72 AC 359 ms
7,340 KB
testcase_73 AC 139 ms
67,204 KB
testcase_74 AC 500 ms
72,792 KB
testcase_75 AC 329 ms
35,520 KB
testcase_76 AC 283 ms
66,212 KB
testcase_77 AC 275 ms
76,688 KB
testcase_78 AC 713 ms
21,748 KB
testcase_79 AC 623 ms
62,948 KB
testcase_80 AC 589 ms
64,288 KB
testcase_81 AC 268 ms
65,132 KB
testcase_82 AC 467 ms
279,680 KB
testcase_83 AC 699 ms
279,796 KB
testcase_84 TLE -
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<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){
            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