結果
問題 | No.1068 #いろいろな色 / Red and Blue and more various colors (Hard) |
ユーザー | leafirby |
提出日時 | 2020-05-20 02:11:33 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,176 ms / 3,500 ms |
コード長 | 4,004 bytes |
コンパイル時間 | 2,124 ms |
コンパイル使用メモリ | 180,872 KB |
実行使用メモリ | 17,096 KB |
最終ジャッジ日時 | 2024-11-06 02:10:51 |
合計ジャッジ時間 | 24,754 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,816 KB |
testcase_01 | AC | 4 ms
6,820 KB |
testcase_02 | AC | 3 ms
6,820 KB |
testcase_03 | AC | 23 ms
6,820 KB |
testcase_04 | AC | 14 ms
6,816 KB |
testcase_05 | AC | 15 ms
6,816 KB |
testcase_06 | AC | 14 ms
6,816 KB |
testcase_07 | AC | 13 ms
6,820 KB |
testcase_08 | AC | 14 ms
6,816 KB |
testcase_09 | AC | 16 ms
6,816 KB |
testcase_10 | AC | 8 ms
6,816 KB |
testcase_11 | AC | 12 ms
6,820 KB |
testcase_12 | AC | 8 ms
6,816 KB |
testcase_13 | AC | 1,172 ms
16,968 KB |
testcase_14 | AC | 1,164 ms
17,096 KB |
testcase_15 | AC | 1,169 ms
16,968 KB |
testcase_16 | AC | 1,167 ms
17,096 KB |
testcase_17 | AC | 1,162 ms
17,096 KB |
testcase_18 | AC | 1,164 ms
16,972 KB |
testcase_19 | AC | 1,159 ms
16,964 KB |
testcase_20 | AC | 1,155 ms
16,968 KB |
testcase_21 | AC | 1,158 ms
16,904 KB |
testcase_22 | AC | 1,163 ms
17,092 KB |
testcase_23 | AC | 1,161 ms
17,092 KB |
testcase_24 | AC | 1,166 ms
17,092 KB |
testcase_25 | AC | 1,176 ms
16,968 KB |
testcase_26 | AC | 1,163 ms
17,096 KB |
testcase_27 | AC | 1,165 ms
16,968 KB |
testcase_28 | AC | 1,159 ms
16,968 KB |
testcase_29 | AC | 1,146 ms
16,968 KB |
testcase_30 | AC | 1,151 ms
16,968 KB |
testcase_31 | AC | 3 ms
6,816 KB |
ソースコード
#include <bits/stdc++.h> #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; #define lli long long int #define uli unsigned long long int #define INF 9999999999 #define rep(i,m,n) for(lli i = m;i < n;i++) #define rrep(i,m,n) for(lli i=m-1;i>=n;i--) #define pb(n) push_back(n) #define UE(N) N.erase(unique(N.begin(),N.end()),N.end()); #define Sort(n) sort(n.begin(), n.end()) #define Rev(n) reverse(n.begin(),n.end()) #define Out(S) cout << S << endl #define NeOut(S) cout << S #define HpOut(S) cout << setprecision(25) << S << endl #define Vec(K,L,N,S) vector<L> K(N,S) #define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S)) #define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S))) #define pint pair<lli,lli> #define paf(L,R) pair<L,R> //#define mod 1000000007 #define MAX 10000000 #define ALL(a) a.begin(),a.end() #define chmax(a, b) a = (((a)<(b)) ? (b) : (a)) #define chmin(a, b) a = (((a)>(b)) ? (b) : (a)) lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T; Vec(P,lli,200000,0); lli modpow(lli n,lli k,lli m){ if(k==0)return 1; else if(k%2==1)return modpow(n,k-1,m)*n%m; else{ lli temp=modpow(n,k/2,m); return temp*temp%m; } } long long modinv(long long a, long long mod) { long long b = mod, u = 1, v = 0; while (b) { long long t = a/b; a -= t*b; swap(a, b); u -= t*v; swap(u, v); } u %= mod; if (u < 0) u += mod; return u; } const int MOD = 998244353; // to be set appropriately const long long PR = 3; // to be set appropriately void trans(vector<long long> &v, bool inv = false) { int n = (int)v.size(); for (int i = 0, j = 1; j < n-1; j++) { for (int k = n>>1; k > (i ^= k); k >>= 1); if (i > j) swap(v[i], v[j]); } for (int t = 2; t <= n; t <<= 1) { long long bw = modpow(PR, (MOD-1)/t, MOD); if (inv) bw = modinv(bw, MOD); for (int i = 0; i < n; i += t) { long long w = 1; for (int j = 0; j < t/2; ++j) { int j1 = i + j, j2 = i + j + t/2; long long c1 = v[j1], c2 = v[j2] * w % MOD; v[j1] = c1 + c2; v[j2] = c1 - c2 + MOD; while (v[j1] >= MOD) v[j1] -= MOD; while (v[j2] >= MOD) v[j2] -= MOD; w = w * bw % MOD; } } } if (inv) { long long inv_n = modinv(n, MOD); for (int i = 0; i < n; ++i) v[i] = v[i] * inv_n % MOD; } } vector<long long> NTT(vector<long long> A, vector<long long> B) { int size_a = 1; while (size_a < A.size()) size_a <<= 1; int size_b = 1; while (size_b < B.size()) size_b <<= 1; int size_fft = max(size_a, size_b) << 1; vector<long long> cA(size_fft, 0), cB(size_fft, 0), cC(size_fft, 0); for (int i = 0; i < A.size(); ++i) cA[i] = A[i]; for (int i = 0; i < B.size(); ++i) cB[i] = B[i]; trans(cA); trans(cB); for (int i = 0; i < size_fft; ++i) cC[i] = cA[i] * cB[i] % MOD; trans(cC, true); vector<long long> res((int)A.size() + (int)B.size() - 1); for (int i = 0; i < res.size(); ++i) res[i] = cC[i]; return res; } vector<lli> divide_and_solve(int left,int right){//f_l(x)からf_r(x)までの積 if(right-left==1){ Vec(v,lli,2,1); v[1]=P[left]; return v; } auto vl=divide_and_solve(left,(left+right)/2); auto vr=divide_and_solve((left+right)/2,right); int ls=vl.size(),rs=vr.size(); if(min(ls,rs)<130){ Vec(marge,lli,ls+rs-1,0); rep(i,0,ls)rep(j,0,rs){ marge[i+j]+=(vl[i]*vr[j])%MOD; marge[i+j]%=MOD; } return marge; } else return NTT(vl,vr); } int main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> N >> M; Vec(Q,lli,M,0); P.resize(N); rep(i,0,N){ cin >> P[i]; P[i]--; P[i]%=MOD; } rep(i,0,M)cin >> Q[i]; auto ans=divide_and_solve(0,N); Rev(ans); rep(i,0,M)Out(ans[Q[i]]%MOD); }