AT_abc466_f 题解
可恶,来晚了,d 和 e 的 tj 都没得写了。
只好写 f 的了。
但是为什么 c 的能写,难猜难猜。
首先发现
然后我们考虑贡献的过程。为了方便,将
首先最基本的,对于每个
那么,我们就可以模拟这个过程了。具体来讲,你维护一个当前遍历到的位置
唉怎么这么一长串,跟绕口令似的,代码倒是很简单。哦以及最后记得要
::::success[code && submission]
#include<bits/stdc++.h>
#define LL long long
#define UInt unsigned int
#define ULL unsigned long long
#define LD long double
#define pii pair<int,int>
#define pLL pair<LL,LL>
#define pDD pair<LD,LD>
#define fr first
#define se second
#define pb push_back
#define isr insert
#define _i128 __int128
using namespace std;
const int N = 2e5+5;
LL T,n,m,p[N],a[N],f[N];
bool vis[N];
LL read(){
LL su=0,pp=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')pp=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){su=su*10+ch-'0';ch=getchar();}
return su*pp;
}
LL sol(LL x,LL yu){
if(x<=0)return 1;
LL tmp=yu%a[x-1],res=0;
if(!vis[x])f[x]=sol(x-1,a[x-1]),vis[x]=1;
res=yu/a[x-1]*f[x];
if(tmp){
int id=lower_bound(a,a+x,tmp)-a;
res+=sol(id,tmp);
}
//cout<<x<<","<<yu<<","<<tmp<<":"<<res<<"\n";
return res;
}
int main(){
T=read();
while(T--){
n=read(),m=read()+1;
p[0]=m;
for(int i=1;i<=n;i++){
p[i]=read();
if(p[i]>=p[i-1])i--,n--;
}
for(int i=n;i>=0;i--)
a[i]=p[n-i],vis[i]=0;
cout<<sol(n,m)-1<<"\n";
}
return 0;
}
::::
如果本篇题解对你有帮助的话,麻烦你点一个小小的赞,真是太感谢啦!
以及,昨天是天依宝宝的生日,祝她十四周年快乐喵!!