# Luogu P5309 [Ynoi2012]D1T1

### 总体分析

CODE

#include<cstdio>
#include<cctype>
#include<cmath>
#define RI register int
#define CI const int&
#define Tp template <typename T>
using namespace std;
const int N=200005,mod=1e9+7,S=40;
int n,m,a[N],opt,x,y,z,size;
class FileInputOutput
{
private:
static const int S=1<<21;
#define pc(ch) (Ftop<S?Fout[Ftop++]=ch:(fwrite(Fout,1,S,stdout),Fout[(Ftop=0)++]=ch))
char Fin[S],Fout[S],*A,*B; int Ftop,pt[15];
public:
{
x=0; char ch; while (!isdigit(ch=tc()));
while (x=(x<<3)+(x<<1)+(ch&15),isdigit(ch=tc()));
}
Tp inline void write(T x)
{
if (!x) return (void)(pc('0'),pc('\n')); RI ptop=0;
while (x) pt[++ptop]=x%10,x/=10; while (ptop) pc(pt[ptop--]+48); pc('\n');
}
inline void Fend(void)
{
fwrite(Fout,1,Ftop,stdout);
}
#undef tc
#undef pc
}F;
inline void inc(int& x,CI y)
{
if ((x+=y)>=mod) x-=mod;
}
inline int sum(CI a,CI b)
{
int t=a+b; return t>=mod?t-mod:t;
}
inline int sub(CI a,CI b)
{
int t=a-b; return t<0?t+mod:t;
}
namespace Case1 //Solver for z>sqrt(n)
{
const int BLO=450; int sum[BLO],blk[N];
inline void init(void)
{
for (RI i=1;i<=n;++i) inc(sum[blk[i]=(i-1)/size+1],a[i]);
}
inline void modify(CI x,CI y,CI z)
{
for (RI i=y;i<=n;i+=x) inc(a[i],z),inc(sum[blk[i]],z);
}
inline int BF(CI x,CI y,int ret=0)
{
for (RI i=x;i<=y;++i) inc(ret,a[i]); return ret;
}
inline int query(CI x,CI y,int ret=0)
{
if (blk[x]==blk[y]) return BF(x,y);
inc(ret,BF(x,blk[x]*size)); inc(ret,BF((blk[y]-1)*size+1,y));
for (RI i=blk[x]+1;i<blk[y];++i) inc(ret,sum[i]); return ret;
}
};
namespace Case2 //Solver for z<=sqrt(n)
{
int mv[S+5][S+5],sum[S+5],stack[N],top; bool vis[S+5];
inline void modify(CI x,CI y,CI z)
{
if (!vis[x]) vis[x]=1,stack[++top]=x;
for (RI i=y%x;i<x;++i) inc(mv[x][i],z); inc(sum[x],z);
}
inline int query(CI x,CI y,int ret=0)
{
for (RI i=1;i<=top;++i)
{
int p=stack[i],t=(y-x+1)/p; inc(ret,1LL*t*sum[p]%mod);
int l=x+t*p,r=y; if (l>r) continue; l%=p; r%=p;
if (l<=r) inc(ret,sub(mv[p][r],l?mv[p][l-1]:0)); else
inc(ret,mv[p][r]),inc(ret,sub(sum[p],l?mv[p][l-1]:0));
}
return ret;
}
};
int main()
{
//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
}