AT2005 [AGC003E] Sequential operations on Sequence
洛谷传送门 AT传送门
Solution
这种题对我来说——思维难度太高了吧(;´д`)ゞ
首先我们要处理一下
发现当
我 们 往 下 走。
转化一下:对于第
那么可以看作
既然
我们选择二分找到一个
优化:我们不能每次都
时间复杂度是
Code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+10;
int n,Q,tot;
ll q[N],num[N],c[N];
void solve(ll d,ll w){
int j=lower_bound(q+1,q+tot+1,d)-q-1;
if(!j) c[1]+=w,c[d+1]-=w;
else num[j]+=d/q[j]*w,solve(d%q[j],w);
}
int main(){
scanf("%d%d",&n,&Q);
q[++tot]=n;
while(Q--){
ll a; scanf("%lld",&a);
while(tot&&q[tot]>=a) tot--;
q[++tot]=a;
}
num[tot]=1;
for(int i=tot;i>=2;i--) num[i-1]+=q[i]/q[i-1]*num[i],solve(q[i]%q[i-1],num[i]);
c[1]+=num[1]; c[q[1]+1]-=num[1];
for(int i=1;i<=n;i++) printf("%lld\n",c[i]+=c[i-1]);
return 0;
}