/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 1.316 MiB
#2 Accepted 3ms 1.316 MiB
#3 Accepted 45ms 1.68 MiB
#4 Accepted 47ms 1.703 MiB
#5 Accepted 44ms 1.781 MiB
#6 Accepted 49ms 1.727 MiB
#7 Accepted 49ms 2.223 MiB
#8 Accepted 54ms 2.27 MiB
#9 Accepted 48ms 2.25 MiB
#10 Accepted 63ms 7.762 MiB
#11 Accepted 58ms 7.879 MiB
#12 Accepted 59ms 7.789 MiB
#13 Accepted 52ms 2.254 MiB
#14 Accepted 50ms 2.246 MiB
#15 Accepted 117ms 1.781 MiB
#16 Accepted 116ms 1.77 MiB
#17 Accepted 41ms 1.852 MiB
#18 Accepted 118ms 1.809 MiB
#19 Accepted 51ms 1.789 MiB
#20 Accepted 52ms 2.211 MiB
#21 Accepted 73ms 7.816 MiB
#22 Accepted 69ms 7.758 MiB
#23 Accepted 117ms 7.781 MiB
#24 Accepted 96ms 9.207 MiB
#25 Accepted 59ms 7.879 MiB
#26 Accepted 137ms 1.609 MiB
#27 Accepted 103ms 8.117 MiB

Code

#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define EB emplace_back
#define all(x) std::begin(x), std::end(x)
#define sz(x) (int)(x).size()
#define rep(i, a, b) for(long long i = a; i < (b); ++i)
#define endl '\n'
#define debarr(a, n) cerr << #a << " : ";for(int i = 0; i < n; i++) cerr << a[i] << " "; cerr << endl;
#define debmat(mat, row, col) cerr << #mat << " :\n";for(int i = 0; i < row; i++) {for(int j = 0; j < col; j++) cerr << mat[i][j] << " ";cerr << endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const unordered_set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const unordered_map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}

typedef long long lli;
typedef pair<lli, lli> ii;    typedef vector<lli> vi;
typedef vector<ii> vii;       typedef vector<vi> graph;
template<class T> bool ckmax(T &a, const T& b) {return b > a ? a = b, 1 : 0;}
template<class T> bool ckmin(T &a, const T& b) {return b < a ? a = b, 1 : 0;}

int const MOD = 1000000007;
const int mxN=1e5+10;
vi p(mxN, 1);
vi primes;
void pre() {
	p[0]=p[1]=0;
	for(int i=2;i<mxN;i++) {
		if(p[i]) {
			primes.push_back(i);
			for(int j=2*i;j<mxN;j+=i) {
				p[j]=0;
			}
		}
	}
}

void solve() {
	int n,x;
	cin>>n>>x;
	vi arr(n);
	rep(i,0,n) {
		cin>>arr[i];
	}

	map<int,int> mp;
	for(auto &prime:primes) {
		while(x>1&&x%prime==0) {
			mp[prime]++;
			x/=prime;
		}
		if(x==1)break;
	}
	if(x>1)mp[x]++;

	map<int,int> idx;
	int id=0;
	for(auto &x:mp) {
		idx[x.first]=id++;
	}

	vector<vector<int>> cnt(n, vector<int>(sz(mp), 0));
	rep(i,0,n) {
		if(i)cnt[i]=cnt[i-1];
		for(auto &x:mp) {
			while(arr[i]>1&&arr[i]%x.first==0) {
				cnt[i][idx[x.first]]++;
				arr[i]/=x.first;
			}
			if(arr[i]==1)break;
		}
	}

	int q;
	cin>>q;
	while(q--) {
		int l, r;
		cin>>l>>r;--l;--r;

		bool ok=true;
		for(auto &x:mp) {
			int tot=cnt[r][idx[x.first]];
			if(l==0) {
			}else tot-=cnt[l-1][idx[x.first]];
			if(tot<x.second) {
				ok=false;
				break;
			}
		}
		if(ok) {
			cout<<"Yes"<<endl;
		}else cout<<"No"<<endl;
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	pre();

	int t = 1;
	cin >> t;
	rep(i, 0, t) solve();
}

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-07 15:08:03
Judged At
2024-11-11 02:23:12
Judged By
Score
100
Total Time
137ms
Peak Memory
9.207 MiB