样例过全WA求调
查看原帖
样例过全WA求调
339728
末然Ender楼主2024/10/10 17:43

rt

#include<bits/stdc++.h>
using namespace std;
template<typename T>
void read(T& x) {
	x=0;
	char ch=getchar();
	long long f=1;
	while(!isdigit(ch)) {
		if(ch=='-')f*=-1;
		ch=getchar();
	}
	while(isdigit(ch)) {
		x=x*10+ch-48;
		ch=getchar();
	}
	x*=f;
}
template<typename T,typename... Args>
void read(T& first,Args&... args) {
	read(first);
	read(args...);
}
template<typename T>
void write(T arg) {
	T x=arg;
	if (x<0) {
		putchar('-');
		x=-x;
	}
	if(x>9) {
		write(x/10);
	}
	putchar(x%10+'0');
}
template<typename T,typename... Args>
void write(T arg,Args... args) {
	write(arg);
	if(sizeof...(args) !=0) {
		putchar(' ');
		write(args...);
	}
}
typedef long long ll;
const int N=5e5+5,mod=998244353;
struct segtree{
	int l,r;
	double sn,cs;
	ll lazy;
}tr[N<<2];
#define lc root<<1
#define rc root<<1|1
ll a[N],n,q;
void pushup(int root){
	tr[root].sn=tr[lc].sn+tr[rc].sn;
	tr[root].cs=tr[lc].cs+tr[rc].cs;
}
void build(int root,int l,int r){
	tr[root].l=l,tr[root].r=r;
	if(l==r){
		tr[root].sn=sin(a[l]);
		tr[root].cs=cos(a[l]);
		return;
	}
	int mid=l+r>>1;
	build(lc,l,mid);
	build(rc,mid+1,r);
	pushup(root);
}
void pushdown(int root){
	if(!tr[root].lazy)return;
	tr[lc].lazy+=tr[root].lazy,tr[rc].lazy+=tr[root].lazy;
	double sn=sin(tr[root].lazy),cs=cos(tr[root].lazy);
	tr[lc].sn=tr[lc].sn*cs+tr[lc].cs*sn;
	tr[lc].cs=tr[lc].cs*cs-tr[lc].sn*sn;
	tr[rc].sn=tr[rc].sn*cs+tr[rc].cs*sn;
	tr[rc].cs=tr[rc].cs*cs-tr[rc].sn*sn;
	tr[root].lazy=0;
}
void update(int root,int l,int r,ll val){
	if(l<=tr[root].l&&tr[root].r<=r){
		double sn=sin(val),cs=cos(val);
		tr[root].sn=tr[lc].sn*cs+tr[root].cs*sn;
		tr[root].cs=tr[lc].cs*cs-tr[root].sn*sn;
		tr[root].lazy+=val;
		return;
	}
	pushdown(root);
	int mid=tr[root].l+tr[root].r>>1;
	if(l<=mid)update(lc,l,r,val);
	if(r>mid)update(rc,l,r,val);
	pushup(root);
}
double query(int root,int l,int r){
	if(l<=tr[root].l&&tr[root].r<=r){
		return tr[root].sn;
	}
	pushdown(root);
	double ans=0;
	int mid=tr[root].l+tr[root].r>>1;
	if(l<=mid)ans+=query(lc,l,r);
	if(r>mid)ans+=query(rc,l,r);
	return ans;
}
int main() {
	read(n);
	for(int i=1;i<=n;i++)read(a[i]);
	build(1,1,n);
	read(q);
	while(q--){
		int op;
		ll a,b,c;
		read(op);
		if(op==1){
			read(a,b,c);
			update(1,a,b,c);
		}else{
			read(a,b);
			printf("%.1lf\n",query(1,a,b));
		}
	}
	return 0;
}
2024/10/10 17:43
加载中...