题意略,题解生成函数练习题,1+(q-ai)x卷积即可,线段树优化(类似分治思想)

  1. //#pragma GCC optimize(2)
  2. //#pragma GCC optimize(3)
  3. //#pragma GCC optimize(4)
  4. //#pragma GCC optimize("unroll-loops")
  5. //#pragma comment(linker, "/stack:200000000")
  6. //#pragma GCC optimize("Ofast,no-stack-protector")
  7. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  8. #include<bits/stdc++.h>
  9. //#include <bits/extc++.h>
  10. #define fi first
  11. #define se second
  12. #define db double
  13. #define mp make_pair
  14. #define pb push_back
  15. #define mt make_tuple
  16. //#define pi acos(-1.0)
  17. #define ll long long
  18. #define vi vector<int>
  19. #define mod 998244353
  20. #define ld long double
  21. //#define C 0.5772156649
  22. #define ls l,m,rt<<1
  23. #define rs m+1,r,rt<<1|1
  24. #define pll pair<ll,ll>
  25. #define pil pair<int,ll>
  26. #define pli pair<ll,int>
  27. #define pii pair<int,int>
  28. #define ull unsigned long long
  29. #define bpc __builtin_popcount
  30. #define base 1000000000000000000ll
  31. #define fin freopen("a.txt","r",stdin)
  32. #define fout freopen("a.txt","w",stdout)
  33. #define fio ios::sync_with_stdio(false);cin.tie(0)
  34. #define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
  35. inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
  36. inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
  37. inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
  38. template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
  39. template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
  40. inline ll mul(ll a,ll b,ll c){return (a*b-(ll)((ld)a*b/c)*c+c)%c;}
  41. 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;}
  42. 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;}
  43. using namespace std;
  44. //using namespace __gnu_pbds;
  45. const ld pi = acos(-1);
  46. const ull ba=233;
  47. const db eps=1e-5;
  48. const ll INF=0x3f3f3f3f3f3f3f3f;
  49. const int N=200000+10,maxn=2000000+10,inf=0x3f3f3f3f;
  50. ll x[N<<3],y[N<<3];
  51. int rev[N<<3];
  52. void getrev(int bit)
  53. {
  54. for(int i=0;i<(1<<bit);i++)
  55. rev[i]=(rev[i>>1]>>1) | ((i&1)<<(bit-1));
  56. }
  57. void ntt(ll *a,int n,int dft)
  58. {
  59. for(int i=0;i<n;i++)
  60. if(i<rev[i])
  61. swap(a[i],a[rev[i]]);
  62. for(int step=1;step<n;step<<=1)
  63. {
  64. ll wn=qp(3,(mod-1)/(step*2));
  65. if(dft==-1)wn=qp(wn,mod-2);
  66. for(int j=0;j<n;j+=step<<1)
  67. {
  68. ll wnk=1;
  69. for(int k=j;k<j+step;k++)
  70. {
  71. ll x=a[k];
  72. ll y=wnk*a[k+step]%mod;
  73. a[k]=(x+y)%mod;a[k+step]=(x-y+mod)%mod;
  74. wnk=wnk*wn%mod;
  75. }
  76. }
  77. }
  78. if(dft==-1)
  79. {
  80. ll inv=qp(n,mod-2);
  81. for(int i=0;i<n;i++)a[i]=a[i]*inv%mod;
  82. }
  83. }
  84. vi v[N<<2];
  85. int a[N],b[N];
  86. void solve(int l,int r,int rt)
  87. {
  88. if(l==r)
  89. {
  90. v[rt].clear();
  91. v[rt].pb(1);v[rt].pb(b[l]);
  92. // printf("%d\n",b[l]);
  93. return ;
  94. }
  95. int m=(l+r)>>1;
  96. solve(ls);solve(rs);
  97. int p=v[rt<<1].size(),q=v[rt<<1|1].size();
  98. int sz=0;
  99. while((1<<sz)<=p+q)sz++;
  100. getrev(sz);
  101. int len=(1<<sz);
  102. // printf("%d\n",len);
  103. for(int i=0;i<len;i++)
  104. {
  105. x[i]=(i<p?v[rt<<1][i]:0);
  106. y[i]=(i<q?v[rt<<1|1][i]:0);
  107. }
  108. ntt(x,len,1);ntt(y,len,1);
  109. for(int i=0;i<len;i++)x[i]=x[i]*y[i]%mod;
  110. ntt(x,len,-1);
  111. v[rt].clear();
  112. for(int i=0;i<len;i++)v[rt].pb(x[i]);
  113. while(v[rt].size()&&v[rt].back()==0)v[rt].pop_back();
  114. }
  115. int main()
  116. {
  117. // fin;
  118. int n,k;scanf("%d%d",&n,&k);
  119. for(int i=1;i<=n;i++)scanf("%d",&a[i]),a[i]%=mod;
  120. int q;scanf("%d",&q);
  121. while(q--)
  122. {
  123. int op,q,x,y,z;scanf("%d%d%d%d",&op,&q,&x,&y);
  124. if(op==1)
  125. {
  126. q%=mod,y%=mod;
  127. for(int i=1;i<=n;i++)
  128. {
  129. b[i]=(i==x?q-y:q-a[i]);
  130. if(b[i]<0)b[i]+=mod;
  131. }
  132. }
  133. else
  134. {
  135. scanf("%d",&z);
  136. q%=mod,z%=mod;
  137. for(int i=1;i<=n;i++)
  138. {
  139. if(x<=i&&i<=y)b[i]=((q-a[i]-z)%mod+mod)%mod;
  140. else b[i]=(q-a[i]+mod)%mod;
  141. }
  142. }
  143. solve(1,n,1);
  144. printf("%d\n",v[1][k]);
  145. }
  146. return 0;
  147. }
  148. /********************
  149. ********************/

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. 编写一个简单的内核驱动模块时报错 “/lib/modules/3.13.0-32-generic/bulid: 没有那个文件或目录。 停止。”

    编写一个简单的内核驱动模块 static int hello_init() { printk(“hello,I am in kernel now\n”); ; } void addfunc(int a ...

  2. vue与webpack

    由于最近在vue-cli生成的webpack模板项目的基础上写一个小东西,开发过程中需要改动到build和config里面一些相关的配置,所以刚好趁此机会将所有配置文件看一遍,理一理思路,也便于以后修 ...

  3. 随笔记录 yum -y clean all出错解决方案

    出现以下问题的解决方案: 使用解决方案之前,要先确定一下几种情况: 1.检查光盘是否挂载 2.ISO映像文件是否使用正确 解决方案1: rm -rf /var/cache/yum/* yum repo ...

  4. easyui datagrid 绑定从后台得到的复杂的特殊数据结构

    由于项目需要,从后台得到的数据统一为了类似{state:xxx,data:xxx,message:xxx}类型 但是easyui datagrid却只认{total:xxx,rows:xxx}...所 ...

  5. tf-idf 词条权重计算

    在文本分类问题中,某些高频词一直出现,这样的词对区分文档的作用不大,例如: D1:  'Job was the chairman of Apple Inc.' D2:  'I like to use ...

  6. 实时监听input输入情况

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. 【JZOJ6411】上网

    description analysis 如果把所有大小关系连成边,小的往大的连,就可以直接上拓扑 暴力连边时间复杂度\(O(n^2)\),然而连边的过程,考虑用线段树优化 线段树上的所有儿子节点向父 ...

  8. bzoj1006题解

    [题意分析] 给你一张弦图,求图的最小染色数. [解题思路] 这篇讲稿已经讲得很详尽了.. 直接求完美消除序列,然后倒着染色即可.复杂度O(n2+nm). [参考程序] 求完美消除序列我是用的MCS( ...

  9. 浅谈使用RestKit将服务器的Json直接映射为本地对象

    RestKit是一个主要用于iOS上网络通信的开源框架,除了发送请求与接受响应这些基本功能外,还附带coredata,以及将远程JSON映射为本地对象的功能.目前版本0.9.3,coredata还不是 ...

  10. Spring Boot 遇到空指针

    @Autowired private IRoadRescueService roadRescueService; 千万不要把注入的service类设为static