1. 程式人生 > >ARC 003 E Sequential operations on Sequenc

ARC 003 E Sequential operations on Sequenc

題目大意:開始有個字串 S , S i = i S

1 0 5 S,S_i=i,|S|\le10^5 m
1 0 5 m\le10^5
次操作每次給你一個 a i
1 0 18 a_i\le10^{18}
你要把當前的 S S 無限迴圈然後取前 a i a_i 位。問最後每個字元出現了幾次。
題解:
首先大於後一個的a沒有用,現在操作的a單調上升。
一個顯然的想法是,記ans[i]表示操作i次後的答案(暫且認為是個struct),然後顯然 a n s [ i ] = a [ i ] a [ i 1 ] a n s [ i 1 ] + s o l v e ( a [ i ] m o d    a [ i 1 ] ) ans[i]=\left\lfloor\frac{a[i]}{a[i-1]}\right\rfloor ans[i-1]+solve(a[i]\mod a[i-1]) ,然後直接做就gg了。但是注意到最後答案就是若干倍的a[1]然後是若干a[1]的字首拼起來,因此維護tms[i]表示操作i進行了幾次,每次下推即可。

#include<bits/stdc++.h>
#define gc getchar()
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define Rep(i,v) rep(i,0,(int)v.size()-1)
#define lint long long
#define db double
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define N 100010
using namespace std;
typedef pair<int,int> pii;
typedef set<int>::iterator sit;
namespace IO { const int __S=(1<<20)+5;char __buf[__S],*__H,*__T;char __obuf[__S],*__oS=__obuf,*__oT=__oS+__S-1,__c,__qu[55];int __qr;
	inline char getc() { if(__H==__T) __T=(__H=__buf)+fread(__buf,1,__S,stdin);if(__H==__T) return -1;return *__H++; }
	template <class __I>inline void inn(__I &__x) { __x=0;int __fg=1;char __c=getc();while(!isdigit(__c)&&__c!='-') __c=getc();
		if(__c=='-') __fg=-1,__c=getc();while(isdigit(__c)) __x=__x*10+__c-'0',__c=getc();__x*=__fg; }
	inline void flush(){fwrite(__obuf,1,__oS-__obuf,stdout);__oS=__obuf;}inline void putc(char __x){*__oS++ =__x;if(__oS==__oT) flush();}
	inline void el(){putc('\n');}inline void sp(){putc(' ');} template <class __I>inline void print(__I __x)
	{ if(!__x) putc('0');if(__x<0) putc('-'),__x=-__x;while(__x) __qu[++__qr]=__x%10+'0',__x/=10;while(__qr) putc(__qu[__qr--]); }
}using namespace IO;lint a[N],tms[N],cnt[N];
inline int getpos(lint x,int R) { for(int L=1,mid=(L+R)>>1;L<=R;mid=(L+R)>>1) if(a[mid]<=x) L=mid+1;else R=mid-1;return (int)R; }
inline int solve(lint r,lint k,int m)
{
	if(!r) return 0;if(r<=a[1]) return cnt[1]+=k,cnt[r+1]-=k,0;
	int p=getpos(r,m);return tms[p]+=k*(r/a[p]),solve(r%a[p],k,p-1);
}
int main()
{
	int n,m=1,t;inn(n),inn(t);
	for(lint x=a[1]=n;t;a[++m]=x,t--) for(inn(x);m&&x<=a[m];m--);
	for(lint i=m+(tms[m]=1)-1,k,r;i>1;i--)
		k=a[i]/a[i-1],r=a[i]%a[i-1],tms[i-1]+=k*tms[i],solve(r,tms[i],(int)i-1);
	rep(i,1,a[1]) print((cnt[i]+=cnt[i-1])+tms[1]),el();
	rep(i,a[1]+1,n) print(0),el();return flush(),0;
}