社区讨论

全WA求调

P6327区间加区间 sin 和参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mlhq0r1m
此快照首次捕获于
2026/02/11 15:41
上周
此快照最后确认于
2026/02/11 15:52
上周
查看原帖
有调必关!(已经调懵逼了)
CPP
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+5;
int n,m,l,r,v,op;
long double a[N];
struct{
	int lson,rson;
	long double lazy,si,co;
	#define mid (t[p].lson+t[p].rson)/2
}t[N<<2];
void build(int p,int lc,int rc){
	t[p].lson=lc;
	t[p].rson=rc;
	if(lc==rc){
		t[p].si=sin(a[lc]);
		t[p].co=cos(a[lc]);
		return;
	}
	build(p<<1,lc,mid);
	build(p<<1|1,mid+1,rc);
	t[p].si=t[p<<1].si+t[p<<1|1].si;
	t[p].co=t[p<<1].co+t[p<<1|1].co;
}
void spread(int p){
	double tp=t[p<<1].si*cos(t[p].lazy)+t[p<<1].co*sin(t[p].lazy);
	double to=t[p<<1].co*cos(t[p].lazy)-t[p<<1].si*sin(t[p].lazy);
	t[p<<1].si=tp;
	t[p<<1].co=to;
	tp=t[p<<1|1].si*cos(t[p].lazy)+t[p<<1|1].co*sin(t[p].lazy);
	to=t[p<<1|1].co*cos(t[p].lazy)-t[p<<1|1].si*sin(t[p].lazy);
	t[p<<1|1].si=tp;
	t[p<<1|1].co=to;
	t[p].lazy=0;
}
void change(int p,int lc,int rc,int d){
	if(lc<=t[p].lson && t[p].rson<=rc){
		t[p].si=t[p].si*cos(d)+t[p].co*sin(d);
		t[p].co=t[p].co*cos(d)-t[p].si*sin(d);
		t[p].lazy+=d;
		return;
	}
	spread(p);
	if(lc<=mid)
		change(p<<1,lc,rc,d);
	if(rc>mid)
		change(p<<1|1,lc,rc,d);
	t[p].si=t[p<<1].si+t[p<<1|1].si;
	t[p].co=t[p<<1].co+t[p<<1|1].co;
}
double asksin(int p,int lc,int rc){
	if(lc<=t[p].lson && t[p].rson<=rc)
		return t[p].si;
	spread(p);
	double al=0;
	if(lc<=mid)
		al+=asksin(p<<1,lc,rc);
	if(rc>mid)
		al+=asksin(p<<1|1,lc,rc);
	return al;
}
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	build(1,1,n);
	cin>>m;
	while(cin>>op>>l>>r){
		if(op==1){
			cin>>v;
			change(1,l,r,v);
		}
		else
			cout<<fixed<<setprecision(1)<<asksin(1,l,r)<<endl;
	}
	return 0;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...