题意略,题解生成函数练习题,1+(q-ai)x卷积即可,线段树优化(类似分治思想)
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
//#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 998244353
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
#define base 1000000000000000000ll
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll mul(ll a,ll b,ll c){return (a*b-(ll)((ld)a*b/c)*c+c)%c;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=mul(ans,a,c);a=mul(a,a,c),b>>=1;}return ans;}
using namespace std;
//using namespace __gnu_pbds;
const ld pi = acos(-1);
const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=200000+10,maxn=2000000+10,inf=0x3f3f3f3f;
ll x[N<<3],y[N<<3];
int rev[N<<3];
void getrev(int bit)
{
for(int i=0;i<(1<<bit);i++)
rev[i]=(rev[i>>1]>>1) | ((i&1)<<(bit-1));
}
void ntt(ll *a,int n,int dft)
{
for(int i=0;i<n;i++)
if(i<rev[i])
swap(a[i],a[rev[i]]);
for(int step=1;step<n;step<<=1)
{
ll wn=qp(3,(mod-1)/(step*2));
if(dft==-1)wn=qp(wn,mod-2);
for(int j=0;j<n;j+=step<<1)
{
ll wnk=1;
for(int k=j;k<j+step;k++)
{
ll x=a[k];
ll y=wnk*a[k+step]%mod;
a[k]=(x+y)%mod;a[k+step]=(x-y+mod)%mod;
wnk=wnk*wn%mod;
}
}
}
if(dft==-1)
{
ll inv=qp(n,mod-2);
for(int i=0;i<n;i++)a[i]=a[i]*inv%mod;
}
}
vi v[N<<2];
int a[N],b[N];
void solve(int l,int r,int rt)
{
if(l==r)
{
v[rt].clear();
v[rt].pb(1);v[rt].pb(b[l]);
// printf("%d\n",b[l]);
return ;
}
int m=(l+r)>>1;
solve(ls);solve(rs);
int p=v[rt<<1].size(),q=v[rt<<1|1].size();
int sz=0;
while((1<<sz)<=p+q)sz++;
getrev(sz);
int len=(1<<sz);
// printf("%d\n",len);
for(int i=0;i<len;i++)
{
x[i]=(i<p?v[rt<<1][i]:0);
y[i]=(i<q?v[rt<<1|1][i]:0);
}
ntt(x,len,1);ntt(y,len,1);
for(int i=0;i<len;i++)x[i]=x[i]*y[i]%mod;
ntt(x,len,-1);
v[rt].clear();
for(int i=0;i<len;i++)v[rt].pb(x[i]);
while(v[rt].size()&&v[rt].back()==0)v[rt].pop_back();
}
int main()
{
// fin;
int n,k;scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)scanf("%d",&a[i]),a[i]%=mod;
int q;scanf("%d",&q);
while(q--)
{
int op,q,x,y,z;scanf("%d%d%d%d",&op,&q,&x,&y);
if(op==1)
{
q%=mod,y%=mod;
for(int i=1;i<=n;i++)
{
b[i]=(i==x?q-y:q-a[i]);
if(b[i]<0)b[i]+=mod;
}
}
else
{
scanf("%d",&z);
q%=mod,z%=mod;
for(int i=1;i<=n;i++)
{
if(x<=i&&i<=y)b[i]=((q-a[i]-z)%mod+mod)%mod;
else b[i]=(q-a[i]+mod)%mod;
}
}
solve(1,n,1);
printf("%d\n",v[1][k]);
}
return 0;
}
/********************
********************/