RT,调了有点久了(
求神仙看看。
这是用样例跑出来的:
但是交了之后就是WA。
代码:
#include<bits/stdc++.h>
using namespace std;
namespace fastIO{
#define spc ;putchar(' ');
#define ent ;puts("");
template<typename T>inline void read(T &x){
x=0;int f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
}x*=f;
}
template<typename T>inline void write(T x){
if(x<0){
x=-x,putchar('-');
}
if(x>9){
write(x/10);
}putchar(x%10+48);
}
}using namespace fastIO;
const int si=2e5+10;
int n,m;
int a[si];
struct segment_tree{
int l,r;
double sum_cos,sum_sin;
int lazytag;
#define l(o) t[o].l
#define r(o) t[o].r
#define tag(o) t[o].lazytag
#define sinv(o) t[o].sum_sin
#define cosv(o) t[o].sum_cos
#define lson(o) o<<1
#define rson(o) o<<1|1
}t[si*4];
void pushup(int p){
sinv(p)=sinv(lson(p))+sinv(rson(p));
cosv(p)=cosv(lson(p))+cosv(rson(p));
}
void add(int p,double sin_,double cos_){
sinv(p)=sinv(p)*cos_+cosv(p)*sin_;
cosv(p)=cosv(p)*cos_-sinv(p)*sin_;
}
inline void build(int p,int l,int r){
l(p)=l,r(p)=r;
if(l==r){
sinv(p)=sin(a[l]);
cosv(p)=cos(a[l]);
return;
}
int mid=(l+r)>>1;
build(lson(p),l,mid);
build(rson(p),mid+1,r);
pushup(p);
}
inline void pushdown(int p){
if(tag(p)){
add(lson(p),sin(tag(p)),cos(tag(p)));
add(rson(p),sin(tag(p)),cos(tag(p)));
tag(lson(p))+=tag(p),tag(rson(p))+=tag(p);
tag(p)=0;
}
}
void update(int p,int l,int r,int v){
int nl=l(p),nr=r(p);
if(l<=nl&&nr<=r){
add(p,sin(v),cos(v));
tag(p)+=v;
return;
}
pushdown(p);
int mid=(nl+nr)>>1;
if(l<=mid){
update(lson(p),l,r,v);
}
if(r>mid){
update(rson(p),l,r,v);
}
pushup(p);
}
double query(int p,int l,int r){
int nl=l(p),nr=r(p);
if(l<=nl&&nr<=r){
return sinv(p);
}
pushdown(p);
double res=0.0;
int mid=(nr+nl)>>1;
if(l<=mid){
res+=query(lson(p),l,r);
}
if(r>mid){
res+=query(rson(p),l,r);
}
return res;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("out.txt","w",stdout);
#endif
read(n);
for(register int i=1;i<=n;++i){
read(a[i]);
}
build(1,1,n);
read(m);
while(m--){
int op,x,y,k;
read(op),read(x),read(y);
if(op==1){
read(k);
update(1,x,y,k);
}
else{
printf("%.1lf\n",query(1,x,y));
}
}
return 0;
}