Portal
Main topic
$1,2...n,n$ number from small to large arrangement, there is $m$ this operation, each operation given a parameter $x$, will be when and the sequence as a cyclic section of the infinite expansion, and then take the former $x$ as a new series, the final sequence of each number of occurrences.
$n, M\leq 10^5,x\leq 10^{18}$
Exercises
Human wisdom Problem
First for two $x$ continuous operation, the last operation is meaningless, for the first operation $x<n$, to be special.
Remember the current sequence length of $len$, the new home into the operation is $x$, first calculate how many $len$ in $x$, know the final answer will be the number of $len$ represented by the series of the composition. Since the sequence left by each step is bound to appear as the prefix of the cyclic section in the new sequence, we will calculate the value of the $x\mod len$, and then recursively find the last operation so that the operation ends $len<x$, recursion can be processed until $x\leq n$, which will $1-x$ Add the final answer to the number in turn.
Consider the forward recursion from the last operation, and constantly find out how many times the shape such as $1-x$ independently appeared, the final statistical answer can be.
Because for each step of the operation, each time the location of the $len$ appears to need two points, each time $x$ due to the cause of the mold will be at least half of the original, so is to find not more than $\log x$ times, the complexity of $o (M\log m\log x+n) $.
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include < Cmath> #define LL Long long#define M 100020using namespace Std;const int Bs=1<<19;char Bf[bs],ot[bs],*sz=ot,*hd, *tl;const Char *ed=ot+bs-1; Char ss[20]; int Top;char Getchar () {if (HD==TL) tl= (HD=BF) +fread (Bf,1,bs,stdin); return *hd++;} void Flush () {fwrite (ot,1,sz-ot,stdout);} void Putchar (char c) {*sz++ =c;if (sz==ed) flush (), sz=ot;} void write (LL x) {if (!x) {Putchar (x), Putchar (' \ n ');} while (x) ss[++top]= (x%10+ ' 0 '), X/=10;while (Top) Putchar (Ss[top]), top--; Putchar (' \ n ');} ll read () {ll nm=0,fh=1; char Cw=getchar (); for (;! IsDigit (CW); Cw=getchar ()) if (cw== '-') fh=-fh;for (; IsDigit (CW); Cw=getchar ()) nm=nm*10+ (cw-' 0 '); return NM*FH;} ll N,t,m,p[m],n,g[m],f[m],k[m],tmp;int Main () {N=read (), T=read (); while (t--) {LL-x=read (); while (m&&p[m]>= x) m--; P[++m]=x;} if (m&&p[1]<n) {n=n,n=p[1];for (LL i=1;i<m;i++) p[i]=p[i+1];m--;} G[0]=p[0]=n,f[m]=1;for (ll i=m;i>=0;i--) {ll res=p[i],noW=i-1;while (res>n) {LL K=res/p[now]; F[now]+=f[i]*k,res-=k*p[now];now=upper_bound (P,p+now,res)-p-1;} G[i]=res,k[1]+=f[i],k[g[i]+1]-=f[i];} For (LL-i=1;i<=n;i++) K[i]+=k[i-1],write (K[i]), while (n<n) N++,putchar (' 0 '), Putchar (' \ n '); Flush (); return 0;}
Agc003_e sequential operations on Sequence