求救大佬,先是RE然后就是TLE,改了13次还不行
查看原帖
求救大佬,先是RE然后就是TLE,改了13次还不行
927800
baijunkai楼主2023/8/6 13:26
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
struct node{
	int l,r;
	long long sum,max;
}t[N<<2];
long long n,m;
long long a[N];
inline void pushup(int p)
{
	t[p].sum=t[p<<1].sum+t[p<<1|1].sum;
	t[p].max=max(t[p<<1].max,t[p<<1|1].max);
}
inline void build(int p,int l,int r)
{
	t[p].l=l,t[p].r=r;
	if(l==r)
	{
		t[p].sum=t[p].max=a[l];
		return;
	}
	int mid=l+r>>1;
	build(p<<1,l,mid);
	build(p<<1|1,mid+1,r);
	pushup(p);
}
inline void change(int p,int L,int R)
{
	if(t[p].max<=1)return;
	if(L<=t[p].l&&t[p].r<=R&&t[p].r-t[p].l+1==t[p].sum)return;
	if(t[p].l==t[p].r)
	{
		t[p].sum=sqrtl((long double)t[p].sum);
		t[p].max=t[p].sum;
		return;
	}
	int mid=t[p].l+t[p].r>>1;
	if(L<=mid)change(p<<1,L,R);
	if(mid<R)change(p<<1|1,L,R);
	pushup(p);
}
inline long long query(int p,int L,int R)
{
	if(L<=t[p].l&&t[p].r<=R)return t[p].sum;
	long long ret=0;
	int mid=t[p].l+t[p].r>>1;
	if(L<=mid)ret+=query(p<<1,L,R);
	if(mid<R)ret+=query(p<<1|1,L,R);
	return ret;
}
int main()
{
	ios::sync_with_stdio(0);
	int num=0;
	while(scanf("%d",&n)!=EOF)
	{
		num++;
		printf("Case #%d:",num);
		memset(a,0,sizeof(a));
//		memset(t,0,sizeof(t));
		for(int i=1;i<=n;i++)scanf("%d",&a[i]);
		scanf("%d",&m);
		build(1,1,n);
		while(m--)
		{
			int op,x,y;
			cin>>op>>x>>y;
			if(x>y)swap(x,y);
			if(op==0)change(1,x,y);
			else if(op==1)printf("%d\n",query(1,x,y));
		}
		printf("\n");
	}
	return 0;
}
2023/8/6 13:26
加载中...