/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 29ms 31.016 MiB
#2 Accepted 30ms 30.91 MiB
#3 Accepted 184ms 31.363 MiB
#4 Accepted 180ms 31.398 MiB
#5 Accepted 136ms 31.285 MiB
#6 Accepted 137ms 31.391 MiB
#7 Accepted 161ms 31.387 MiB
#8 Accepted 164ms 31.453 MiB
#9 Accepted 163ms 31.477 MiB
#10 Accepted 199ms 32.16 MiB
#11 Accepted 203ms 32.234 MiB
#12 Accepted 212ms 32.172 MiB
#13 Accepted 169ms 31.387 MiB
#14 Accepted 169ms 31.344 MiB
#15 Accepted 187ms 31.227 MiB
#16 Accepted 192ms 31.391 MiB
#17 Accepted 193ms 31.418 MiB
#18 Accepted 192ms 31.215 MiB
#19 Accepted 140ms 31.32 MiB
#20 Accepted 170ms 31.359 MiB
#21 Accepted 202ms 32.082 MiB
#22 Accepted 202ms 32.176 MiB
#23 Accepted 205ms 32.254 MiB
#24 Accepted 197ms 32.145 MiB
#25 Accepted 197ms 32.223 MiB
#26 Accepted 195ms 31.375 MiB
#27 Accepted 361ms 32.52 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-11 02:26:02
Judged By
Score
100
Total Time
361ms
Peak Memory
32.52 MiB