求大佬帮忙看看
查看原帖
求大佬帮忙看看
363495
我爱杨帆楼主2020/11/18 15:40
#include<bits/stdc++.h>
using namespace std;
#define l(p) tree[p].l
#define r(p) tree[p].r
#define sind(p) tree[p].sind
#define add(p) tree[p].add
#define cosd(p) tree[p].cosd
#define int long long
const int sz=2e6+5;
int read()
{
	char c=getchar();
	int r=0,f=1;
	while((c<'0'||c>'9')&&c!='-')
		c=getchar();
	if(c=='-') {
		f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9') {
		r=r*10+c-'0';
		c=getchar();
	}
	return f*r;
}
int n,m,a[sz];
struct node {

	int l,r;
	double sind,add,cosd;
};
node tree[sz*4];
void build(int l,int r,int p)
{
	l(p)=l,r(p)=r;
	if(l==r) {
		tree[p].sind=sin(a[l]),tree[p].cosd=cos(a[l]);
		return;
	}
	int mid=(l+r)>>1;
	build(l,mid,p<<1);
	build(mid+1,r,p<<1|1);
	sind(p)=sind(p<<1)+sind(p<<1|1);
	cosd(p)=cosd(p<<1)+cosd(p<<1|1);
}
void spread(int p)
{
	if(!add(p)) return;
	double sindd=sind(p<<1),cosdd=cosd(p<<1);
	sind(p<<1)=sindd*cos(add(p))+cosdd*sin(add(p));
	cosd(p<<1)=cosdd*cos(add(p))-sindd*sin(add(p));
	sindd=sind(p<<1|1),cosdd=cosd(p<<1|1);
	sind(p<<1|1)=sindd*cos(add(p))+cosdd*sin(add(p));
	cosd(p<<1|1)=cosdd*cos(add(p))-sindd*sin(add(p));
	add(p)=0;
	return;
}
void change(int l,int r,int p,double sd,double cd,double d)
{
	if(l<=l(p)&&r(p)<=r) {
		double sindd=sind(p),cosdd=cosd(p);
		sind(p)=sindd*cd+cosdd*sd,cosd(p)=cosdd*cd-sd*sindd;
	    add(p)+=d;
		return;
	}
	spread(p);
	int mid=(l(p)+r(p))>>1;
	if(mid>=l) change(l,r,p<<1,sd,cd,d);
	if(mid<r)  change(l,r,p<<1|1,sd,cd,d);
	sind(p)=sind(p<<1)+sind(p<<1|1);
	cosd(p)=cosd(p<<1)+cosd(p<<1|1);
}
double ask(int l,int r,int p)
{
	if(l<=l(p)&&r(p)<=r) return sind(p);
	spread(p);
	int mid=(l(p)+r(p))>>1;
	double ans=0;
	if(mid>=l) ans+=ask(l,r,p<<1);
	if(mid<r)  ans+=ask(l,r,p<<1|1);
	return ans;
}
signed main()
{
	n=read();
	for(int i=1; i<=n; i++) a[i]=read();
	build(1,n,1);
	m=read();
	for(int i=1; i<=m; i++) {
		int op=read();
		if(op==1) {
			int l=read(),r=read(),v=read();
			double sd=sin(v),cd=cos(v);
			change(l,r,1,sd,cd,v);
		} else {
			int l=read(),r=read();
			double anss=ask(l,r,1);
			printf("%.1f\n",anss);
		}
	}
}
/*
10
1978978069 3579789789 177978947 7897895345 543879789 357878979 567564 218797823 419789231 123789911 
20
2 1 1
2 3 6
2 3 5
1 4 6 0
2 6 5
2 4 9
1 2 5 3
1 2 9 9
1 3 4 5
1 2 3 5
1 1 3 4
1 4 5 6
1 4 8 5
1 4 3 1
1 3 4 2
2 4 9
1 5 7 8
2 1 3
1 3 4 7
2 3 7
*/

试了很多组数据,全WA了,long long 也开了

2020/11/18 15:40
加载中...