Tony102's Blog - 三角函数
type: channel
link: https://tony102.com/index.php/tag/%E4%B8%89%E8%A7%92%E5%87%BD%E6%95%B0/
items: Luogu6327 区间加区间sin和

Luogu6327 区间加区间sin和
type: item
date: 2020-11-28T11:28:00+08:00
description: Link前置知识这个题还是要先学会和角公式(有的什么毒瘤复数的做法太无聊了)$$ \sin(\alpha + \beta) = \sin(\alpha)\cos(\beta) + \cos(\alpha)\sin(\beta) $$$$ \cos(\alpha + \beta) = \cos(\alpha)\cos(\beta) - \sin(\alpha)\sin(\beta) $$Sol有了上面的公式,你应该就会做这个题了.加入现在要给 $[l,r]$ 内的所有角加上一个 $\alpha$ 角那么$$ \sum_{i=l}^{r} \sin(a_i + \alpha) = \sum_{i=l}^{r} \sin(a_i) \times \cos(\alpha) + \sum_{i= l}^{r} \cos(a_i) \times \sin(\alpha) $$那么需要维护区间 $\sin$ 和 $\cos$ 的和$$ \sum_{i=l}^{r} \cos(a_i + \alpha) = \sum_{i=l}^{r} \cos(a_i) \times \cos(\alpha) - \sum_{i= l}^{r} \sin(a_i) \times \sin(\alpha) $$也许到这里你就会了.还要注意的地方是,每次更新 $\sin$ 和 $\cos$ 的时候要先记录一下没更新前的值,再更新.如果你这么做的话tree[lson(p)].sine = cos(tree[p].tag) * tree[lson(p)].sine + sin(tree[p].tag) * tree[lson(p)].cosine; tree[lson(p)].cosine = tree[lson(p)].cosine * cos(tree[p].tag) - tree[lson(p)].sine * sin(tree[p].tag);就会跟我一样sb还有要开long longCode#include <bits/stdc++.h> using namespace std; #define int long long const int SIZE = 3e5 + 5; int n, q; int a[SIZE]; struct node { int l, r, tag; double cosine, sine; } tree[SIZE << 2]; namespace ae86 { const int bufl = 1 << 15; char buf[bufl], *s = buf, *t = buf; inline int fetch() { if (s == t) { t = (s = buf) + fread(buf, 1, bufl, stdin); if (s == t) return EOF; } return *s++; } inline int read() { int a = 0, b = 1, c = fetch(); while (!isdigit(c))b ^= c == '-', c = fetch(); while (isdigit(c)) a = a * 10 + c - 48, c = fetch(); return b ? a : -a; } } using ae86::read; #define lson(p) p << 1 #define rson(p) p << 1 | 1 inline void pushUp(int p) { tree[p].cosine = tree[lson(p)].cosine + tree[rson(p)].cosine; tree[p].sine = tree[lson(p)].sine + tree[rson(p)].sine; } inline void pushDown(int p) { if (tree[p].tag != 0.00) { double lsine = tree[lson(p)].sine, rsine = tree[rson(p)].sine; double lcos = tree[lson(p)].cosine, rcos = tree[rson(p)].cosine; tree[lson(p)].sine = cos(tree[p].tag) * lsine + sin(tree[p].tag) * lcos; tree[lson(p)].cosine = lcos * cos(tree[p].tag) - lsine * sin(tree[p].tag); tree[rson(p)].sine = cos(tree[p].tag) * rsine …