結果

問題 No.854 公平なりんご分配
ユーザー chocopuuchocopuu
提出日時 2019-07-26 22:46:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,858 bytes
コンパイル時間 2,411 ms
コンパイル使用メモリ 181,536 KB
実行使用メモリ 244,788 KB
最終ジャッジ日時 2023-09-15 03:20:59
合計ジャッジ時間 29,831 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9+7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}

vector<int> P;
void make_primes(int n)
{
	vector<bool> primes;
	n++;
	primes.resize(n, true);
	primes[0] = primes[1] = false;
	FOR(i, 2, sqrt(n)) if (primes[i]) for (int j = 0; i * (j + 2) < n; j++)
		primes[i * (j + 2)] = false;

	FOR(i, 2, n) if (primes[i]) P.push_back(i);
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    //計算量は√N!!!
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

signed main(){
	int N;
	cin >> N;
	make_primes(2000);
	vector<int>inv(2000,0);
	REP(i,P.size())inv[P[i]] = i;
	vector<int> a(N); for(auto& e:a)cin >> e;
	vector<vector<int>>cnt(N+1,vector<int>(P.size(),0));
	REP(i,N){
		auto tmp = prime_factorize(a[i]);
		for(auto e:tmp){
			cnt[i+1][inv[e.first]] += e.second;
		}
	}
	REP(i,N)REP(j,P.size())cnt[i+1][j] += cnt[i][j];
	int Q;
	cin >> Q;
	vector<int>ans;
	REP(i,Q){
		int p,l,r;
		cin >> p >> l >> r;
		l--;r--;
		auto tmp = prime_factorize(p);
		int flg = 0;
		for(auto e:tmp)if(e.second>cnt[r+1][inv[e.first]]-cnt[l][inv[e.first]])flg = 1;
		ans.push_back(flg);
	}
	for(auto e:ans){
		if(e)cout<<"NO"<<endl;
		else cout<<"Yes"<<endl;
	}
}

0