/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 28ms 31.066 MiB
#2 Accepted 29ms 30.961 MiB
#3 Accepted 213ms 31.27 MiB
#4 Accepted 216ms 31.355 MiB
#5 Accepted 151ms 31.23 MiB
#6 Accepted 153ms 31.27 MiB
#7 Accepted 143ms 31.27 MiB
#8 Accepted 148ms 31.41 MiB
#9 Accepted 144ms 31.27 MiB
#10 Accepted 184ms 32.117 MiB
#11 Accepted 169ms 32.27 MiB
#12 Accepted 166ms 32.02 MiB
#13 Accepted 143ms 31.27 MiB
#14 Accepted 145ms 31.371 MiB
#15 Accepted 196ms 31.219 MiB
#16 Accepted 201ms 31.297 MiB
#17 Accepted 225ms 31.27 MiB
#18 Accepted 223ms 31.27 MiB
#19 Accepted 143ms 31.27 MiB
#20 Accepted 146ms 31.27 MiB
#21 Accepted 171ms 32.066 MiB
#22 Accepted 177ms 31.98 MiB
#23 Accepted 179ms 32.059 MiB
#24 Accepted 178ms 32.113 MiB
#25 Accepted 179ms 32.238 MiB
#26 Accepted 182ms 31.363 MiB
#27 Accepted 329ms 32.449 MiB

Code

#include<bits/stdc++.h>
using namespace std;
/*
#ifndef ONLINE_JUDGE
#include "DEBUG.h"
#define bug(...)           __f (#__VA_ARGS__, __VA_ARGS__)
#endif*/

#define first_in_out       ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll                 long long int
#define double             long double
#define min_heap           priority_queue <ll, vector<ll>, greater<ll>>
#define print(a)           for(auto x : a) cout << x << " ";
#define printpair(a)       for(auto x : a) cout << x.first << " " << x.second<<"\n";


const  ll N = 1e6 + 1;
ll arr[N];
int x;
template<class T>
struct segtree
{
	T tree[4 * N];

	void init(ll node, ll s, ll e)
	{
		if (s == e)
		{
			tree[node] = arr[s] % x;
			return;
		}

		ll mid = (s + e) / 2;
		ll left = node * 2;
		ll right = left + 1;
		init(left, s, mid);
		init(right, mid + 1, e);

		tree[node] = (tree[left] * tree[right]) % x;
	}

	T query(ll node, ll s, ll e, ll l, ll r)
	{

		if (s > r or e < l)
			return -1;

		if (s >= l and  e <= r)
			return tree[node];

		ll mid = (s + e) / 2;
		ll left = node * 2;
		ll right = left + 1;
		auto p1 = query(left, s, mid, l, r);
		auto p2 = query(right, mid + 1, e, l, r);

		return ((p1 % x) * (p2 % x)) % x;
	}

	void update(ll node, ll s, ll e, ll pos, ll val)
	{

		if (pos > e  or pos < s)
			return ;

		if (s == e and s == pos) {
			tree[node] = val;
			return;
		}

		ll mid = (s + e) / 2;
		ll left = node * 2;
		ll right = left + 1;
		update(left, s, mid, pos, val);
		update(right, mid + 1, e, pos, val);
		tree[node] = (tree[left] * tree[right]) % x;

	}
};

void solve()
{
	ll n, q;
	cin >> n >> x;

	for (ll i = 0; i < n; i++)
		cin >> arr[i];

	segtree<ll>seg;

	seg.init(1, 0, n - 1);

	cin >> q;

	while (q--)
	{

		int l, r;
		cin >> l >> r;
		l--, r--;

		if (seg.query(1, 0, n - 1, l, r) == 0)
			cout << "Yes" << "\n";
		else
			cout << "No\n";
	}

}


int main()
{
	first_in_out
	//clock_t z = clock();

	int t = 1;
	cin >> t;

	while (t--)
		solve();

	//cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);
}

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 17:23:01
Judged At
2024-11-05 17:23:01
Judged By
Score
100
Total Time
329ms
Peak Memory
32.449 MiB