全WA,样例能过,玄关求条
查看原帖
全WA,样例能过,玄关求条
754639
I_Was_Spasmodic楼主2024/10/7 00:00

rt

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+5;
int a[N];
int op,l,r,x,n,q;
struct seg{
	int l,r,add;
	double s,c;
}t[N<<3];	// 这里不知道为什么开四倍会 RE
void down(int p)
{
	if(t[p].add)
	{
		double s=cos(t[p].add)*t[p].s+sin(t[p].add)*t[p].c;
		double c=cos(t[p].add)*t[p].c-sin(t[p].add)*t[p].s;
		t[p].s=s;
		t[p].c=c;
		t[p*2].add+=t[p].add;
		t[p*2+1].add+=t[p].add;
		t[p].add=0;
	}
}
void upd(seg &A,seg B,seg C)
{
	A.c=B.c+C.c;
	A.s=B.s+C.s; 
}
void upd(seg &A,int b,int c)
{
	down(b);
	down(c);
	A.c=t[b].c+t[c].c;
	A.s=t[b].s+t[c].s;
}
void build(int p,int l,int r)
{
	t[p].l=l;t[p].r=r;
	if(l==r)
	{
		t[p].s=sin(a[l]);
		t[p].c=cos(a[l]);
		return;
	}
	int mid=(l+r)>>1;
	build(p*2,l,mid);
	build(p*2+1,mid+1,r);
	upd(t[p],p*2,p*2+1);
}
double ask(int p,int l,int r)
{
	//printf("vis [%d,%d] , want [%d,%d]\n",t[p].l,t[p].r,l,r);
	if(t[p].l==l and t[p].r==r)return t[p].s;
	int mid=(t[p].l+t[p].r)>>1;
	down(p);
	double res=0;
	if(l<=mid)res+=ask(p*2,l,min(r,mid));
	else if(r>mid)res+=ask(p*2+1,max(l,mid+1),r);
	return res;
}
void change(int p,int l,int r,int x)
{
	//printf("vis [%d,%d] , want [%d,%d]\n",t[p].l,t[p].r,l,r);
	if(t[p].l==l and t[p].r==r)
	{
		t[p].add+=x;
		return;
	}
	down(p);
	int mid=(t[p].l+t[p].r)>>1;
	if(l<=mid)change(p*2,l,min(mid,r),x);
	if(r>mid)change(p*2+1,max(mid+1,l),r,x);
	upd(t[p],p*2,p*2+1);
}
signed main()
{
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	build(1,1,n);
	cin>>q;
	while(q--)
	{
		cin>>op>>l>>r;
		if(op==1)
		{
			cin>>x;
			change(1,l,r,x);
		}
		else {
			printf("%.1lf\n",ask(1,l,r));
		}
	}
}
2024/10/7 00:00
加载中...