标签:pre include flag return c++ mod als sync scanf
一个数最多能取8-9次根号。
#include <bits/stdc++.h>
using namespace std;
#define debug printf("bug!!!\n");
typedef long long ll;
const int MAXN=1e5+10;
const ll MOD=1e9+7;
ll tree[MAXN*4];
ll lazy[MAXN*4];
ll a[MAXN];
//9-10次
void build(int p,int l,int r){
if(l==r){
tree[p]=a[l];
return;
}
int mid=(l+r)>>1;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
tree[p]=tree[p<<1]+tree[p<<1|1];
}
void update(int p,int l,int r,int L,int R){
if(tree[p]<=r-l+1)return;
if(l==r){
tree[p]=sqrt(tree[p]);
return ;
}
int mid=(l+r)>>1;
if(L<=mid)update(p<<1,l,mid,L,R);
if(R>mid)update(p<<1|1,mid+1,r,L,R);
tree[p]=tree[p<<1]+tree[p<<1|1];
}
ll query(int p,int l,int r,int L,int R){
if(L<=l && r<=R)return tree[p];
int mid=(l+r)>>1;
ll res=0;
if(L<=mid)res+=query(p<<1,l,mid,L,R);
if(R>mid)res+=query(p<<1|1,mid+1,r,L,R);
return res;
}
int main(){
//ios::sync_with_stdio(false);
int n;
int flag=0;
while(~scanf("%d",&n)){
printf("Case #%d:\n",++flag);
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
build(1,1,n);
int m;
scanf("%d",&m);
while(m--){
int op,a,b;
scanf("%d%d%d",&op,&a,&b);
if(a>b)swap(a,b);
if(op==0){
update(1,1,n,a,b);
}
else{
printf("%lld\n",query(1,1,n,a,b));
}
}
printf("\n");
}
return 0;
}
标签:pre include flag return c++ mod als sync scanf
原文地址:https://www.cnblogs.com/qq103013999/p/13320753.html