ARC 003 E Sequential operations on Sequenc
阿新 • • 發佈:2018-11-11
題目大意:開始有個字串
,
次操作每次給你一個
你要把當前的
無限迴圈然後取前
位。問最後每個字元出現了幾次。
題解:
首先大於後一個的a沒有用,現在操作的a單調上升。
一個顯然的想法是,記ans[i]表示操作i次後的答案(暫且認為是個struct),然後顯然
,然後直接做就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;
}