結果

問題 No.1349 Subset Product Queries
ユーザー V_Melville
提出日時 2024-11-13 21:14:17
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 844 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 3,003 ms
コンパイル使用メモリ 250,764 KB
実行使用メモリ 96,128 KB
最終ジャッジ日時 2024-11-13 21:14:37
合計ジャッジ時間 20,221 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

inline void chmax(int& x, int y) { if (x < y) x = y; }

int main() {
    int n, q, p;
    cin >> n >> q >> p;
    
    vector<int> a(n);    
    rep(i, n) cin >> a[i];
    
    vector dp(n+1, vector<int>(p, -1));
    rep(i, n) {
        rep(j, p) {
            chmax(dp[i+1][j], dp[i][j]);
            chmax(dp[i+1][j*a[i]%p], dp[i][j]);
        }
        dp[i+1][a[i]] = i; 
    }
    
    rep(qi, q) {
        int l, r, k;
        cin >> l >> r >> k;
        --l;
        
        if (dp[r][k] >= l) puts("Yes");
        else puts("No");
    }
    
    return 0;
}
0