#include <bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
register int x = 0, f = 1;
register char c = getchar();
while(c < '0' || c > '9')
{
if(c == '-')f = -1;
c = getchar();
}
while(c <= '9' && c >= '0')
{
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
inline void write(int x)
{
if(!x)return;
write(x / 10);
putchar(x % 10 + '0');
return;
}
struct node
{
int l, r;
double sumsin, sumcos;
int lazy;
}t[2000010];
int n, m;
double sinn[400], coss[400];
int a[1000010];
void pushdown(int q)
{
if(t[q].lazy != 0)
{
double x = t[q].sumsin, y = t[q].sumcos;
t[q].sumsin = x * coss[t[q].lazy % 360] + y * sinn[t[q].lazy % 360];
t[q].sumcos = y * coss[t[q].lazy % 360] - x * sinn[t[q].lazy % 360];
if(q * 2 <= n * 4)t[q * 2].lazy += t[q].lazy;
if(q * 2 + 1 <= n * 4)t[q * 2 + 1].lazy += t[q].lazy;
t[q].lazy = 0;
}
return;
}
void update(int q)
{
pushdown(q);
pushdown(q * 2);
pushdown(q * 2 + 1);
t[q].sumsin = t[q * 2].sumsin + t[q * 2 + 1].sumsin;
t[q].sumcos = t[q * 2].sumcos + t[q * 2 + 1].sumcos;
return;
}
void build(int q, int l, int r)
{
t[q].l = l, t[q].r = r, t[q].lazy = 0;
if(l == r)
{
t[q].sumsin = sinn[a[l] % 360];
t[q].sumcos = coss[a[l] % 360];
return;
}
build(q * 2, l, (l + r) / 2);
build(q * 2 + 1, (l + r) / 2 + 1, r);
update(q);
return;
}
void add(int q, int l, int r, int k)
{
if(l > t[q].r || r < t[q].l)return;
if(l <= t[q].l && t[q].r <= r)
{
t[q].lazy += k;
return;
}
pushdown(q);
add(q * 2, l, r, k);
add(q * 2 + 1, l, r, k);
update(q);
return;
}
double query(int q, int l, int r)
{
if(l > t[q].r || r < t[q].l)return 0;
if(l <= t[q].l && t[q].r <= r)
{
double x = t[q].sumsin, y = t[q].sumcos;
return x * coss[t[q].lazy % 360] + y * sinn[t[q].lazy % 360];
}
pushdown(q);
double ans = 0;
ans += query(q * 2, l, r);
ans += query(q * 2 + 1, l, r);
update(q);
return ans;
}
void init_t()
{
for(int i = 0;i <= 360;i++)
{
sinn[i] = sin(i);
coss[i] = cos(i);
}
return;
}
signed main()
{
init_t();
cin >> n;
for(int i = 1;i <= n;i++)
{
cin >> a[i];
}
build(1, 1, n);
cin >> m;
while(m--)
{
int l, r, v, op;
cin >> op >> l >> r;
if(op == 1)
{
cin >> v;
add(1, l, r, v);
}
else
{
printf("%.1lf\n", round(query(1, l, r) * 10) / 10.0);
}
}
return 0;
}
警示后人也看过了,小数据也测过了。