题目链接 https://nanti.jisuanke.com/t/28872

解析 递推 直接套杜教板子

AC代码

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <string>
  7. #include <map>
  8. #include <set>
  9. #include <iostream>
  10. #include <cassert>
  11. using namespace std;
  12. #define rep(i,a,n) for (int i=a;i<n;i++)
  13. #define per(i,a,n) for (int i=n-1;i>=a;i--)
  14. #define pb push_back
  15. #define mp make_pair
  16. #define all(x) (x).begin(),(x).end()
  17. #define fi first
  18. #define se second
  19. #define SZ(x) ((int)(x).size())
  20. typedef vector<int> VI;
  21. typedef long long ll;
  22. typedef pair<int,int> PII;
  23. const int maxn=1e6+;
  24. const ll mod=;
  25. ll powmod(ll a,ll b) {ll res=;a%=mod; assert(b>=); for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
  26. // head
  27.  
  28. int _,n,k;
  29. int a[maxn],c[maxn];
  30. namespace linear_seq {
  31. const int N=;
  32. ll res[N],base[N],_c[N],_md[N];
  33.  
  34. vector<int> Md;
  35. void mul(ll *a,ll *b,int k) {
  36. rep(i,,k+k) _c[i]=;
  37. rep(i,,k) if (a[i]) rep(j,,k) _c[i+j]=(_c[i+j]+a[i]*b[j])%mod;
  38. for (int i=k+k-;i>=k;i--) if (_c[i])
  39. rep(j,,SZ(Md)) _c[i-k+Md[j]]=(_c[i-k+Md[j]]-_c[i]*_md[Md[j]])%mod;
  40. rep(i,,k) a[i]=_c[i];
  41. }
  42. int solve(ll n,VI a,VI b) { // a 系数 b 初值 b[n+1]=a[0]*b[n]+...
  43. // printf("%d\n",SZ(b));
  44. ll ans=,pnt=;
  45. int k=SZ(a);
  46. assert(SZ(a)==SZ(b));
  47. rep(i,,k) _md[k--i]=-a[i];_md[k]=;
  48. Md.clear();
  49. rep(i,,k) if (_md[i]!=) Md.push_back(i);
  50. rep(i,,k) res[i]=base[i]=;
  51. res[]=;
  52. while ((1ll<<pnt)<=n) pnt++;
  53. for (int p=pnt;p>=;p--) {
  54. mul(res,res,k);
  55. if ((n>>p)&) {
  56. for (int i=k-;i>=;i--) res[i+]=res[i];res[]=;
  57. rep(j,,SZ(Md)) res[Md[j]]=(res[Md[j]]-res[k]*_md[Md[j]])%mod;
  58. }
  59. }
  60. rep(i,,k) ans=(ans+res[i]*b[i])%mod;
  61. if (ans<) ans+=mod;
  62. return ans;
  63. }
  64. VI BM(VI s) {
  65. VI C(,),B(,);
  66. int L=,m=,b=;
  67. rep(n,,SZ(s)) {
  68. ll d=;
  69. rep(i,,L+) d=(d+(ll)C[i]*s[n-i])%mod;
  70. if (d==) ++m;
  71. else if (*L<=n) {
  72. VI T=C;
  73. ll c=mod-d*powmod(b,mod-)%mod;
  74. while (SZ(C)<SZ(B)+m) C.pb();
  75. rep(i,,SZ(B)) C[i+m]=(C[i+m]+c*B[i])%mod;
  76. L=n+-L; B=T; b=d; m=;
  77. } else {
  78. ll c=mod-d*powmod(b,mod-)%mod;
  79. while (SZ(C)<SZ(B)+m) C.pb();
  80. rep(i,,SZ(B)) C[i+m]=(C[i+m]+c*B[i])%mod;
  81. ++m;
  82. }
  83. }
  84. return C;
  85. }
  86. int gao(VI a,ll n) {
  87. VI c=BM(a);
  88. c.erase(c.begin());
  89. rep(i,,SZ(c)) c[i]=(mod-c[i])%mod;
  90. return solve(n,c,VI(a.begin(),a.begin()+SZ(c)));
  91. }
  92. };
  93.  
  94. int main() {
  95. while(scanf("%d%d",&n,&k)==)
  96. {
  97. for(int i=;i<=n;i++)scanf("%d",&a[i]);
  98. for(int i=;i<=n;i++)scanf("%d",&c[i]);
  99. for(int i=n+;i<=n*;i++)
  100. {
  101. a[i]=;
  102. for(int j=;j<=n;j++)
  103. a[i]=(a[i]+1ll*a[i-j]*c[j]%mod)%mod;
  104. }
  105. VI g;g.clear();
  106. for(int i=;i<=*n;i++)g.pb(a[i]);
  107. cout<<linear_seq::gao(g,k-)<<endl;
  108. }
  109. }

................................................................................................................................................................

  1. #include <bits/stdc++.h>
  2. #define fir first
  3. #define se second
  4. #define pb push_back
  5. #define ll long long
  6. #define mp make_pair
  7. #define rep(i,a,n) for (int i=a;i<n;i++)
  8. #define per(i,a,n) for (int i=n-1;i>=a;i--)
  9. #define all(x) (x).begin(),(x).end()
  10. #define SZ(x) ((int)(x).size())
  11. using namespace std;
  12. typedef vector<ll> VI;
  13. typedef pair<int,int> PII;
  14. const int maxn=1e5+;
  15. const int maxm=1e6+;
  16. const int inf=0x3f3f3f3f;
  17. const ll mod=1e9+;
  18. const double eps=1e-;
  19. ll powmod(ll a,ll b) {ll res=;a%=mod; assert(b>=); for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
  20. namespace linear_seq {
  21. const int N=;
  22. ll res[N],base[N],_c[N],_md[N];
  23.  
  24. vector<int> Md;
  25. void mul(ll *a,ll *b,int k) {
  26. rep(i,,k+k) _c[i]=;
  27. rep(i,,k) if (a[i]) rep(j,,k) _c[i+j]=(_c[i+j]+a[i]*b[j])%mod;
  28. for (int i=k+k-;i>=k;i--) if (_c[i])
  29. rep(j,,SZ(Md)) _c[i-k+Md[j]]=(_c[i-k+Md[j]]-_c[i]*_md[Md[j]])%mod;
  30. rep(i,,k) a[i]=_c[i];
  31. }
  32. ll solve(ll n,VI a,VI b) { // a 系数 b 初值 b[n+1]=a[0]*b[n]+...
  33. // printf("%d\n",SZ(b));
  34. ll ans=,pnt=;
  35. int k=SZ(a);
  36. assert(SZ(a)==SZ(b));
  37. rep(i,,k) _md[k--i]=-a[i];_md[k]=;
  38. Md.clear();
  39. rep(i,,k) if (_md[i]!=) Md.push_back(i);
  40. rep(i,,k) res[i]=base[i]=;
  41. res[]=;
  42. while ((1ll<<pnt)<=n) pnt++;
  43. for (int p=pnt;p>=;p--) {
  44. mul(res,res,k);
  45. if ((n>>p)&) {
  46. for (int i=k-;i>=;i--) res[i+]=res[i];res[]=;
  47. rep(j,,SZ(Md)) res[Md[j]]=(res[Md[j]]-res[k]*_md[Md[j]])%mod;
  48. }
  49. }
  50. rep(i,,k) ans=(ans+res[i]*b[i])%mod;
  51. if (ans<) ans+=mod;
  52. return ans;
  53. }
  54. VI BM(VI s) {
  55. VI C(,),B(,);
  56. int L=,m=,b=;
  57. rep(n,,SZ(s)) {
  58. ll d=;
  59. rep(i,,L+) d=(d+(ll)C[i]*s[n-i])%mod;
  60. if (d==) ++m;
  61. else if (*L<=n) {
  62. VI T=C;
  63. ll c=mod-d*powmod(b,mod-)%mod;
  64. while (SZ(C)<SZ(B)+m) C.pb();
  65. rep(i,,SZ(B)) C[i+m]=(C[i+m]+c*B[i])%mod;
  66. L=n+-L; B=T; b=d; m=;
  67. } else {
  68. ll c=mod-d*powmod(b,mod-)%mod;
  69. while (SZ(C)<SZ(B)+m) C.pb();
  70. rep(i,,SZ(B)) C[i+m]=(C[i+m]+c*B[i])%mod;
  71. ++m;
  72. }
  73. }
  74. return C;
  75. }
  76. int gao(VI a,ll n) {
  77. VI c=BM(a);
  78. c.erase(c.begin());
  79. rep(i,,SZ(c)) c[i]=(mod-c[i])%mod;
  80. return solve(n,c,VI(a.begin(),a.begin()+SZ(c)));
  81. }
  82. };
  83.  
  84. int n,k;
  85. vector<ll> a,b;
  86.  
  87. int main(){
  88. while (~scanf("%d %d",&n,&k)){
  89. a.clear();
  90. b.clear();
  91. for (int i=;i<n;i++){
  92. int num;
  93. scanf("%d",&num);
  94. b.pb(num);
  95. }
  96. for (int i=;i<n;i++){
  97. int num;
  98. scanf("%d",&num);
  99. a.pb(num);
  100. }
  101. printf("%lld\n",linear_seq::solve(k-,a,b));
  102. }
  103. return ;
  104. }

2018 江苏省邀请赛 H的更多相关文章

  1. 2018宁夏邀请赛 L Continuous Intervals(单调栈+线段树)

    2018宁夏邀请赛 L Continuous Intervals(单调栈+线段树) 传送门:https://nanti.jisuanke.com/t/41296 题意: 给一个数列A 问在数列A中有多 ...

  2. XTU 1267 - Highway - [树的直径][2017湘潭邀请赛H题(江苏省赛)]

    这道题可能有毒……总之一会儿能过一会儿不能过的,搞的我很心烦…… 依然是上次2017江苏省赛的题目,之前期末考试结束了之后有想补一下这道题,当时比较懵逼不知道怎么做……看了题解也不是很懂……就只好放弃 ...

  3. Good Bye 2018 (A~F, H)

    目录 Codeforces 1091 A.New Year and the Christmas Ornament B.New Year and the Treasure Geolocation C.N ...

  4. ACM-ICPC 2018全国邀请赛(陕西西安)

    一.火车晚点 星期五下午4.36的火车,我们3点到了长沙火车站.差不多4点了,提示,晚点1h45min,DZC马上说,不知道会不会延误郑州到西安的那趟车.过了一会,又提示,晚点2h17min,再过一会 ...

  5. 2018湘潭邀请赛 AFK题解 其他待补...

    A.HDU6276:Easy h-index Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  6. HDU 4597 Play Game 2013 ACM-ICPC吉林通化全国邀请赛H题

    九野的博客,转载请注明出处:  http://blog.csdn.net/acmmmm/article/details/10833941 题意:给定T个测试数据,下面有2副牌,每副n张,每张都有一个分 ...

  7. 2018湘潭邀请赛C题(主席树+二分)

    题目地址:https://www.icpc.camp/contests/6CP5W4knRaIRgU 比赛的时候知道这题是用主席树+二分,可是当时没有学主席树,就连有模板都不敢套,因为代码实在是太长了 ...

  8. 2017湘潭大学邀请赛H题(树的直径)

    链接:https://www.icpc.camp/contests/4mYguiUR8k0GKE H. Highway The input contains zero or more test cas ...

  9. 2018宁夏邀请赛L Continuous Intervals

    题目链接:https://nanti.jisuanke.com/t/28412 题意: 给出n个数的序列.问序列中有多少个区间满足,排序完之后任意两个相邻的数之差不大于1. 题解: 用max表示区间最 ...

随机推荐

  1. Js学习文件上传

    // 文件上传 jQuery(function() { var $ = jQuery, $list = $('#thelist'), $btn = $('#ctlBtn'), state = 'pen ...

  2. (转)SpringMVC学习(十)——SpringMVC与前台的json数据交互

    http://blog.csdn.net/yerenyuan_pku/article/details/72514022 json数据格式在接口调用中.html页面中比较常用,json格式比较简单,解析 ...

  3. android和IOS长连接区别

    http://blog.csdn.net/zhangzeyuaaa/article/details/39028369 首先我们必须知道,所有的推送功能必须有一个客户端和服务器的长连接,因为推送是由服务 ...

  4. django authentication

    django authentication django session expiry login and logout view.py from django.contrib.auth import ...

  5. ios之sqllite3简单使用

    SQLite3是嵌入在iOS中的关系型数据库,对于存储大规模的数据很有效.SQLite3使得不必将每个对象都加到内存中. 基本操作: (1)打开或者创建数据库 sqlite3 *database; i ...

  6. Ubuntu下压缩与解压各种文件的命令

    1.压缩与解压xz文件 (1)压缩 xz -z  filename (2)解压 xz -d  filename.xz 2.压缩与解压tar文件 (1)压缩 tar -cvf  filename(压缩到 ...

  7. thinkphp5实现文件上传

    原理:通过form表单的enctype = "multipart / form-data"属性将文件临时放在htdocs文件夹的tmp目录下,再通过后台的程序将文件保存在自己设定的 ...

  8. 前端基础之CSS_1

    摘要 CSS(层叠样式表)的三种设置方法 基本选择器 组合选择器 属性选择器 分组与嵌套 伪类选择器 伪元素选择器 选择器的优先级 一些样式的设置(字体.文本.背景.边框) display属性设置 0 ...

  9. Mysql索引研究总结

    闲来无事,研究了一下mysql索引,场景如下: 有一张MyISAM 类型的zt_action表,数据大约230W行,建两个索引,CREATE INDEX `read` ON zt_action(`re ...

  10. 【01】恶趣味玩转 GitHub commit 历史记录

    [黑科技]恶趣味玩转 GitHub commit 历史记录   工具:https://github.com/gelstudios/gitfiti 效果截图:预览地址:https://github.co ...