結果

問題 No.854 公平なりんご分配
ユーザー snrnsidysnrnsidy
提出日時 2021-11-01 01:52:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,785 bytes
コンパイル時間 2,029 ms
コンパイル使用メモリ 207,508 KB
実行使用メモリ 132,972 KB
最終ジャッジ日時 2024-04-17 19:15:36
合計ジャッジ時間 28,144 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
7,656 KB
testcase_06 AC 2 ms
6,948 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 5 ms
6,940 KB
testcase_23 AC 4 ms
6,944 KB
testcase_24 AC 7 ms
6,944 KB
testcase_25 AC 3 ms
6,940 KB
testcase_26 AC 7 ms
6,940 KB
testcase_27 AC 5 ms
6,944 KB
testcase_28 AC 5 ms
6,944 KB
testcase_29 AC 3 ms
6,940 KB
testcase_30 AC 3 ms
6,944 KB
testcase_31 AC 6 ms
6,940 KB
testcase_32 AC 47 ms
29,520 KB
testcase_33 AC 109 ms
19,088 KB
testcase_34 AC 188 ms
40,440 KB
testcase_35 AC 114 ms
31,936 KB
testcase_36 AC 92 ms
9,200 KB
testcase_37 AC 48 ms
28,496 KB
testcase_38 AC 30 ms
24,392 KB
testcase_39 AC 371 ms
44,268 KB
testcase_40 AC 135 ms
18,048 KB
testcase_41 AC 131 ms
29,180 KB
testcase_42 AC 146 ms
40,212 KB
testcase_43 AC 268 ms
30,364 KB
testcase_44 AC 243 ms
38,520 KB
testcase_45 AC 261 ms
13,544 KB
testcase_46 AC 393 ms
39,452 KB
testcase_47 AC 108 ms
25,056 KB
testcase_48 AC 127 ms
39,340 KB
testcase_49 AC 100 ms
39,592 KB
testcase_50 AC 36 ms
28,504 KB
testcase_51 AC 353 ms
41,416 KB
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 WA -
testcase_83 AC 83 ms
123,360 KB
testcase_84 AC 84 ms
123,236 KB
testcase_85 AC 86 ms
123,492 KB
testcase_86 AC 69 ms
123,604 KB
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 AC 2,125 ms
132,972 KB
testcase_93 AC 2,167 ms
132,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h> 

using namespace std; 

bool isprime[2001];
vector <int> prime;
int A[100001];
int psum[100001][303];
int n,q;
int P[100000];
int L[100000];
int R[100000];
int idx[2001];
map <pair<int,pair<int,int>>,string> memo;
long long int mypow(long long int x,long long int n,long long int m)
{
	long long int res = 1;
	while(n > 0)
	{
		if(n%2==1)
		{
			res *= x;
			res%=m;
		}
		x *= x;
		x%=m;
		n/=2;
	}
	return res;
}
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	memset(isprime,true,sizeof(isprime));

	for(int i=2;i<=2000;i++)
	{
		if(isprime[i])
		{
			prime.push_back(i);
			for(int j=2*i;j<=2000;j+=i)
			{
				isprime[j] = false;
			}
		}
	}

	cin >> n;

	for(int i=1;i<=n;i++)
	{
		cin >> A[i];
	}

	cin >> q;

	for(int i=0;i<q;i++)
	{
		cin >> P[i] >> L[i] >> R[i];
	}

	for(int i=0;i<prime.size();i++)
	{
		idx[prime[i]] = i;
	}

	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<prime.size();j++)
		{
			psum[i][j] += psum[i-1][j];
		}
		int temp = A[i];
		for(int j=0;j<prime.size();j++)
		{
			if(temp==1 || prime[j]*prime[j] > temp) break;
			while(1)
			{
				if(temp%prime[j]!=0) break;
				temp/=prime[j];
				psum[i][j]++;
			}
		}	
		if(temp > 1)
		{
			psum[i][idx[temp]]++;
		}
	}

	for(int i=0;i<q;i++)
	{
		if(memo.find(make_pair(P[i],make_pair(L[i],R[i])))!=memo.end())
		{
			cout << memo[make_pair(P[i],make_pair(L[i],R[i]))] << '\n';
			continue;
		}
		long long int val = 1;
		for(int j=0;j<prime.size();j++)
		{
			val*=mypow(prime[j],psum[R[i]][j] - psum[L[i]-1][j],P[i]);
			val%=P[i];
			if(val==0) break;
		}
		if(val==0)
		{
			memo[make_pair(P[i],make_pair(L[i],R[i]))] = "Yes";
			cout << "Yes" << '\n';
		}
		else
		{
			memo[make_pair(P[i],make_pair(L[i],R[i]))] = "NO";
			cout << "NO" << '\n';
		}
	}


	return 0;
}
0