比赛 |
树形数据结构拔高 |
评测结果 |
AAAAAAAAAA |
题目名称 |
HS造题的七分钟 |
最终得分 |
100 |
用户昵称 |
会挽弯弓满月 |
运行时间 |
0.544 s |
代码语言 |
C++ |
内存使用 |
5.31 MiB |
提交时间 |
2025-04-17 20:59:58 |
显示代码纯文本
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+10;
ll read(){
ll x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
x=x*10+c-'0';
c=getchar();
}
return f*x;
}
ll n,m;
ll a[N];
ll opt,l,r;
ll fa[N];
ll find(ll x){
if(fa[x]==x) return x;
return fa[x]=find(fa[x]);
}
struct tree{
ll c[N];
void add(ll x,ll y){
for(;x<=n;x+=(x&-x)) c[x]+=y;
return;
}
ll ask(ll x){
ll ans=0;
for(;x;x-=(x&-x)) ans+=c[x];
return ans;
}
}t;
int main(){
freopen("hssqrt.in","r",stdin);
freopen("hssqrt.out","w",stdout);
n=read();
for(int i=1;i<=n;i++){
a[i]=read();
t.add(i,a[i]);
fa[i]=i;
}
fa[n+1]=n+1;
m=read();
for(ll i=1;i<=m;i++){
opt=read();l=read();r=read();
if(l>r) swap(l,r);
if(opt==0){
while(l<=r)
{
ll k=sqrt(a[l]);
t.add(l,k-a[l]);
a[l]=k;
if(a[l]<=1) fa[l]=fa[l+1];
if(fa[l]==l) l=l+1;
else l=find(fa[l]);
}
}
else{
ll ans;
ans=t.ask(r)-t.ask(l-1);
printf("%lld\n",ans);
}
}
return 0;
}