#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template ostream &operator<<(ostream &os, const vector &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; } template void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } #define COLOR(s) ("\x1b[" s "m") template T power(T a, Int e, T m) { T b = 1; for (; e; e >>= 1) { if (e & 1) b = (b * a) % m; a = (a * a) % m; } return b; } // Checks if n is a prime using Miller-Rabin test bool isPrime(Int n) { if (n <= 1 || n % 2 == 0) return (n == 2); const int s = __builtin_ctzll(n - 1); const Int d = (n - 1) >> s; // http://miller-rabin.appspot.com/ for (const Int base : {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) { __int128 a = base % n; if (a == 0) continue; a = power<__int128>(a, d, n); if (a == 1 || a == n - 1) continue; bool ok = false; for (int i = 0; i < s - 1; ++i) { a = (a * a) % n; if (a == n - 1) { ok = true; break; } } if (!ok) return false; } return true; } #ifdef LOCAL mt19937_64 rng(58); #else mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #endif // [l, r] Int randLong(Int l, Int r) { return uniform_int_distribution(l, r)(rng); } constexpr int H = 10; Int M[H]; int N, Q; Int K; vector A; vector L, R; int main() { for (int h = 0; h < H; ++h) { for (; ; ) { M[h] = randLong(1LL << 30, 1LL << 31); if (isPrime(M[h])) { break; } } } cerr<<"M = ";pv(M,M+H); for (; ~scanf("%d%d%lld", &N, &Q, &K); ) { A.resize(N); for (int i = 0; i < N; ++i) { scanf("%lld", &A[i]); } L.resize(Q); R.resize(Q); for (int q = 0; q < Q; ++q) { scanf("%d%d", &L[q], &R[q]); --L[q]; } vector> KK(H, vector(N + 1)); vector> fss(H, vector(N + 1, 0)); for (int h = 0; h < H; ++h) { const Int k = K % M[h]; KK[h][0] = 1; for (int i = 1; i <= N; ++i) { KK[h][i] = (KK[h][i - 1] * k) % M[h]; } for (int i = N; --i >= 0; ) { fss[h][i] = (A[i] + k * fss[h][i + 1]) % M[h]; } } for (int q = 0; q < Q; ++q) { bool ans = false; for (int h = 0; h < H; ++h) { Int f = (fss[h][L[q]] - KK[h][R[q] - L[q]] * fss[h][R[q]]) % M[h]; ans = ans || f; } puts(ans ? "Yes" : "No"); } } return 0; }