結果
| 問題 |
No.2592 おでぶなおばけさん 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-12-20 00:25:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 180 ms / 2,500 ms |
| コード長 | 3,432 bytes |
| コンパイル時間 | 1,501 ms |
| コンパイル使用メモリ | 122,936 KB |
| 実行使用メモリ | 21,516 KB |
| 最終ジャッジ日時 | 2024-09-27 09:31:32 |
| 合計ジャッジ時間 | 18,810 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 83 |
ソースコード
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <chrono>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &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 <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
template<class T> 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<Int>(l, r)(rng);
}
constexpr int H = 10;
Int M[H];
int N, Q;
Int K;
vector<Int> A;
vector<int> 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<vector<Int>> KK(H, vector<Int>(N + 1));
vector<vector<Int>> fss(H, vector<Int>(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;
}