蒟蒻求调
查看原帖
蒟蒻求调
553673
ygkl9698楼主2022/8/11 13:23
#include<iostream>
#include<cstdio>
#include<cmath>
#define LL long long 
#define MAXN 100005
using namespace std;
LL n,a[MAXN*4],s[MAXN*4],add[MAXN*4];
void up(int p){
	s[p]=s[p*2]+s[p*2+1];
	a[p]=a[p*2]&&a[p*2+1];
}
void build(int p,int l,int r){
	if(l==r){
		scanf("%d",&s[p]);
		if(s[p]==0||s[p]==1) a[p]=1;
		return ;
	}
	int m=(l+r)/2;
	build(p*2,l,m);
	build(p*2+1,m+1,r);
	up(p);
}
void update(int p,int l,int r,int x,int y){
	if(a[p]) return ;
	if(y<l||x>r){
		return ;
	}
	if(l==r){
		s[p]=sqrt(s[p]);
		if(s[p]==1||s[p]==0){
			a[p]=1;
		}
		return ;
	}
	int m=(l+r)/2;
	update(p*2,l,m,x,y);
	update(p*2+1,m+1,r,x,y);
	up(p);
}
LL query_sum(int p,int l,int r,int x,int y){
	if(x>r||y<l) return 0;
	if(x<=l&&r<=y) return s[p];
	int m=(l+r)/2;
	LL ret=0;
	ret+=query_sum(p*2,l,m,x,y);
	ret+=query_sum(p*2+1,m+1,r,x,y);
	return ret;
}
int main(){
	cin>>n;
	build(1,1,n);
	int q;
	cin>>q;
	while(q--){
		int ch,x,v,y;
		cin>>ch;
		if(ch==0){
			cin>>x>>y;
			if(x>y)
				swap(x,y);
			update(1,1,n,x,y);
		}
		if(ch==1){
			cin>>x>>y;
			if(x>y)
				swap(x,y);
			cout<<query_sum(1,1,n,x,y)<<endl;
		}
	}
	return 0;
} 

50pts,后五个点全WA

2022/8/11 13:23
加载中...