import bisect def main(): import sys input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]) Q = int(data[idx+1]) P = int(data[idx+2]) idx +=3 A = list(map(int, data[idx:idx+N])) idx +=N # Precompute prefix zeros prefix_zeros = [0]*(N+1) for i in range(N): prefix_zeros[i+1] = prefix_zeros[i] + (A[i] == 0) # Precompute positions for each non-zero remainder from collections import defaultdict pos = defaultdict(list) for i in range(N): a = A[i] if a !=0: pos[a].append(i+1) # 1-based index # Process queries for _ in range(Q): L = int(data[idx]) R = int(data[idx+1]) K = int(data[idx+2]) idx +=3 if K ==0: if prefix_zeros[R] - prefix_zeros[L-1] >0: print("Yes") else: print("No") continue # Check if K is present in the interval found = False if K < P and K in pos: lst = pos[K] left = bisect.bisect_left(lst, L) right = bisect.bisect_right(lst, R) if left < right: found = True if found: print("Yes") continue # Now process the interval with DP current_mask = 0 found = False for i in range(L-1, R): a = A[i] if a ==0: continue # Compute new_bits new_bits = 0 temp_mask = current_mask r = 0 while temp_mask: if temp_mask & 1: new_r = (r * a) % P new_bits |= 1 << new_r temp_mask >>=1 r +=1 # Update current_mask current_mask |= new_bits current_mask |= 1 << a # Check if K is present if (current_mask & (1 << K)) !=0: found = True break print("Yes" if found else "No") if __name__ == "__main__": main()