結果

問題 No.2592 おでぶなおばけさん 2
ユーザー fdironia
提出日時 2023-12-20 00:15:01
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 294 ms / 2,500 ms
コード長 874 bytes
コンパイル時間 1,103 ms
コンパイル使用メモリ 80,004 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-27 09:30:55
合計ジャッジ時間 25,875 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 83
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;

using ll = long long;

constexpr int Z[3] = {(int)1e9-71, (int)1e9+7, (int)1e9+9};

int main() {
    int n, q;
    ll k;
    cin >> n >> q >> k;
    int ps[n+1][3];
    ps[0][0] = ps[0][1] = ps[0][2] = 0;
    int powk[3] = {1, 1, 1};
    for (int i = 1; i <= n; i++) {
        ll a;
        cin >> a;
        for (int j = 0; j < 3; j++) {
            int moda = (a % Z[j] + Z[j]) % Z[j];
            ps[i][j] = (ps[i-1][j] + 1ll * moda * powk[j]) % Z[j];
            powk[j] = powk[j] * (k % Z[j]) % Z[j];
        }
    }

    while (q--) {
        int l, r;
        cin >> l >> r;

        bool ans = false;
        for (int j = 0; j < 3; j++) {
            if ((ps[r][j] - ps[l-1][j] + Z[j]) % Z[j] != 0) {
                ans = true;
            }
        }

        cout << (ans ? "Yes" : "No") << endl;
    }

    return 0;
}
0