結果

問題 No.854 公平なりんご分配
ユーザー lightninglightning
提出日時 2019-07-26 22:43:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,266 bytes
コンパイル時間 1,918 ms
コンパイル使用メモリ 181,284 KB
実行使用メモリ 160,448 KB
最終ジャッジ日時 2023-09-15 03:13:38
合計ジャッジ時間 11,054 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,376 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,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 TLE -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }

template<typename T>
T upsum(const T& l, const T& r) {//SegmentTreeのupdate関数
	T res;
	res = l + r;
	return res;
}

template<typename T>
class SegmentTree {
public:
	using F = function<T(T&, T&)>;
	vector<T> seg;
	int sz = 1;
	T unit;
	F up;
	//T (*up)(const T& l,const T& r);
	SegmentTree(int n, F up, T unit = 0) {
		this->unit = unit;
		//int sz = 1;
		while (sz < n) sz <<= 1;
		seg.resize(sz * 2, unit);
		this->up = up;
	}
	void set(const int& k, const T& x) {//左からk番目の葉にxを代入する
		seg[sz - 1 + k] = x;
	}
	T get(const int& k) {//左からk番目の葉を得る
		return seg[sz - 1 + k];
	}
	void update(int k, const T& v) {// k 番目の値をvに変更
		k += sz - 1;
		seg[k] = v;
		while (k > 0) {
			k = (k - 1) / 2;
			seg[k] = up(seg[2 * k + 1], seg[2 * k + 2]);
		}
	}
	T query(int a, int b, int k, int l, int r) {//[a,b)のupの合成を求める(a,b,0,0,sz)のように使う
		if (r <= a || b <= l) {
			return unit;
		}
		if (a <= l && r <= b) {
			return seg[k];
		}
		else {
			T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return up(vl, vr);
		}
	}
};


int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	REP(i, n)cin >> a[i];
	int q;
	cin >> q;
	vector<int> p(q), l(q), r(q);
	REP(i, q)cin >> p[i] >> l[i] >> r[i];
	vector<int> prime;
	FOR(i,2, 2001) {
		bool flag = true;
		for (int j = 2; j * j <= i; ++j) {
			if (i % j == 0)flag = false;
		}
		if (flag) {
			prime.push_back(i);
		}
	}
	vector<SegmentTree<ll>> sg(prime.size(), SegmentTree<ll>(n, upsum<ll>, 0));
	//SegmentTree<int> sgmax(n, upsum<int>, -1);
	int m = prime.size();
	REP(i, n) {
		int k = a[i];
		for (int j = 0; j < m;) {
			if (k % prime[j] == 0) {
				ll t = sg[j].get(i);
				sg[j].update(i,t + 1);
				k /= prime[j];
			}
			else {
				j++;
			}
			if (k == 1) {
				break;
			}
		}
	}
	int sz = sg[0].sz;
	REP(i, q) {
		vector<ll> ps(m, 0);
		REP(j, m) {
			ps[j] = sg[j].query(l[i]-1, r[i], 0, 0, sz);
		}
		vector<ll> pt(m, 0);
		int k = p[i];
		for (int j = 0; j < m;) {
			if (k % prime[j] == 0) {
				pt[j]++;
				k /= prime[j];
			}
			else {
				j++;
			}
			if (k == 1) {
				break;
			}
		}
		if (k != 1) {
			put("NO");
			return 0;
		}
		bool flag = true;
		REP(j, m) {
			if (ps[j] < pt[j]) {
				flag = false;
			}
		}
		if (flag) {
			put("Yes");
		}
		else {
			put("NO");
		}
	}
 	return 0;
}
0