求调RE QAQ
查看原帖
求调RE QAQ
1067741
Andyxz楼主2024/11/23 12:33

样例自己测的没问题啊

#include<iostream>
#include<cstdio>
#include<cmath>
#include<bits/stdc++.h>
#define ll long long
#define MAXN 1000005
using namespace std;
unsigned ll n,m,a[MAXN],ans[MAXN<<2];bool tag[MAXN<<2];
inline ll ls(ll x){
	return x<<1;
}
inline ll rs(ll y){
	return y<<1|1;
}
inline void f(ll p,ll l,ll r,ll k){
	tag[p]=tag[p]+k;
	ans[p]=ans[p]+k*(r-l+1);
}
void in(){
	for(ll i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	return;
}
inline void push_up(ll p){
	if(tag[rs(p)]&&tag[ls(p)]) tag[p]=1;
	ans[p]=ans[ls(p)]+ans[rs(p)];
}
inline void push_down(ll p,ll l,ll r){
	ll mid=(l+r)>>1;
	f(ls(p),l,mid,tag[p]);
	f(rs(p),mid+1,r,tag[p]);
	tag[p]=0;
}

void build(ll p,ll l,ll r){
	if(l==r){
		if(a[l]==1||a[l]==0) tag[p]=1;
		ans[p]=a[l];return;
	}
	ll mid=(l+r)>>1;
	build(ls(p),l,mid);
	build(rs(p),mid+1,r);
	push_up(p);
}

inline void update(ll l1,ll r1,ll l,ll r,ll p){
	if(tag[p]){
		return;
	}
	if(l==r){
		if(ans[p]==1||ans[p]==0) tag[p]=1;
		else ans[p]=sqrt(ans[p]);
		return;
	}
	ll mid=(l+r)>>1;
	if(l1<=mid) update(l1,r1,l,mid,ls(p));
	if(r1>mid) update(l1,r1,mid+1,r,rs(p));
	push_up(p);
}
ll query(ll x,ll y,ll l,ll r,ll p){
	ll res=0;
	if(x<=l&&y>=r){
		return ans[p];
	}
	ll mid=(l+r)>>1;
	//push_down(p,l,r);
	if(x<=mid) res+=query(x,y,l,mid,ls(p));
	if(y>mid) res+=query(x,y,mid+1,r,rs(p));
	return res;
}
int main(){
	ll a1,b,c,d,e,f;
int p=0;
	while(scanf("%lld",&n)){
		memset(ans,0,sizeof ans);
		memset(tag,0,sizeof tag);
		p++;
		cout<<"case #"<<p<<":"<<endl;
		in();
		cin>>m;
	build(1,1,n);while(m--){
		scanf("%lld",&a1);
		if(a1==0){
				scanf("%lld%lld",&b,&c);
				if(b>c) swap(b,c);
				update(b,c,1,n,1);
			}
		else{
				scanf("%lld%lld",&e,&f);
				if(e>f) swap(e,f);
				printf("%lld\n",query(e,f,1,n,1));
			}
		}
		cout<<endl;
	}
		
	return 0;
}

求调QAQ

2024/11/23 12:33
加载中...