結果

問題 No.854 公平なりんご分配
ユーザー snrnsidysnrnsidy
提出日時 2021-11-01 02:46:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,570 ms / 3,153 ms
コード長 2,033 bytes
コンパイル時間 2,339 ms
コンパイル使用メモリ 207,456 KB
実行使用メモリ 136,448 KB
最終ジャッジ日時 2024-04-17 19:18:28
合計ジャッジ時間 20,832 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
124,928 KB
testcase_01 AC 32 ms
125,056 KB
testcase_02 AC 32 ms
125,312 KB
testcase_03 AC 32 ms
124,928 KB
testcase_04 AC 33 ms
124,928 KB
testcase_05 AC 32 ms
125,184 KB
testcase_06 AC 33 ms
125,184 KB
testcase_07 AC 32 ms
125,056 KB
testcase_08 AC 32 ms
125,184 KB
testcase_09 AC 32 ms
125,184 KB
testcase_10 AC 34 ms
125,056 KB
testcase_11 AC 33 ms
125,056 KB
testcase_12 AC 34 ms
125,184 KB
testcase_13 AC 33 ms
125,184 KB
testcase_14 AC 32 ms
125,184 KB
testcase_15 AC 33 ms
125,184 KB
testcase_16 AC 33 ms
125,056 KB
testcase_17 AC 33 ms
125,184 KB
testcase_18 AC 34 ms
125,056 KB
testcase_19 AC 32 ms
125,056 KB
testcase_20 AC 32 ms
124,928 KB
testcase_21 AC 33 ms
125,184 KB
testcase_22 AC 36 ms
125,312 KB
testcase_23 AC 35 ms
125,184 KB
testcase_24 AC 40 ms
125,056 KB
testcase_25 AC 36 ms
125,184 KB
testcase_26 AC 38 ms
125,312 KB
testcase_27 AC 36 ms
124,928 KB
testcase_28 AC 36 ms
124,928 KB
testcase_29 AC 34 ms
125,056 KB
testcase_30 AC 35 ms
124,928 KB
testcase_31 AC 39 ms
125,312 KB
testcase_32 AC 83 ms
125,696 KB
testcase_33 AC 156 ms
126,464 KB
testcase_34 AC 245 ms
126,848 KB
testcase_35 AC 159 ms
126,080 KB
testcase_36 AC 136 ms
126,720 KB
testcase_37 AC 83 ms
125,696 KB
testcase_38 AC 65 ms
125,696 KB
testcase_39 AC 486 ms
128,256 KB
testcase_40 AC 198 ms
126,720 KB
testcase_41 AC 187 ms
126,336 KB
testcase_42 AC 205 ms
126,336 KB
testcase_43 AC 349 ms
127,488 KB
testcase_44 AC 327 ms
127,616 KB
testcase_45 AC 369 ms
128,512 KB
testcase_46 AC 482 ms
128,640 KB
testcase_47 AC 143 ms
126,080 KB
testcase_48 AC 176 ms
126,464 KB
testcase_49 AC 148 ms
126,080 KB
testcase_50 AC 70 ms
125,440 KB
testcase_51 AC 463 ms
128,128 KB
testcase_52 AC 215 ms
128,384 KB
testcase_53 AC 88 ms
126,592 KB
testcase_54 AC 206 ms
128,128 KB
testcase_55 AC 54 ms
125,824 KB
testcase_56 AC 53 ms
125,568 KB
testcase_57 AC 115 ms
126,336 KB
testcase_58 AC 275 ms
128,512 KB
testcase_59 AC 55 ms
125,568 KB
testcase_60 AC 145 ms
127,360 KB
testcase_61 AC 83 ms
126,336 KB
testcase_62 AC 194 ms
127,616 KB
testcase_63 AC 93 ms
127,232 KB
testcase_64 AC 63 ms
125,824 KB
testcase_65 AC 84 ms
125,824 KB
testcase_66 AC 104 ms
126,464 KB
testcase_67 AC 124 ms
127,616 KB
testcase_68 AC 154 ms
128,000 KB
testcase_69 AC 49 ms
125,696 KB
testcase_70 AC 51 ms
125,696 KB
testcase_71 AC 57 ms
125,952 KB
testcase_72 AC 179 ms
127,360 KB
testcase_73 AC 54 ms
125,824 KB
testcase_74 AC 150 ms
127,744 KB
testcase_75 AC 113 ms
126,464 KB
testcase_76 AC 91 ms
127,744 KB
testcase_77 AC 87 ms
127,104 KB
testcase_78 AC 261 ms
128,640 KB
testcase_79 AC 165 ms
128,000 KB
testcase_80 AC 160 ms
127,744 KB
testcase_81 AC 83 ms
126,976 KB
testcase_82 AC 100 ms
127,076 KB
testcase_83 AC 98 ms
126,976 KB
testcase_84 AC 100 ms
127,152 KB
testcase_85 AC 97 ms
126,912 KB
testcase_86 AC 89 ms
127,020 KB
testcase_87 AC 161 ms
136,192 KB
testcase_88 AC 166 ms
136,448 KB
testcase_89 AC 161 ms
136,416 KB
testcase_90 AC 160 ms
136,296 KB
testcase_91 AC 160 ms
136,192 KB
testcase_92 AC 2,568 ms
136,200 KB
testcase_93 AC 2,570 ms
136,368 KB
権限があれば一括ダウンロードができます

ソースコード

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;
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);

	//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]==0)
		{
			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;
		}
		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