結果

問題 No.2592 おでぶなおばけさん 2
ユーザー t98slidert98slider
提出日時 2023-12-21 01:56:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,054 ms / 2,500 ms
コード長 3,024 bytes
コンパイル時間 2,541 ms
コンパイル使用メモリ 213,544 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-21 01:59:48
合計ジャッジ時間 178,499 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,997 ms
6,548 KB
testcase_01 AC 1,974 ms
6,548 KB
testcase_02 AC 1,972 ms
6,548 KB
testcase_03 AC 1,972 ms
6,548 KB
testcase_04 AC 1,973 ms
6,548 KB
testcase_05 AC 1,975 ms
6,548 KB
testcase_06 AC 1,972 ms
6,548 KB
testcase_07 AC 1,976 ms
6,548 KB
testcase_08 AC 1,974 ms
6,548 KB
testcase_09 AC 1,973 ms
6,548 KB
testcase_10 AC 1,972 ms
6,548 KB
testcase_11 AC 1,976 ms
6,548 KB
testcase_12 AC 1,974 ms
6,548 KB
testcase_13 AC 1,977 ms
6,548 KB
testcase_14 AC 1,975 ms
6,548 KB
testcase_15 AC 1,976 ms
6,548 KB
testcase_16 AC 2,001 ms
6,548 KB
testcase_17 AC 2,000 ms
6,548 KB
testcase_18 AC 2,002 ms
6,548 KB
testcase_19 AC 2,024 ms
6,548 KB
testcase_20 AC 2,000 ms
6,548 KB
testcase_21 AC 1,981 ms
6,548 KB
testcase_22 AC 1,978 ms
6,548 KB
testcase_23 AC 1,977 ms
6,548 KB
testcase_24 AC 1,999 ms
6,548 KB
testcase_25 AC 2,000 ms
6,548 KB
testcase_26 AC 2,027 ms
6,548 KB
testcase_27 AC 2,032 ms
6,548 KB
testcase_28 AC 2,028 ms
6,548 KB
testcase_29 AC 2,031 ms
6,548 KB
testcase_30 AC 2,032 ms
6,548 KB
testcase_31 AC 2,054 ms
6,548 KB
testcase_32 AC 2,026 ms
6,676 KB
testcase_33 AC 2,003 ms
6,676 KB
testcase_34 AC 2,026 ms
6,676 KB
testcase_35 AC 2,002 ms
6,676 KB
testcase_36 AC 1,976 ms
6,676 KB
testcase_37 AC 1,976 ms
6,676 KB
testcase_38 AC 1,978 ms
6,676 KB
testcase_39 AC 2,008 ms
6,676 KB
testcase_40 AC 2,030 ms
6,676 KB
testcase_41 AC 1,980 ms
6,676 KB
testcase_42 AC 1,976 ms
6,676 KB
testcase_43 AC 1,976 ms
6,676 KB
testcase_44 AC 1,984 ms
6,676 KB
testcase_45 AC 1,980 ms
6,676 KB
testcase_46 AC 1,977 ms
6,676 KB
testcase_47 AC 1,980 ms
6,676 KB
testcase_48 AC 2,003 ms
6,676 KB
testcase_49 AC 2,002 ms
6,676 KB
testcase_50 AC 2,028 ms
6,676 KB
testcase_51 AC 1,978 ms
6,676 KB
testcase_52 AC 2,004 ms
6,676 KB
testcase_53 AC 1,978 ms
6,676 KB
testcase_54 AC 1,981 ms
6,676 KB
testcase_55 AC 1,983 ms
6,676 KB
testcase_56 AC 1,984 ms
6,676 KB
testcase_57 AC 1,972 ms
6,676 KB
testcase_58 AC 1,978 ms
6,676 KB
testcase_59 AC 1,978 ms
6,676 KB
testcase_60 AC 1,976 ms
6,676 KB
testcase_61 AC 2,001 ms
6,676 KB
testcase_62 AC 2,001 ms
6,676 KB
testcase_63 AC 2,001 ms
6,676 KB
testcase_64 AC 1,976 ms
6,676 KB
testcase_65 AC 2,003 ms
6,676 KB
testcase_66 AC 1,980 ms
6,676 KB
testcase_67 AC 1,978 ms
6,676 KB
testcase_68 AC 1,977 ms
6,676 KB
testcase_69 AC 2,000 ms
6,676 KB
testcase_70 AC 1,981 ms
6,676 KB
testcase_71 AC 1,979 ms
6,676 KB
testcase_72 AC 1,977 ms
6,676 KB
testcase_73 AC 1,975 ms
6,676 KB
testcase_74 AC 1,970 ms
6,676 KB
testcase_75 AC 1,982 ms
6,676 KB
testcase_76 AC 1,978 ms
6,676 KB
testcase_77 AC 2,029 ms
6,676 KB
testcase_78 AC 2,006 ms
6,676 KB
testcase_79 AC 2,009 ms
6,676 KB
testcase_80 AC 2,026 ms
6,676 KB
testcase_81 AC 2,022 ms
6,676 KB
testcase_82 AC 1,980 ms
6,676 KB
testcase_83 AC 2,011 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

