結果

問題 No.854 公平なりんご分配
ユーザー MarcusAureliusAntoninusMarcusAureliusAntoninus
提出日時 2019-07-26 22:07:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,374 bytes
コンパイル時間 1,962 ms
コンパイル使用メモリ 203,992 KB
実行使用メモリ 6,056 KB
最終ジャッジ日時 2023-09-15 01:39:56
合計ジャッジ時間 8,540 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 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 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 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 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 86 ms
6,056 KB
testcase_83 AC 258 ms
5,956 KB
testcase_84 AC 385 ms
5,952 KB
testcase_85 AC 56 ms
5,964 KB
testcase_86 AC 49 ms
6,052 KB
testcase_87 AC 174 ms
5,896 KB
testcase_88 AC 178 ms
5,952 KB
testcase_89 AC 180 ms
5,952 KB
testcase_90 AC 177 ms
5,988 KB
testcase_91 AC 174 ms
6,040 KB
testcase_92 WA -
testcase_93 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In instantiation of ‘SegmentTree<T, Operation_t, Update_t>::SegmentTree(const std::vector<_Tp>&, Operation_t, Update_t, T) [with T = long int; Operation_t = std::multiplies<long int>; Update_t = main()::<ラムダ(const auto:28&, const auto:29&)>]’:
main.cpp:101:9:   required from ‘decltype(auto) makeSegmentTree(const std::vector<_Tp>&, Operation_t, Update_t, T) [with T = long int; Operation_t = std::multiplies<long int>; Update_t = main()::<ラムダ(const auto:28&, const auto:29&)>]’
main.cpp:110:30:   required from here
main.cpp:67:62: 警告: narrowing conversion of ‘((((SegmentTree<long int, std::multiplies<long int>, main()::<ラムダ(const auto:28&, const auto:29&)> >*)this)->SegmentTree<long int, std::multiplies<long int>, main()::<ラムダ(const auto:28&, const auto:29&)> >::container_.std::vector<long int>::size() >> 1) - 1)’ from ‘std::vector<long int>::size_type’ {aka ‘long unsigned int’} to ‘unsigned int’ [-Wnarrowing]
   67 |                 for (unsigned int i{(container_.size() >> 1) - 1}; i > 0; i--)
      |                                     ~~~~~~~~~~~~~~~~~~~~~~~~~^~~

ソースコード

diff #

#include <bits/stdc++.h>

int64_t calcGCD(int64_t a, int64_t b)
{
	while (a)
	{
		b %= a;
		std::swap(a, b);
	}
	return b;
}

///////////////////////
// 抽象化セグメント木 //
//////////////////////

// モノイドを扱えるが半群は扱えない
// identityはその演算の単位元としてのみ使用されるので、minの単位元としてINT64_MAXなどが許される
// std::minをそのまま渡してもオーバーロードを解決できないのでlambda式で包む必要がある
template <typename T, typename Operation_t, typename Update_t>
class SegmentTree {
private:

	std::vector<T> container_;
	// モノイドの演算
	Operation_t operate_;
	// 更新する値を返す
	Update_t assign_;
	// モノイドの単位元
	T identity_;

	void build(const unsigned int array_size)
	{
		unsigned int length{1};
		while (length < array_size)
			length <<= 1;
		container_.resize(2 * length, identity_);
	}

	// // デバッグ用出力関数(中身は適宜編集)
	// void debugOutput()
	// {
	// 	int line_break{2};
	// 	for (int i{1}; i < (int)container_.size(); i++)
	// 	{
	// 		// std::cout << container_[i] << ' ';
	// 		if (i + 1 == line_break)
	// 		{
	// 			putchar('\n');
	// 			line_break *= 2;
	// 		}
	// 	}
	// }

public:
	SegmentTree(const unsigned int array_size, Operation_t operate, Update_t assign, T identity)
		: operate_(operate), assign_(assign), identity_(identity)
	{
		build(array_size);
	}
	SegmentTree(const std::vector<T> &array, Operation_t operate, Update_t assign, T identity)
		: operate_(operate), assign_(assign), identity_(identity)
	{
		build(array.size());
		std::copy(array.begin(), array.end(), container_.begin() + (container_.size() >> 1));

		for (unsigned int i{(container_.size() >> 1) - 1}; i > 0; i--)
			container_[i] = operate_(container_[2 * i], container_[2 * i + 1]);
	}
	SegmentTree(const SegmentTree& st)
		: container_(st.container_), operate_(st.operate_), assign_(st.assign_), identity_(st.identity_){}
	SegmentTree(SegmentTree&& st)
		: container_(std::move(st.container_)), operate_(st.operate_), assign_(st.assign_), identity_(st.identity_){}

	// 配列内の半開区間[l,r)(0-indexed)の総和を返す
	bool get(const int left, const int right, int64_t num) const
	{
		for (int left_i{std::max(0, left) + ((int)container_.size() >> 1)}, right_i{std::min((int)container_.size() >> 1, right) + ((int)container_.size() >> 1)};
			left_i < right_i; left_i >>= 1, right_i >>= 1
			)
		{
			if (left_i & 1)
			{
				num /= calcGCD(num, container_[left_i]);
				left_i++;
			}
			if (right_i & 1)
			{
				right_i--;
				num /= calcGCD(num, container_[right_i]);
			}
		}
		return num == 1ll;
	}
};


template <typename T, typename Operation_t, typename Update_t>
decltype(auto) makeSegmentTree(const std::vector<T> &array, Operation_t operate, Update_t assign, T identity)
{
	return SegmentTree<T, Operation_t, Update_t>(array, operate, assign, identity);
}

int main()
{
	int N;
	scanf("%d", &N);
	std::vector<int64_t> A(N);
	for (auto& e: A) scanf("%lld", &e);
	auto segTree{makeSegmentTree(A, std::multiplies<int64_t>(), [](const auto& a, const auto& b) { return a; }, (int64_t)1)};
	int Q;
	scanf("%d", &Q);
	for (int i{}; i < Q; i++)
	{
		int64_t P;
		int L, R;
		scanf("%lld%d%d", &P, &L, &R);
		if (segTree.get(L - 1, R, P)) puts("Yes");
		else puts("NO");
	}

	return 0;
}
0