In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation
DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of n integers: a1, a2, ..., an. Moreover, there are mqueries, each query has one of the two types:
- Format of the query "1 l r". In reply to the query, you need to add Fi - l + 1 to each element ai, where l ≤ i ≤ r.
-
Format of the query "2 l r". In reply to the query you should output the value of
modulo 1000000009 (109 + 9).
Help DZY reply to all the queries.
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 300000). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — initial array a.
Then, m lines follow. A single line describes a single query in the format given in the statement. It is guaranteed that for each query inequality 1 ≤ l ≤ r ≤ n holds.
For each query of the second type, print the value of the sum on a single line.
4 4 1 2 3 4 1 1 4 2 1 4 1 2 4 2 1 3
17 12
#include
#include
#include
#include
using namespace std;
#define lson l,m,o<<1
#define rson m+1,r,o<<1|1
#define maxn 300010
#define mod 1000000009
typedef long long ll;
ll a[maxn<<2];
ll b[maxn<<2];
ll sum[maxn<<2];
ll fibo[maxn];
ll sfibo[maxn];
int n,m;
ll addit(ll a,ll x)
{
a+=x;
if(a>=mod)a-=mod;
return a;
}
void pushup(int o)
{
sum[o]=addit(sum[o<<1],sum[o<<1|1]);
}
void build(int l,int r,int o)
{
a[o]=b[o]=0;
if(l==r){
cin>>sum[o];
return;
}
int m=l+r>>1;
build(lson);
build(rson);
pushup(o);
}
ll chul(ll a,ll b,int n)
{
if(n==1)return a;
if(n==2)return b;
return addit( fibo[n-2] * a % mod , fibo[n-1] * b % mod );
}
ll chuli(ll a,ll b,int n)
{
if(n==1)return a;
if(n==2)return addit(a,b);
return addit( addit(sfibo[n-2],1) * a % mod , sfibo[n-1] * b % mod );
}
void pushdown(int o,int n)
{
if(a[o])
{
int LL=n/2+n%2;
int rr=n-LL;
a[o<<1]=addit(a[o<<1],a[o]);
b[o<<1]=addit(b[o<<1],b[o]);
sum[o<<1]=addit( sum[o<<1] , chuli(a[o],b[o],LL) );
ll x=chul(a[o],b[o],LL+1);
ll y=chul(a[o],b[o],LL+2);
a[o<<1|1]=addit(a[o<<1|1],x);
b[o<<1|1]=addit(b[o<<1|1],y);
sum[o<<1|1]=addit( sum[o<<1|1] , chuli(x,y,rr) );
a[o]=b[o]=0;
}
}
void update(int l,int r,int o,int L,int R)
{
if(L<=l&&r<=R){
ll aa=chul(1,1,l-L+1);
ll bb=chul(1,1,l-L+2);
a[o]=addit(a[o],aa);
b[o]=addit(b[o],bb);
sum[o]=addit(sum[o], chuli(aa,bb,r-l+1) );
return;
}
pushdown(o,r-l+1);
int m=l+r>>1;
if(L<=m)update(lson,L,R);
if(m>1;
ll ans=0;
pushdown(o,r-l+1);
if(L<=m)ans=addit(ans,query(lson,L,R));
if(m