/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 1.43 MiB
#2 Accepted 4ms 1.316 MiB
#3 Accepted 762ms 1.941 MiB
#4 Accepted 782ms 1.957 MiB
#5 Time Exceeded ≥1578ms ≥15.262 MiB
#6 Time Exceeded ≥1591ms ≥17.727 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> fx;
	for(auto &prime:primes) {
		while(x>1&&x%prime==0) {
			fx[prime]++;
			x/=prime;
		}
		if(x==1)break;
	}

	vector<map<int,int>> farr(n);
	rep(i,0,n) {
		if(i)farr[i]=farr[i-1];
		map<int,int> temp;
		for(auto &prime:primes) {
			while(arr[i]>1&&arr[i]%prime==0) {
				farr[i][prime]++;
				arr[i]/=prime;
			}
			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:fx) {
			int cnt=farr[r][x.first];
			if(l==0) {
			}else cnt-=farr[l-1][x.first];
			if(cnt<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 13:51:42
Judged At
2024-11-11 02:23:16
Judged By
Score
7
Total Time
≥1591ms
Peak Memory
≥17.727 MiB