結果

問題 No.2592 おでぶなおばけさん 2
ユーザー nullnull
提出日時 2023-12-19 04:19:43
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 7,899 bytes
コンパイル時間 9,063 ms
コンパイル使用メモリ 537,076 KB
実行使用メモリ 84,080 KB
最終ジャッジ日時 2024-09-27 09:10:07
合計ジャッジ時間 62,043 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 266 ms
38,660 KB
testcase_02 AC 206 ms
29,648 KB
testcase_03 AC 76 ms
12,928 KB
testcase_04 AC 51 ms
9,088 KB
testcase_05 AC 593 ms
81,736 KB
testcase_06 AC 305 ms
31,740 KB
testcase_07 AC 350 ms
30,172 KB
testcase_08 AC 402 ms
46,096 KB
testcase_09 AC 132 ms
16,732 KB
testcase_10 AC 70 ms
6,944 KB
testcase_11 AC 410 ms
47,400 KB
testcase_12 AC 84 ms
11,776 KB
testcase_13 AC 418 ms
53,536 KB
testcase_14 AC 422 ms
54,372 KB
testcase_15 AC 279 ms
35,920 KB
testcase_16 AC 419 ms
54,184 KB
testcase_17 AC 494 ms
63,460 KB
testcase_18 AC 283 ms
36,436 KB
testcase_19 AC 196 ms
25,088 KB
testcase_20 AC 1,093 ms
37,748 KB
testcase_21 AC 913 ms
22,472 KB
testcase_22 AC 1,261 ms
57,148 KB
testcase_23 AC 500 ms
64,120 KB
testcase_24 AC 348 ms
44,796 KB
testcase_25 AC 143 ms
18,428 KB
testcase_26 AC 147 ms
19,076 KB
testcase_27 AC 660 ms
83,956 KB
testcase_28 AC 663 ms
83,956 KB
testcase_29 AC 664 ms
83,956 KB
testcase_30 AC 662 ms
83,956 KB
testcase_31 AC 754 ms
83,956 KB
testcase_32 AC 669 ms
83,960 KB
testcase_33 AC 666 ms
83,960 KB
testcase_34 AC 666 ms
83,956 KB
testcase_35 AC 661 ms
83,956 KB
testcase_36 AC 662 ms
83,956 KB
testcase_37 AC 667 ms
83,988 KB
testcase_38 AC 664 ms
83,828 KB
testcase_39 AC 660 ms
83,832 KB
testcase_40 AC 668 ms
83,956 KB
testcase_41 AC 659 ms
83,956 KB
testcase_42 AC 656 ms
83,828 KB
testcase_43 AC 658 ms
83,956 KB
testcase_44 AC 658 ms
83,956 KB
testcase_45 AC 659 ms
83,956 KB
testcase_46 AC 662 ms
83,956 KB
testcase_47 AC 629 ms
83,956 KB
testcase_48 AC 629 ms
83,956 KB
testcase_49 AC 635 ms
83,956 KB
testcase_50 AC 632 ms
83,956 KB
testcase_51 AC 629 ms
83,956 KB
testcase_52 AC 655 ms
83,956 KB
testcase_53 AC 654 ms
83,956 KB
testcase_54 AC 657 ms
83,956 KB
testcase_55 AC 656 ms
83,956 KB
testcase_56 AC 658 ms
83,952 KB
testcase_57 AC 602 ms
83,952 KB
testcase_58 AC 667 ms
83,956 KB
testcase_59 AC 659 ms
83,952 KB
testcase_60 AC 658 ms
83,956 KB
testcase_61 AC 658 ms
83,832 KB
testcase_62 AC 657 ms
83,956 KB
testcase_63 AC 652 ms
84,080 KB
testcase_64 AC 654 ms
83,956 KB
testcase_65 AC 649 ms
83,956 KB
testcase_66 WA -
testcase_67 AC 645 ms
83,956 KB
testcase_68 AC 648 ms
83,956 KB
testcase_69 AC 646 ms
83,956 KB
testcase_70 WA -
testcase_71 WA -
testcase_72 AC 647 ms
83,952 KB
testcase_73 AC 648 ms
83,956 KB
testcase_74 AC 3 ms
6,940 KB
testcase_75 AC 659 ms
83,952 KB
testcase_76 AC 657 ms
83,824 KB
testcase_77 AC 657 ms
83,952 KB
testcase_78 AC 654 ms
83,960 KB
testcase_79 AC 659 ms
83,956 KB
testcase_80 AC 658 ms
83,956 KB
testcase_81 AC 659 ms
83,952 KB
testcase_82 AC 659 ms
83,952 KB
testcase_83 AC 663 ms
83,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
このコード、と~おれ!
Be accepted!
∧_∧ 
(。・ω・。)つ━☆・*。
⊂   ノ    ・゜+.
 しーJ   °。+ *´¨)
          .· ´¸.·*´¨) ¸.·*¨)
		            (¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
#include <array>
#include <chrono>
#include <unordered_set>

//#pragma GCC target("arch=skylake-avx512")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse4")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define repeat(i, n, m) for(int i = n; i < (m); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)
#define printLdb(a) printf("%.50Lf\n", a)
#define printdbd(a) printf("%.16lf\n", a)
#define prints(s) printf("%s\n", s.c_str())
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d))

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-14;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
inline T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
inline T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

//cpp_int
#if __has_include(<boost/multiprecision/cpp_int.hpp>)
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace boost::multiprecision;
#else
using cpp_int = ll;
#endif

//atcoder library
#if __has_include(<atcoder/all>)
#include <atcoder/all>
//using namespace atcoder;
#endif

/*
	random_device seed_gen;
	mt19937 engine(seed_gen());
	uniform_int_distribution dist(1, 100);
*/


