BZOJ 3211 花神游历各国 ( 线段树区间开根号

题意:

两个操作

1 区间开根号
2 区间求和

题解:

考虑到取模的性质,一个数 顶多被操作不超过1010次就会变成11 标记一下 即可 保证复杂度为O(nlogn)

#include <bits/stdc++.h>

using namespace std;

#define ll long long 
#define pb push_back
#define ls o<<1
#define rs o<<1|1
#define fi first
#define se second
#define CLR(a, b) memset(a, (b), sizeof(a))
const ll INF = 0x3f3f3f3f;
const ll mod = 1e9+7;
const ll MAXN = 2e5+10;

void F() {
    //ios::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
}
ll arr[MAXN];
struct node {
    ll l,r;
    ll x; bool v;
}t[MAXN<<2];
inline void push_up(ll o) {
    t[o].x=t[ls].x+t[rs].x;
    t[o].v=t[ls].v&t[rs].v;
}
inline void build(ll l,ll r, ll o) {
    t[o].l=l,t[o].r=r,t[o].v=false;
    if(l==r) {
        t[o].x=arr[l]; return;
    }
    ll mid = (l+r)>>1;
    build(l,mid,ls); build(mid+1,r,rs);
    push_up(o);
}
inline void update(ll l,ll r,ll o) {
    if(t[o].v) return;
    if(t[o].l==t[o].r){
        t[o].x = (ll)floor(sqrt(t[o].x));
        if(t[o].x<=1) t[o].v=true;
        return;
    }
    ll mid = (t[o].l+t[o].r)>>1;
    if(r<=mid) update(l,r,ls);
    else if(l>mid) update(l,r,rs);
    else {
        update(l,mid,ls);update(mid+1,r,rs);
    }
    push_up(o);
}
inline ll query(ll l,ll r,ll o) {
    if(t[o].l>=l&&t[o].r<=r) return t[o].x;
    ll ans = 0;
    ll mid=(t[o].l+t[o].r)>>1;
    if(r<=mid) ans+=query(l,r,ls);
    else if(l>mid) ans+=query(l,r,rs);
    else {
        ans+=query(l,mid,ls); ans+=query(mid+1,r,rs);
    }
    return ans;
}
int main() {
    F();
    ll n, m;
    scanf("%lld",&n);
    for(ll i=1;i<=n;++i){
        scanf("%lld",&arr[i]);
    }
    build(1,n,1);
    scanf("%lld",&m);
    while(m--){
        ll op,l,r;
        scanf("%lld%lld%lld",&op,&l,&r);
        if(op==1) printf("%lld\n",query(l,r,1));
        else update(l,r,1);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值