rt,求条/ll/dk
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') {
f = -1;
}
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
int n, m;
int a[N];
struct segment_tree {
int l, r;
double sina, cosa;
int lazy;
#define l(x) t[x].l
#define r(x) t[x].r
#define tsin(x) t[x].sina
#define tcos(x) t[x].cosa
#define lazy(x) t[x].lazy
}t[N * 4];
void upd(int u, double sinx, double cosx) {
double tmp_sin = tsin(u), tmp_cos = tcos(u);
tsin(u) = tmp_sin * cosx + tmp_cos * sinx;
tcos(u) = tmp_cos * cosx - tmp_sin * sinx;
}
void pushup(int p) {
tsin(p) = tsin(p << 1) + tsin(p << 1 | 1);
tcos(p) = tcos(p << 1) + tcos(p << 1 | 1);
}
void pushdown(int p) {
if (lazy(p) == 0) {
return;
}
double lazy_sin = sin(lazy(p)), lazy_cos = cos(lazy(p));
upd(p << 1, lazy_sin, lazy_cos);
upd(p << 1 | 1, lazy_sin, lazy_cos);
lazy(p << 1) += lazy(p);
lazy(p << 1 | 1) += lazy(p);
lazy(p) = 0;
}
void build(int p, int l, int r) {
l(p) = l, r(p) = r;
if (l == r) {
tsin(p) = sin(a[l]);
tcos(p) = cos(a[l]);
return;
}
int mid = (l + r) >> 1;
build(p << 1, l, mid);
build(p << 1 | 1, mid + 1, r);
pushup(p);
}
void add(int p, int l, int r, int v, double sinv, double cosv) {
if (l <= l(p) && r >= r(p)) {
upd(p, sinv, cosv);
lazy(p) += v;
return;
}
pushdown(p);
int mid = (l(p) + r(p)) >> 1;
if (l <= mid) {
add(p << 1, l, r, v, sinv, cosv);
}
if (r > mid) {
add(p << 1 | 1, l, r, v, sinv, cosv);
}
pushup(p);
}
double ask(int p, int l, int r) {
if (l <= l(p) && r >= r(p)) {
return tsin(p);
}
double ans = 0;
int mid = (l(p) + r(p)) >> 1;
pushdown(p);
if (l <= mid) {
ans += ask(p << 1, l, r);
}
if (r > mid) {
ans += ask(p << 1 | 1, l, r);
}
return ans;
}
int main() {
n = read();
for (int i = 1; i <= n; ++i) {
a[i] = read();
}
build(1, 1, n);
m = read();
while (m--) {
int op, l, r;
if (read() == 1) {
int l = read(), r = read(), v = read();
add(1, l, r, v, sin(v), cos(v));
}else {
printf("%.1lf\n", ask(1, read(), read()));
}
}
return 0;
}