結果
問題 |
No.1349 Subset Product Queries
|
ユーザー |
![]() |
提出日時 | 2021-02-11 06:16:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,534 bytes |
コンパイル時間 | 3,786 ms |
コンパイル使用メモリ | 214,964 KB |
最終ジャッジ日時 | 2025-01-18 17:16:33 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 10 RE * 20 |
ソースコード
#include<bits/stdc++.h> //using namespace std; #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++) #define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++) #define per(i,j,n) for(int i=(int)(j);(int)(n)<=i;i--) #define ALL(a) (a).begin(),(a).end() #define pb emplace_back #define mp std::make_pair // #define endl "\n" //using std::endl; using std::cin; using std::cout; using ll=short; using std::vector; using std::string; using std::upper_bound; using std::lower_bound; using vi=vector<ll>; using vii=vector<vi>; using pii=std::pair<ll,ll>; vii dp; vector<vii> mem; vi A; ll dfs(ll now,ll val){ if(dp[now][val]!=-1) return dp[now][val]; if(now==0) return 0; if(A[now-1]==val) return now; dp[now][val]=std::max(dp[now][val],dfs(now-1,val)); for(auto p:mem[A[now-1]][val]) dp[now][val]=std::max(dp[now][val],dfs(now-1,p)); return dp[now][val]; } int main(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); std::random_device rnd; std::mt19937 mt(rnd()); ll N,Q,P; cin>>N>>Q>>P; A.resize(N); rep(i,0,N) cin>>A[i]; dp.resize(N+1,vi(P,-1)); mem.resize(P,vii(P)); rep(i,0,P){ rep(j,0,P) mem[i][(int)i*j%P].pb(j); } while(Q--){ ll L,R,K; cin>>L>>R>>K; string ans="No"; if(dfs(R,K)>=L) ans="Yes"; cout<<ans<<endl; } }