题意:
In a galaxy far, far away, there are two integer sequence a and b of length n.
b is a static permutation of 1 to n. Initially a is filled with zeroes.
There are two kind of operations:
1. add l r: add one for al,al+1...ar
2. query l r: query ∑ri=l⌊ai/bi⌋
代码:
#include <cstdio>
#include<iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#define mid ((l+r)/2)
#define ls (o<<1)
#define rs ((o<<1)+1)
using namespace std;
typedef long long int ll;
const int maxn = 100000;
const ll mod=1000000007;
int n,m,a[maxn+5];
int val[maxn*4+5],add[maxn*4+5],sum[maxn*4+5];
void pushup(int o)
{
val[o] = min(val[ls],val[rs]);
sum[o] = sum[ls]+sum[rs];
}
void pushdown(int o)
{
if(add[o]!=0)
{
val[ls]+=add[o];
val[rs]+=add[o];
add[ls]+=add[o];
add[rs]+=add[o];
add[o]=0;
}
pushup(o);
}
void build(int o,int l,int r)
{
add[o] = sum[o] = 0;
if(l==r)
{
val[o] = a[l];
return;
}
build(ls,l,mid);
build(rs,mid+1,r);
pushup(o);
}
void updata(int o,int l,int r,int L,int R)
{
if(R<l||r<L) return;
if(L<=l&&r<=R)
{
if(val[o]>1)
{
val[o]--, add[o]--;
}
else
{
if(l==r)
{
val[o]=a[l],add[o]=0,sum[o]++;
return;
}
else
{
pushdown(o);
updata(ls,l,mid,L,R);
updata(rs,mid+1,r,L,R);
pushup(o);
}
}
}
else
{
pushdown(o);
if(L<=mid) updata(ls,l,mid,L,R);
if(mid<R) updata(rs,mid+1,r,L,R);
pushup(o);
}
}
int query(int o,int l,int r,int L,int R)
{
if(R<l||r<L) return 0;
if(L<=l&&r<=R) return sum[o];
int Sum = 0;
if(L<=mid) Sum+=query(ls,l,mid,L,R);
if(mid<R) Sum+=query(rs,mid+1,r,L,R);
return Sum;
}
int main()
{
while(~scanf("%d %d",&n,&m))
{
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
build(1,1,n);
while(m--)
{
char opt[10];
int L,R;
scanf("%s %d %d",opt,&L,&R);
if(opt[0]=='a') updata(1,1,n,L,R);
else printf("%d\n",query(1,1,n,L,R));
}
}
return 0;
}