求调 0msTLE #1
查看原帖
求调 0msTLE #1
1263684
Elysialr楼主2024/11/22 21:13
#include<bits/stdc++.h>
using namespace std;
#define x_lc (x<<1)
#define x_rc (x<<1|1)
#define x_mid ((t[x].l+t[x].r)>>1)
#define ll long long

struct SegmentTree{
    ll l,r;
    ll data;
    ll leng(){
        return r-l+1;
    }
};

ll a[1000001];
SegmentTree t[4000001];

void build(ll x,ll l,ll r){
    t[x].l=l;
    t[x].r=r;
    if(l==r){
        t[x].data=a[l];
        return;
    }
    build(x_lc,l,x_mid);
    build(x_rc,x_mid+1,r);
    t[x].data=t[x_lc].data+t[x_rc].data;
}
ll finds(ll x,ll l,ll r){
    if(t[x].l>=l&&t[x].r<=r) return t[x].data;
    ll res=0;
    if(x_mid>=l) res+=finds(x_lc,l,r);
    if(x_mid+1<=r) res+=finds(x_rc,l,r);
    return res;
}
void change(ll x,ll l,ll r){
    if(t[x].l==t[x].r){
        t[x].data=sqrt(t[x].data);
        return;
    }
    if(t[x].data==t[x].leng()) return;
    if(x_mid>=l) change(x_lc,l,r);
    if(x_mid+1<=r) change(x_rc,l,r);
    t[x].data=t[x_lc].data+t[x_rc].data;
}
int main(){
    ll n,m;
    for(ll T=1;scanf("%lld",&n)!=EOF;T++){
        cout<<"Case #"<<T<<":\n";
        for(ll i=1;i<=n;i++) 
        cin>>a[i];
        cin>>m;
        build(1,1,n);
        for(ll i=1;i<=m;i++){
            ll k,l,r;
            cin>>k>>l>>r;
            if(k==0) change(1,min(l,r),max(l,r));
            else cout<<finds(1,min(l,r),max(l,r))<<endl;
        }
        cout<<endl;
    }
    return 0;
}
2024/11/22 21:13
加载中...