题意略,题解生成函数练习题,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;
}
/******************** ********************/

Bubble Cup 12 - Finals [Online Mirror, unrated, Div. 1] E. Product Tuples的更多相关文章

  1. Bubble Cup 12 - Finals Online Mirror, unrated, Div. 1

    Bubble Cup 12 - Finals Online Mirror, unrated, Div. 1 C. Jumping Transformers 我会状压 DP! 用 \(dp[x][y][ ...

  2. Bubble Cup 13 - Finals [Online Mirror, unrated, Div. 1] K. Lonely Numbers (数学)

    题意:定义两个数\(a,b\)是朋友,如果:\(gcd(a,b)\),\(\frac{a}{gcd(a,b)}\),\(\frac{b}{gcd(a,b)}\)能构成三角形,现在给你一个正整数\(n\ ...

  3. 【简单dfs】Bubble Cup 14 - Finals Online Mirror (Unrated, ICPC Rules, Teams Preferred, Div. 2), problem: (J) Robot Factory,

    传送门  Problem - 1600J - Codeforces 题目   题意 给定n行m列, 求每个连通块由多少格子组成,并将格子数从大到小排序输出 对于每个格子都有一个数(0~15),将其转化 ...

  4. Bubble Cup 11 - Finals [Online Mirror, Div. 1]题解 【待补】

    Bubble Cup 11 - Finals [Online Mirror, Div. 1] 一场很好玩的题啊! I. Palindrome Pairs 枚举哪种字符出现奇数次. G. AI robo ...

  5. Codeforces Bubble Cup 8 - Finals [Online Mirror] B. Bribes lca

    题目链接: http://codeforces.com/contest/575/problem/B 题解: 把链u,v拆成u,lca(u,v)和v,lca(u,v)(v,lca(u,v)是倒过来的). ...

  6. Codeforces Bubble Cup 8 - Finals [Online Mirror]H. Bots 数学

    H. Bots Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/H Desc ...

  7. Codeforces Bubble Cup 8 - Finals [Online Mirror] D. Tablecity 数学题

    D. Tablecity Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/D ...

  8. Codeforces Bubble Cup 8 - Finals [Online Mirror] F. Bulbo DP

    F. Bulbo Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/F Des ...

  9. Bubble Cup X - Finals [Online Mirror]

    来自FallDream的博客,未经允许,请勿转载,谢谢. 组了个菜鸡队打cf上的ACM比赛 比较快做完了8题但是菜的抠脚罚时巨多,所以最后被顶到了19名(居然没出首页) 自己的号自从上次疯狂掉分就没动 ...

随机推荐

  1. 2018-2-13-win10-edge扩展

    title author date CreateTime categories win10 edge扩展 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:23 ...

  2. Spring入门(三)

    测试Spring Bean的自动化装配 方式一:使用配置文件方式启动组件扫描 准备一个接口 package soundsystem; public interface CompactDisc { vo ...

  3. 文本聚合函数(wm_concat, listagg, group_concat, string_agg)

    实现目标   1.聚合文本   2.聚合文本(去重)   3.聚合文本(去重),按照指定字段排序   4.聚合文本(去重),按照指定字段排序,替换默认逗号分隔符 MySQL: group_concat ...

  4. 41. wait notify 方法

    wait()  等待,如果一个线程执行了wait方法,那么该线程就会进去一个以锁对象为标识符的线程池中等待 notity() 唤醒,如果一个线程执行了notity方法,那么就会唤醒以锁对象为标识符的线 ...

  5. Annotation详解

    转自:http://www.doc88.com/p-995532241886.html 首先我们定义一个简单的注解 package com.qjy.annotation; import java.la ...

  6. Android Telephony分析(一) ---- Phone详解

    目录: Phone的继承关系与PhoneFactory(GsmCdmaPhone.ImsPhone.SipPhone) Phone进程的启动 Phone对象的初始化(DefaultPhoneNotif ...

  7. mysql 实现批量导入,并解决中文乱码问题

    public static String url = "jdbc:mysql://ip/database?characterEncoding=UTF-8"; //在database ...

  8. 为什么 TCP 建立连接是三次握手,关闭连接确是四次挥手呢?

    Java技术栈 www.javastack.cn 优秀的Java技术公众号 作者:小书go https://blog.csdn.net/qzcsu/article/details/72861891 背 ...

  9. Mac Eclipse常用快捷键

    Option + Command + X: 运行 Command + O:显示大纲 Command + 1:快速修复 Command + D:删除当前行 Command + Option + ↓:复制 ...

  10. msSql Server 修复数据库

    --rz要替换为修复数据库DBCC CHECKTABLE ('rz'); use master declare @databasename varchar(255) set @databasename ...