結果

問題 No.854 公平なりんご分配
コンテスト
ユーザー zelda_master
提出日時 2026-07-26 14:18:28
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.90.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 209 ms / 3,153 ms
+ 565µs
コード長 1,643 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,156 ms
コンパイル使用メモリ 172,368 KB
実行使用メモリ 125,824 KB
最終ジャッジ日時 2026-07-26 14:18:49
合計ジャッジ時間 8,864 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 92
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <cstdio>
#include <bitset>
#include <vector>

using namespace std;

const int N = 100010, M = 2010;

bitset<M> is_comp;
vector<int> primes;
int n, q, a[N], ps_cnt[N][310], zero_cnt[N];

void EulerSieve() {
    is_comp[0] = is_comp[1] = true;
    for (int i = 2; i < M; ++i) {
        if (!is_comp[i]) primes.push_back(i);
        for (auto p : primes) {
            if (1LL * i * p >= M) break;
            is_comp[i * p] = true;
            if (i % p == 0) break;
        }
    }
}

int main() {
    // freopen("apple.in", "r", stdin);
    // freopen("apple.out", "w", stdout);

    EulerSieve();
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        zero_cnt[i] = zero_cnt[i - 1] + (a[i] == 0);
        if (a[i] == 0) continue;
        int x = a[i];
        for (int j = 0; j < primes.size(); ++j) {
            int p = primes[j];
            ps_cnt[i][j] = ps_cnt[i - 1][j];
            while (x % p == 0) {
                ++ps_cnt[i][j];
                x /= p;
            }
        }
    }

    scanf("%d", &q);
    while (q--) {
        int p, l, r;
        scanf("%d%d%d", &p, &l, &r);
        int zeros = zero_cnt[r] - zero_cnt[l - 1];
        if (zeros) puts("Yes");
        else {
            for (int i = 0; i < primes.size(); ++i) {
                int pp = primes[i];
                int cnt = ps_cnt[r][i] - ps_cnt[l - 1][i];
                while (cnt && (p % pp == 0)) {
                    p /= pp;
                    --cnt;
                }
            }
            if (p == 1) puts("Yes");
            else puts("NO");
        }
    }

    return 0;
}
0