結果
| 問題 | No.1068 #いろいろな色 / Red and Blue and more various colors (Hard) |
| コンテスト | |
| ユーザー |
sugarrr
|
| 提出日時 | 2020-05-29 22:12:11 |
| 言語 | C++17(clang) (clang++ 21.1.8 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 6,187 bytes |
| 記録 | |
| コンパイル時間 | 2,294 ms |
| コンパイル使用メモリ | 166,688 KB |
| 実行使用メモリ | 17,736 KB |
| 最終ジャッジ日時 | 2024-11-30 18:14:11 |
| 合計ジャッジ時間 | 90,698 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 WA * 10 TLE * 18 |
ソースコード
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
/*
#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
*/
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
ll c=a%i_7;
if(c>=0)return c;
return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
void mod_print(ll k){
ll P=1000;
rep(y,1,P){
ll x=mod(y*k);
if(x+P>=i_7){
x-=i_7;
}
if(abs(x)<=P){
cout<<x<<"/"<<y<<endl;
return;
}
}
cout<<"nun"<<endl;
}
//////////////////////////
namespace NTT { // stanicさん
std::vector<int> tmp;
size_t sz = 1;
inline int powMod(int n, int p, int m) {
int res = 1;
while (p) {
if (p & 1) res = (ll)res * n % m;
n = (ll)n * n % m;
p >>= 1;
}
return (int)res;
}
inline int invMod(int n, int m) {
return powMod(n, m - 2, m);
}
template <int Mod, int PrimitiveRoot>
struct NTTPart {
static std::vector<int> ntt(std::vector<int> a, bool inv = false) {
size_t mask = sz - 1;
size_t p = 0;
for (size_t i = sz >> 1; i >= 1; i >>= 1) {
auto& cur = (p & 1) ? tmp : a;
auto& nex = (p & 1) ? a : tmp;
int e = powMod(PrimitiveRoot, (Mod - 1) / sz * i, Mod);
if (inv) e = invMod(e, Mod);
int w = 1;
for (size_t j = 0; j < sz; j += i) {
for (size_t k = 0; k < i; ++k) {
nex[j + k] = (cur[((j << 1) & mask) + k] + (ll)w * cur[(((j << 1) + i) & mask) + k]) % Mod;
}
w = (ll)w * e % Mod;
}
++p;
}
if (p & 1) std::swap(a, tmp);
if (inv) {
int invSz = invMod(sz, Mod);
for (size_t i = 0; i < sz; ++i) a[i] = (ll)a[i] * invSz % Mod;
}
return a;
}
static std::vector<int> mul(std::vector<int> a, std::vector<int> b) {
a = ntt(a);
b = ntt(b);
for (size_t i = 0; i < sz; ++i) a[i] = (ll)a[i] * b[i] % Mod;
a = ntt(a, true);
return a;
}
};
constexpr int M[] = { 1224736769, 469762049, 167772161 };
constexpr int PR[] = { 3, 3, 3 };
constexpr int NTT_CONVOLUTION_TIME = 1;
inline void garner(std::vector<int> *c, int mod) {
if (NTT_CONVOLUTION_TIME == 1) {
for (auto& x : c[0]) x %= mod;
}
else if (NTT_CONVOLUTION_TIME == 2) {
const int r01 = invMod(M[0], M[1]);
for (size_t i = 0; i < sz; ++i) {
c[1][i] = (c[1][i] - c[0][i]) * (ll)r01 % M[1];
if (c[1][i] < 0) c[1][i] += M[1];
c[0][i] = (c[0][i] + (ll)c[1][i] * M[0]) % mod;
}
}
else if (NTT_CONVOLUTION_TIME == 1) {
const int R01 = invMod(M[0], M[1]);
const int R02 = invMod(M[0], M[2]);
const int R12 = invMod(M[1], M[2]);
const int M01 = (ll)M[0] * M[1] % mod;
for (size_t i = 0; i < sz; ++i) {
c[1][i] = (c[1][i] - c[0][i]) * (ll)R01 % M[1];
if (c[1][i] < 0) c[1][i] += M[1];
c[2][i] = ((c[2][i] - c[0][i]) * (ll)R02 % M[2] - c[1][i]) * R12 % M[2];
if (c[2][i] < 0) c[2][i] += M[2];
c[0][i] = (c[0][i] + (ll)c[1][i] * M[0] + (ll)c[2][i] * M01) % mod;
}
}
}
std::vector<int> mul(std::vector<int> a, std::vector<int> b, int mod) {
for (auto& x : a) x %= mod;
for (auto& x : b) x %= mod;
size_t m = a.size() + b.size() - 1;
sz = 1;
while (m > sz) sz <<= 1;
tmp.resize(sz);
a.resize(sz, 0);
b.resize(sz, 0);
std::vector<int> c[NTT_CONVOLUTION_TIME];
if (NTT_CONVOLUTION_TIME >= 1) c[0] = NTTPart<M[0], PR[0]>::mul(a, b);
if (NTT_CONVOLUTION_TIME >= 2) c[1] = NTTPart<M[1], PR[1]>::mul(a, b);
if (NTT_CONVOLUTION_TIME >= 3) c[2] = NTTPart<M[2], PR[2]>::mul(a, b);
for (auto& v : c) v.resize(m);
garner(c, mod);
return c[0];
}
};
int SOLVE(){
/*a.pb(1);a.pb(2);
b.pb(1);b.pb(4);
auto c(NTT::mul(a, b, i_7));
for(auto x:c)cout<<x<<" ";*/
ll n,q;cin>>n>>q;
vector<int>c;c.pb(1);
rep(zx,0,n-1){
vector<int>a(2);
a[0]=1;cin>>a[1];
a[1]--;
c=NTT::mul(a,c,i_7);
}
//for(auto x:c)cout<<x<<" ";
rep(i,0,q-1){
ll t;cin>>t;
cout<<mod(c[n-t])<<endl;
}
return 0;
}
int main(){fastio
clock_t start = clock();
SOLVE();
clock_t end = clock();
const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
cerr<<endl<<time<<"ms"<<endl;
return 0;
}
sugarrr