#include #include using namespace std; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) template bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; } int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N, Q, P; cin >> N >> Q >> P; vector A(N); for (auto &a : A) cin >> a; vector dp(N + 1, vector(P, N)); IREP(i, N) { dp[i] = dp[i + 1]; chmin(dp[i][A[i]], i); REP(j, P) chmin(dp[i][A[i] * j % P], dp[i + 1][j]); } while (Q--) { int L, R, K; cin >> L >> R >> K; L--; cout << (dp[L][K] < R ? "Yes" : "No") << '\n'; } }