unsigned long long xor64() {
    static unsigned long long x
        = (unsigned long long)(chrono::duration_cast<chrono::nanoseconds>(
            chrono::high_resolution_clock::now().time_since_epoch()).count())
            * 10150724397891781847ULL;
    x ^= x << 7;
    return x ^= x >> 9;
}

struct Miller_Rabin {
    unsigned long long mul_mod(unsigned long long a, unsigned long long b, unsigned long long m) {
        unsigned long long ans = 0;
        #ifdef LOCAL
            if(a > b) std::swap(a, b);
            while(b){
                if(b & 1){
                    ans += a;
                    if(ans >= m) ans -= m;
                }
                if((a <<= 1) >= m) a -= m;
                b >>= 1;
            }
        #else
            ans = (unsigned long long)((__int128)(a) * (__int128)(b) % m); 
        #endif
        return ans;
    }
    unsigned long long pow_mod(unsigned long long x, unsigned long long n, unsigned long long m) {
        if (m == 1) return 0;
        unsigned long long r = 1;
        unsigned long long y = x % m;
        while (n) {
            if (n & 1) r = mul_mod(r, y, m);
            y = mul_mod(y, y, m);
            n >>= 1;
        }
        return r;
    }
    bool is_prime(unsigned long long n) {
        if (n <= 1) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;
        unsigned long long d = n - 1;
        while (d % 2 == 0) d /= 2;
        static std::vector<std::vector<long long>> 
            bases = {{2, 6, 61}, {2, 325, 9375, 28178, 450775, 9780504, 1795265022}};
        for (long long a : bases[d > 4759123141]) {
            unsigned long long t = d;
            unsigned long long y = pow_mod(a, t, n);
            if(a % n){
                while (t != n - 1 && y != 1 && y != n - 1) {
                    y = mul_mod(y, y, n);
                    t <<= 1;
                }
            }
            if (y != n - 1 && t % 2 == 0) return false;
        }
        return true;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    clock_t finish = clock() + CLOCKS_PER_SEC / 1000 * 1960;
    ll n, q, k;
    cin >> n >> q >> k;
    vector<ll> a(n);
    vector<long long> s(n + 1);
    vector<pair<int,int>> query(q);
    vector<bool> ans(q);
    Miller_Rabin MR;
    for(auto &&v : a) cin >> v;
    for(auto &&[l, r] : query) cin >> l >> r, l--;
    while(clock() <= finish){
        long long mod = xor64() & ((1ll << 62) - 1);
        __int128 d = 1;
        while(!MR.is_prime(mod)) mod = xor64() & ((1ll << 62) - 1);

        for(int i = 0; i < n; i++){
            s[i + 1] = (s[i] + a[i] * d) % mod;
            if(s[i + 1] < 0) s[i + 1] += mod;
            d = (d * k) % mod;
        }
        for(int i = 0; i < q; i++){
            if(ans[i]) continue;
            auto [l, r] = query[i];
            ans[i] = s[r] != s[l];
        }
    }
    for(auto &&flg : ans) cout << (flg ? "Yes" : "No") << '\n';
}
0