2018 江苏省邀请赛 H
题目链接 https://nanti.jisuanke.com/t/28872
解析 递推 直接套杜教板子
AC代码
- #include <cstdio>
- #include <cstring>
- #include <cmath>
- #include <algorithm>
- #include <vector>
- #include <string>
- #include <map>
- #include <set>
- #include <iostream>
- #include <cassert>
- using namespace std;
- #define rep(i,a,n) for (int i=a;i<n;i++)
- #define per(i,a,n) for (int i=n-1;i>=a;i--)
- #define pb push_back
- #define mp make_pair
- #define all(x) (x).begin(),(x).end()
- #define fi first
- #define se second
- #define SZ(x) ((int)(x).size())
- typedef vector<int> VI;
- typedef long long ll;
- typedef pair<int,int> PII;
- const int maxn=1e6+;
- const ll mod=;
- 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;}
- // head
- int _,n,k;
- int a[maxn],c[maxn];
- namespace linear_seq {
- const int N=;
- ll res[N],base[N],_c[N],_md[N];
- vector<int> Md;
- void mul(ll *a,ll *b,int k) {
- rep(i,,k+k) _c[i]=;
- rep(i,,k) if (a[i]) rep(j,,k) _c[i+j]=(_c[i+j]+a[i]*b[j])%mod;
- for (int i=k+k-;i>=k;i--) if (_c[i])
- rep(j,,SZ(Md)) _c[i-k+Md[j]]=(_c[i-k+Md[j]]-_c[i]*_md[Md[j]])%mod;
- rep(i,,k) a[i]=_c[i];
- }
- int solve(ll n,VI a,VI b) { // a 系数 b 初值 b[n+1]=a[0]*b[n]+...
- // printf("%d\n",SZ(b));
- ll ans=,pnt=;
- int k=SZ(a);
- assert(SZ(a)==SZ(b));
- rep(i,,k) _md[k--i]=-a[i];_md[k]=;
- Md.clear();
- rep(i,,k) if (_md[i]!=) Md.push_back(i);
- rep(i,,k) res[i]=base[i]=;
- res[]=;
- while ((1ll<<pnt)<=n) pnt++;
- for (int p=pnt;p>=;p--) {
- mul(res,res,k);
- if ((n>>p)&) {
- for (int i=k-;i>=;i--) res[i+]=res[i];res[]=;
- rep(j,,SZ(Md)) res[Md[j]]=(res[Md[j]]-res[k]*_md[Md[j]])%mod;
- }
- }
- rep(i,,k) ans=(ans+res[i]*b[i])%mod;
- if (ans<) ans+=mod;
- return ans;
- }
- VI BM(VI s) {
- VI C(,),B(,);
- int L=,m=,b=;
- rep(n,,SZ(s)) {
- ll d=;
- rep(i,,L+) d=(d+(ll)C[i]*s[n-i])%mod;
- if (d==) ++m;
- else if (*L<=n) {
- VI T=C;
- ll c=mod-d*powmod(b,mod-)%mod;
- while (SZ(C)<SZ(B)+m) C.pb();
- rep(i,,SZ(B)) C[i+m]=(C[i+m]+c*B[i])%mod;
- L=n+-L; B=T; b=d; m=;
- } else {
- ll c=mod-d*powmod(b,mod-)%mod;
- while (SZ(C)<SZ(B)+m) C.pb();
- rep(i,,SZ(B)) C[i+m]=(C[i+m]+c*B[i])%mod;
- ++m;
- }
- }
- return C;
- }
- int gao(VI a,ll n) {
- VI c=BM(a);
- c.erase(c.begin());
- rep(i,,SZ(c)) c[i]=(mod-c[i])%mod;
- return solve(n,c,VI(a.begin(),a.begin()+SZ(c)));
- }
- };
- int main() {
- while(scanf("%d%d",&n,&k)==)
- {
- for(int i=;i<=n;i++)scanf("%d",&a[i]);
- for(int i=;i<=n;i++)scanf("%d",&c[i]);
- for(int i=n+;i<=n*;i++)
- {
- a[i]=;
- for(int j=;j<=n;j++)
- a[i]=(a[i]+1ll*a[i-j]*c[j]%mod)%mod;
- }
- VI g;g.clear();
- for(int i=;i<=*n;i++)g.pb(a[i]);
- cout<<linear_seq::gao(g,k-)<<endl;
- }
- }
................................................................................................................................................................
- #include <bits/stdc++.h>
- #define fir first
- #define se second
- #define pb push_back
- #define ll long long
- #define mp make_pair
- #define rep(i,a,n) for (int i=a;i<n;i++)
- #define per(i,a,n) for (int i=n-1;i>=a;i--)
- #define all(x) (x).begin(),(x).end()
- #define SZ(x) ((int)(x).size())
- using namespace std;
- typedef vector<ll> VI;
- typedef pair<int,int> PII;
- const int maxn=1e5+;
- const int maxm=1e6+;
- const int inf=0x3f3f3f3f;
- const ll mod=1e9+;
- const double eps=1e-;
- 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;}
- namespace linear_seq {
- const int N=;
- ll res[N],base[N],_c[N],_md[N];
- vector<int> Md;
- void mul(ll *a,ll *b,int k) {
- rep(i,,k+k) _c[i]=;
- rep(i,,k) if (a[i]) rep(j,,k) _c[i+j]=(_c[i+j]+a[i]*b[j])%mod;
- for (int i=k+k-;i>=k;i--) if (_c[i])
- rep(j,,SZ(Md)) _c[i-k+Md[j]]=(_c[i-k+Md[j]]-_c[i]*_md[Md[j]])%mod;
- rep(i,,k) a[i]=_c[i];
- }
- ll solve(ll n,VI a,VI b) { // a 系数 b 初值 b[n+1]=a[0]*b[n]+...
- // printf("%d\n",SZ(b));
- ll ans=,pnt=;
- int k=SZ(a);
- assert(SZ(a)==SZ(b));
- rep(i,,k) _md[k--i]=-a[i];_md[k]=;
- Md.clear();
- rep(i,,k) if (_md[i]!=) Md.push_back(i);
- rep(i,,k) res[i]=base[i]=;
- res[]=;
- while ((1ll<<pnt)<=n) pnt++;
- for (int p=pnt;p>=;p--) {
- mul(res,res,k);
- if ((n>>p)&) {
- for (int i=k-;i>=;i--) res[i+]=res[i];res[]=;
- rep(j,,SZ(Md)) res[Md[j]]=(res[Md[j]]-res[k]*_md[Md[j]])%mod;
- }
- }
- rep(i,,k) ans=(ans+res[i]*b[i])%mod;
- if (ans<) ans+=mod;
- return ans;
- }
- VI BM(VI s) {
- VI C(,),B(,);
- int L=,m=,b=;
- rep(n,,SZ(s)) {
- ll d=;
- rep(i,,L+) d=(d+(ll)C[i]*s[n-i])%mod;
- if (d==) ++m;
- else if (*L<=n) {
- VI T=C;
- ll c=mod-d*powmod(b,mod-)%mod;
- while (SZ(C)<SZ(B)+m) C.pb();
- rep(i,,SZ(B)) C[i+m]=(C[i+m]+c*B[i])%mod;
- L=n+-L; B=T; b=d; m=;
- } else {
- ll c=mod-d*powmod(b,mod-)%mod;
- while (SZ(C)<SZ(B)+m) C.pb();
- rep(i,,SZ(B)) C[i+m]=(C[i+m]+c*B[i])%mod;
- ++m;
- }
- }
- return C;
- }
- int gao(VI a,ll n) {
- VI c=BM(a);
- c.erase(c.begin());
- rep(i,,SZ(c)) c[i]=(mod-c[i])%mod;
- return solve(n,c,VI(a.begin(),a.begin()+SZ(c)));
- }
- };
- int n,k;
- vector<ll> a,b;
- int main(){
- while (~scanf("%d %d",&n,&k)){
- a.clear();
- b.clear();
- for (int i=;i<n;i++){
- int num;
- scanf("%d",&num);
- b.pb(num);
- }
- for (int i=;i<n;i++){
- int num;
- scanf("%d",&num);
- a.pb(num);
- }
- printf("%lld\n",linear_seq::solve(k-,a,b));
- }
- return ;
- }
2018 江苏省邀请赛 H的更多相关文章
- 2018宁夏邀请赛 L Continuous Intervals(单调栈+线段树)
2018宁夏邀请赛 L Continuous Intervals(单调栈+线段树) 传送门:https://nanti.jisuanke.com/t/41296 题意: 给一个数列A 问在数列A中有多 ...
- XTU 1267 - Highway - [树的直径][2017湘潭邀请赛H题(江苏省赛)]
这道题可能有毒……总之一会儿能过一会儿不能过的,搞的我很心烦…… 依然是上次2017江苏省赛的题目,之前期末考试结束了之后有想补一下这道题,当时比较懵逼不知道怎么做……看了题解也不是很懂……就只好放弃 ...
- Good Bye 2018 (A~F, H)
目录 Codeforces 1091 A.New Year and the Christmas Ornament B.New Year and the Treasure Geolocation C.N ...
- ACM-ICPC 2018全国邀请赛(陕西西安)
一.火车晚点 星期五下午4.36的火车,我们3点到了长沙火车站.差不多4点了,提示,晚点1h45min,DZC马上说,不知道会不会延误郑州到西安的那趟车.过了一会,又提示,晚点2h17min,再过一会 ...
- 2018湘潭邀请赛 AFK题解 其他待补...
A.HDU6276:Easy h-index Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- HDU 4597 Play Game 2013 ACM-ICPC吉林通化全国邀请赛H题
九野的博客,转载请注明出处: http://blog.csdn.net/acmmmm/article/details/10833941 题意:给定T个测试数据,下面有2副牌,每副n张,每张都有一个分 ...
- 2018湘潭邀请赛C题(主席树+二分)
题目地址:https://www.icpc.camp/contests/6CP5W4knRaIRgU 比赛的时候知道这题是用主席树+二分,可是当时没有学主席树,就连有模板都不敢套,因为代码实在是太长了 ...
- 2017湘潭大学邀请赛H题(树的直径)
链接:https://www.icpc.camp/contests/4mYguiUR8k0GKE H. Highway The input contains zero or more test cas ...
- 2018宁夏邀请赛L Continuous Intervals
题目链接:https://nanti.jisuanke.com/t/28412 题意: 给出n个数的序列.问序列中有多少个区间满足,排序完之后任意两个相邻的数之差不大于1. 题解: 用max表示区间最 ...
随机推荐
- Js学习文件上传
// 文件上传 jQuery(function() { var $ = jQuery, $list = $('#thelist'), $btn = $('#ctlBtn'), state = 'pen ...
- (转)SpringMVC学习(十)——SpringMVC与前台的json数据交互
http://blog.csdn.net/yerenyuan_pku/article/details/72514022 json数据格式在接口调用中.html页面中比较常用,json格式比较简单,解析 ...
- android和IOS长连接区别
http://blog.csdn.net/zhangzeyuaaa/article/details/39028369 首先我们必须知道,所有的推送功能必须有一个客户端和服务器的长连接,因为推送是由服务 ...
- django authentication
django authentication django session expiry login and logout view.py from django.contrib.auth import ...
- ios之sqllite3简单使用
SQLite3是嵌入在iOS中的关系型数据库,对于存储大规模的数据很有效.SQLite3使得不必将每个对象都加到内存中. 基本操作: (1)打开或者创建数据库 sqlite3 *database; i ...
- Ubuntu下压缩与解压各种文件的命令
1.压缩与解压xz文件 (1)压缩 xz -z filename (2)解压 xz -d filename.xz 2.压缩与解压tar文件 (1)压缩 tar -cvf filename(压缩到 ...
- thinkphp5实现文件上传
原理:通过form表单的enctype = "multipart / form-data"属性将文件临时放在htdocs文件夹的tmp目录下,再通过后台的程序将文件保存在自己设定的 ...
- 前端基础之CSS_1
摘要 CSS(层叠样式表)的三种设置方法 基本选择器 组合选择器 属性选择器 分组与嵌套 伪类选择器 伪元素选择器 选择器的优先级 一些样式的设置(字体.文本.背景.边框) display属性设置 0 ...
- Mysql索引研究总结
闲来无事,研究了一下mysql索引,场景如下: 有一张MyISAM 类型的zt_action表,数据大约230W行,建两个索引,CREATE INDEX `read` ON zt_action(`re ...
- 【01】恶趣味玩转 GitHub commit 历史记录
[黑科技]恶趣味玩转 GitHub commit 历史记录 工具:https://github.com/gelstudios/gitfiti 效果截图:预览地址:https://github.co ...