/*----------------------------------------------------------------------------------*/

// montgomery modint (MOD < 2^62, MOD is odd)
struct MontgomeryModInt64 {
    using mint = MontgomeryModInt64;
    using u64 = uint64_t;
    using u128 = __uint128_t;

    // static menber
    static u64 MOD;
    static u64 INV_MOD;  // INV_MOD * MOD ≡ 1 (mod 2^64)
    static u64 T128;  // 2^128 (mod MOD)

    // inner value
    u64 val;

    // constructor
    MontgomeryModInt64() : val(0) { }
    MontgomeryModInt64(long long v) : val(reduce((u128(v) + MOD)* T128)) { }
    u64 get() const {
        u64 res = reduce(val);
        return res >= MOD ? res - MOD : res;
    }

    // mod getter and setter
    static u64 get_mod() { return MOD; }
    static void set_mod(u64 mod) {
        assert(mod < (1LL << 62));
        assert((mod & 1));
        MOD = mod;
        T128 = -u128(mod) % mod;
        INV_MOD = get_inv_mod();
    }
    static u64 get_inv_mod() {
        u64 res = MOD;
        for (int i = 0; i < 5; ++i) res *= 2 - MOD * res;
        return res;
    }
    static u64 reduce(const u128& v) {
        return (v + u128(u64(v) * u64(-INV_MOD)) * MOD) >> 64;
    }

    // arithmetic operators
    mint operator - () const { return mint() - mint(*this); }
    mint operator + (const mint& r) const { return mint(*this) += r; }
    mint operator - (const mint& r) const { return mint(*this) -= r; }
    mint operator * (const mint& r) const { return mint(*this) *= r; }
    mint operator / (const mint& r) const { return mint(*this) /= r; }
    mint& operator += (const mint& r) {
        if ((val += r.val) >= 2 * MOD) val -= 2 * MOD;
        return *this;
    }
    mint& operator -= (const mint& r) {
        if ((val += 2 * MOD - r.val) >= 2 * MOD) val -= 2 * MOD;
        return *this;
    }
    mint& operator *= (const mint& r) {
        val = reduce(u128(val) * r.val);
        return *this;
    }
    mint& operator /= (const mint& r) {
        *this *= r.inv();
        return *this;
    }
    mint inv() const { return pow(MOD - 2); }
    mint pow(u128 n) const {
        mint res(1), mul(*this);
        while (n > 0) {
            if (n & 1) res *= mul;
            mul *= mul;
            n >>= 1;
        }
        return res;
    }

    // other operators
    bool operator == (const mint& r) const {
        return (val >= MOD ? val - MOD : val) == (r.val >= MOD ? r.val - MOD : r.val);
    }
    bool operator != (const mint& r) const {
        return (val >= MOD ? val - MOD : val) != (r.val >= MOD ? r.val - MOD : r.val);
    }
    friend istream& operator >> (istream& is, mint& x) {
        long long t;
        is >> t;
        x = mint(t);
        return is;
    }
    friend ostream& operator << (ostream& os, const mint& x) {
        return os << x.get();
    }
    friend mint modpow(const mint& r, long long n) {
        return r.pow(n);
    }
    friend mint modinv(const mint& r) {
        return r.inv();
    }
};

typename MontgomeryModInt64::u64
MontgomeryModInt64::MOD, MontgomeryModInt64::INV_MOD, MontgomeryModInt64::T128;

// Miller-Rabin
bool MillerRabin(long long N, vector<long long> A) {
    using mint = MontgomeryModInt64;
    mint::set_mod(N);

    long long s = 0, d = N - 1;
    while (d % 2 == 0) {
        ++s;
        d >>= 1;
    }
    for (auto a : A) {
        if (N <= a) return true;
        mint x = mint(a).pow(d);
        if (x != 1) {
            long long t;
            for (t = 0; t < s; ++t) {
                if (x == N - 1) break;
                x *= x;
            }
            if (t == s) return false;
        }
    }
    return true;
}

bool is_prime(long long N) {
    if (N <= 1) return false;
    else if (N == 2) return true;
    else if (N % 2 == 0) return false;
    else if (N < 4759123141LL)
        return MillerRabin(N, { 2, 7, 61 });
    else
        return MillerRabin(N, { 2, 325, 9375, 28178, 450775, 9780504, 1795265022 });
}

//https://drken1215.hatenablog.com/entry/2023/05/23/233000

random_device seed_gen;
mt19937 engine(seed_gen());
uniform_int_distribution<ll> dist(1e9, 3e9);

int main() {

	int n, q;
    ll k;
	scanf("%d%d", &n, &q);
	cin >> k;
	vector<ll> a(n);
	rep(i, n)cin >> a[i];
	vector<ll> rnd(100);
	rep(i, 100) {
		ll x = dist(engine);
		while (not is_prime(x))x = dist(engine);
		rnd[i] = x;
	}
	vector<vector<ll>> cs;
	rep(i, 100) {
        ll kk = rnd[i];
        ll x = 1;
		x %= kk;
		vector<ll> b(n);
		rep(j, n) {
			b[j] = (a[j] % kk) * x;
			b[j] %= kk;
			x *= k;
			x %= kk;
		}
		vector<ll> c(n + 1);
		rep(j, n) {
			c[j + 1] = c[j] + b[j];
			c[j + 1] %= kk;
		}
		cs.push_back(c);
	}
	rep(i, q) {
		int l, r;
		scanf("%d%d", &l, &r);
		--l;
		int ans = 0;
		rep(j, 100) {
            ll x = cs[j][r] - cs[j][l];
			x += rnd[j];
			x %= rnd[j];
			if (x != 0) {
				ans = 1;
				break;
			}
		}
		printyn(ans);
	}

	Please AC;
}
0