結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,648 KB
testcase_01 AC 4 ms
7,400 KB
testcase_02 AC 4 ms
7,140 KB
testcase_03 AC 4 ms
7,136 KB
testcase_04 AC 4 ms
7,396 KB
testcase_05 AC 3 ms
8,428 KB
testcase_06 AC 4 ms
7,396 KB
testcase_07 AC 4 ms
7,912 KB
testcase_08 AC 4 ms
7,656 KB
testcase_09 AC 3 ms
7,776 KB
testcase_10 AC 4 ms
7,780 KB
testcase_11 AC 3 ms
7,396 KB
testcase_12 AC 4 ms
10,852 KB
testcase_13 AC 4 ms
10,984 KB
testcase_14 AC 4 ms
7,144 KB
testcase_15 AC 4 ms
8,420 KB
testcase_16 AC 4 ms
7,524 KB
testcase_17 AC 3 ms
7,788 KB
testcase_18 AC 3 ms
8,168 KB
testcase_19 AC 4 ms
7,264 KB
testcase_20 AC 3 ms
8,420 KB
testcase_21 AC 3 ms
7,908 KB
testcase_22 AC 7 ms
8,296 KB
testcase_23 AC 6 ms
8,556 KB
testcase_24 AC 8 ms
8,692 KB
testcase_25 AC 5 ms
10,728 KB
testcase_26 AC 8 ms
11,112 KB
testcase_27 AC 6 ms
9,276 KB
testcase_28 AC 8 ms
7,532 KB
testcase_29 AC 5 ms
7,652 KB
testcase_30 AC 5 ms
8,688 KB
testcase_31 AC 9 ms
9,436 KB
testcase_32 AC 54 ms
32,600 KB
testcase_33 AC 114 ms
21,972 KB
testcase_34 AC 200 ms
44,024 KB
testcase_35 AC 122 ms
35,960 KB
testcase_36 AC 96 ms
11,592 KB
testcase_37 AC 54 ms
32,496 KB
testcase_38 AC 34 ms
26,920 KB
testcase_39 AC 387 ms
48,328 KB
testcase_40 AC 146 ms
20,152 KB
testcase_41 AC 139 ms
31,808 KB
testcase_42 AC 158 ms
43,752 KB
testcase_43 AC 275 ms
33,160 KB
testcase_44 AC 256 ms
40,648 KB
testcase_45 AC 328 ms
16,760 KB
testcase_46 AC 383 ms
41,216 KB
testcase_47 AC 103 ms
26,364 KB
testcase_48 AC 131 ms
42,024 KB
testcase_49 AC 109 ms
43,312 KB
testcase_50 AC 40 ms
31,264 KB
testcase_51 AC 367 ms
44,192 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 101 ms
125,792 KB
testcase_84 AC 102 ms
125,980 KB
testcase_85 AC 103 ms
125,864 KB
testcase_86 AC 94 ms
125,768 KB
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 AC 2,208 ms
135,328 KB
testcase_93 AC 2,302 ms
135,124 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];
int arr[2001][303];

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

	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