結果

問題 No.854 公平なりんご分配
ユーザー snrnsidysnrnsidy
提出日時 2021-11-01 02:43:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,096 bytes
コンパイル時間 2,547 ms
コンパイル使用メモリ 206,164 KB
実行使用メモリ 136,448 KB
最終ジャッジ日時 2024-04-17 19:17:26
合計ジャッジ時間 14,101 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
125,184 KB
testcase_01 WA -
testcase_02 AC 33 ms
125,056 KB
testcase_03 AC 35 ms
125,056 KB
testcase_04 AC 35 ms
125,312 KB
testcase_05 WA -
testcase_06 AC 34 ms
124,928 KB
testcase_07 AC 35 ms
125,184 KB
testcase_08 WA -
testcase_09 AC 34 ms
125,184 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 34 ms
125,184 KB
testcase_14 AC 34 ms
125,184 KB
testcase_15 AC 35 ms
125,184 KB
testcase_16 AC 35 ms
125,184 KB
testcase_17 AC 34 ms
125,184 KB
testcase_18 AC 33 ms
125,056 KB
testcase_19 AC 35 ms
125,312 KB
testcase_20 AC 34 ms
125,184 KB
testcase_21 WA -
testcase_22 AC 38 ms
125,312 KB
testcase_23 AC 38 ms
125,184 KB
testcase_24 WA -
testcase_25 AC 36 ms
125,312 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 38 ms
125,312 KB
testcase_29 AC 36 ms
125,312 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 159 ms
126,848 KB
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 106 ms
126,972 KB
testcase_83 AC 106 ms
126,908 KB
testcase_84 AC 105 ms
126,848 KB
testcase_85 AC 102 ms
126,788 KB
testcase_86 AC 93 ms
126,976 KB
testcase_87 AC 183 ms
136,384 KB
testcase_88 AC 182 ms
136,320 KB
testcase_89 AC 185 ms
136,352 KB
testcase_90 AC 182 ms
136,192 KB
testcase_91 AC 183 ms
136,448 KB
testcase_92 WA -
testcase_93 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h> 

using namespace std; 

bool isprime[2001];
vector <int> prime;
int A[100001];
int psum[100001][305];
int n,q;
int P[100000];
int L[100000];
int R[100000];
int arr[2001][305];
int cntzero[100001];

map <pair<int,pair<int,int>>,string> memo;
unsigned long long int mypow(unsigned long long int x,unsigned long long int n,unsigned long long int m)
{
	unsigned long long int res = 1;
	while(n > 0)
	{
		if(n%2==1)
		{
			res = ((res%m)*(x%m)%m);
		}
		x = ((x%m)*(x%m)%m);
		n/=2;
	}
	return res;
}
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	//ifstream cin("input.txt");

	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++)
	{
		cntzero[i] += cntzero[i-1];
		cin >> A[i];
		if(A[i]==1)
		{
			cntzero[i]++;
		}
	}

	cin >> q;

	for(int i=0;i<q;i++)
	{
		cin >> P[i] >> L[i] >> R[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]++;
			}
		}
	}
	memset(psum,0,sizeof(psum));
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<prime.size();j++)
		{
			psum[i][j] += psum[i-1][j];
			psum[i][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;
		}
		if(cntzero[R[i]] - cntzero[L[i]-1] > 0)
		{
			memo[make_pair(P[i],make_pair(L[i],R[i]))] = "Yes";
			cout << "Yes" << '\n';
			continue;
		}
		unsigned 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