結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
130,560 KB
testcase_01 AC 36 ms
125,312 KB
testcase_02 AC 37 ms
125,184 KB
testcase_03 AC 37 ms
125,056 KB
testcase_04 AC 35 ms
125,184 KB
testcase_05 AC 36 ms
125,312 KB
testcase_06 AC 37 ms
125,184 KB
testcase_07 AC 36 ms
125,312 KB
testcase_08 AC 36 ms
125,184 KB
testcase_09 AC 36 ms
125,056 KB
testcase_10 AC 37 ms
125,184 KB
testcase_11 AC 35 ms
125,184 KB
testcase_12 AC 36 ms
125,056 KB
testcase_13 AC 34 ms
125,056 KB
testcase_14 AC 37 ms
125,312 KB
testcase_15 AC 37 ms
125,184 KB
testcase_16 AC 36 ms
125,056 KB
testcase_17 AC 37 ms
125,184 KB
testcase_18 AC 38 ms
125,056 KB
testcase_19 AC 36 ms
125,056 KB
testcase_20 AC 35 ms
125,056 KB
testcase_21 AC 35 ms
125,184 KB
testcase_22 AC 44 ms
125,056 KB
testcase_23 AC 40 ms
125,056 KB
testcase_24 AC 44 ms
125,440 KB
testcase_25 AC 38 ms
125,056 KB
testcase_26 AC 43 ms
125,312 KB
testcase_27 AC 40 ms
125,056 KB
testcase_28 AC 40 ms
124,928 KB
testcase_29 AC 37 ms
125,184 KB
testcase_30 AC 39 ms
125,312 KB
testcase_31 AC 42 ms
125,184 KB
testcase_32 AC 114 ms
125,568 KB
testcase_33 AC 241 ms
126,464 KB
testcase_34 AC 393 ms
126,976 KB
testcase_35 AC 243 ms
126,080 KB
testcase_36 AC 189 ms
126,720 KB
testcase_37 AC 117 ms
125,824 KB
testcase_38 AC 82 ms
125,568 KB
testcase_39 AC 757 ms
128,640 KB
testcase_40 AC 288 ms
126,848 KB
testcase_41 AC 280 ms
126,464 KB
testcase_42 AC 311 ms
126,592 KB
testcase_43 AC 540 ms
127,488 KB
testcase_44 AC 501 ms
127,360 KB
testcase_45 AC 517 ms
128,768 KB
testcase_46 AC 756 ms
128,384 KB
testcase_47 AC 203 ms
125,952 KB
testcase_48 AC 252 ms
126,336 KB
testcase_49 AC 214 ms
125,952 KB
testcase_50 AC 88 ms
125,568 KB
testcase_51 AC 713 ms
128,256 KB
testcase_52 AC 304 ms
128,512 KB
testcase_53 AC 114 ms
126,720 KB
testcase_54 AC 291 ms
128,256 KB
testcase_55 AC 60 ms
125,696 KB
testcase_56 AC 62 ms
125,696 KB
testcase_57 AC 155 ms
126,336 KB
testcase_58 AC 388 ms
128,640 KB
testcase_59 AC 65 ms
125,824 KB
testcase_60 AC 211 ms
127,232 KB
testcase_61 AC 103 ms
126,592 KB
testcase_62 AC 283 ms
127,872 KB
testcase_63 AC 118 ms
127,488 KB
testcase_64 AC 81 ms
125,824 KB
testcase_65 AC 111 ms
125,952 KB
testcase_66 AC 146 ms
126,848 KB
testcase_67 AC 170 ms
127,616 KB
testcase_68 AC 212 ms
128,256 KB
testcase_69 AC 52 ms
125,568 KB
testcase_70 AC 60 ms
125,824 KB
testcase_71 AC 70 ms
125,952 KB
testcase_72 AC 240 ms
127,488 KB
testcase_73 AC 64 ms
126,208 KB
testcase_74 AC 215 ms
127,872 KB
testcase_75 AC 158 ms
126,592 KB
testcase_76 AC 116 ms
127,872 KB
testcase_77 AC 114 ms
127,104 KB
testcase_78 AC 377 ms
128,512 KB
testcase_79 AC 243 ms
128,384 KB
testcase_80 AC 234 ms
128,000 KB
testcase_81 AC 108 ms
127,104 KB
testcase_82 AC 108 ms
126,976 KB
testcase_83 AC 106 ms
126,924 KB
testcase_84 AC 105 ms
127,160 KB
testcase_85 AC 107 ms
126,904 KB
testcase_86 AC 97 ms
126,976 KB
testcase_87 AC 194 ms
136,192 KB
testcase_88 AC 191 ms
136,448 KB
testcase_89 AC 191 ms
136,384 KB
testcase_90 AC 195 ms
136,256 KB
testcase_91 AC 197 ms
136,256 KB
testcase_92 TLE -
testcase_93 -- -
権限があれば一括ダウンロードができます

ソースコード

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 = ((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]==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