我们知道当第i+1根棍子旋转的时候,i+1~n根棍子都是相对不动的,只是角度变了而已。
考虑维护每个区间内线段从起点指向终点的向量投影,那么我们要的答案就是整个区间的向量投影。
每次更新的时候只需要知道第i+1与前一个线段的夹角改变了多少,然后区间更新i+1~n的整体转角向量投影,最后别忘把更新的向量pushup上来。
#pragma GCC optimize(2)
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn = 1e4+5;
const int mod = 1e9+9;
int Case = 1;
int n, m;
struct node{
int l, r;
double x, y, lazy;
int mid() {
return (l+r)/2;
}
}tr[maxn<<2];
void pushup(int rt) {
tr[rt].x = tr[rt<<1].x + tr[rt<<1|1].x;
tr[rt].y = tr[rt<<1].y + tr[rt<<1|1].y;
}
void build(int rt, int l, int r) {
tr[rt].l = l;tr[rt].r = r;
tr[rt].lazy = tr[rt].x = 0;
if(l == r) {
scanf("%lf", &tr[rt].y);
return;
}
int mid = tr[rt].mid();
build(rt<<1, l, mid);
build(rt<<1|1, mid+1, r);
pushup(rt);
}
void pushdown(int rt) {
if(tr[rt].lazy) {
double &arc = tr[rt].lazy;
double x = tr[rt<<1].x*cos(arc) + tr[rt<<1].y*sin(arc);
double y = tr[rt<<1].y*cos(arc) - tr[rt<<1].x*sin(arc);
tr[rt<<1].x = x;tr[rt<<1].y = y;
tr[rt<<1].lazy += arc;
x = tr[rt<<1|1].x*cos(arc) + tr[rt<<1|1].y*sin(arc);
y = tr[rt<<1|1].y*cos(arc) - tr[rt<<1|1].x*sin(arc);
tr[rt<<1|1].x = x; tr[rt<<1|1].y = y;
tr[rt<<1|1].lazy += arc;
arc = 0;
}
}
void update(int rt, int l, int r, double arc) {
if(tr[rt].l == l && tr[rt].r == r) {
double x = tr[rt].x*cos(arc) + tr[rt].y*sin(arc);
double y = tr[rt].y*cos(arc) - tr[rt].x*sin(arc);
tr[rt].x = x;tr[rt].y = y;
tr[rt].lazy += arc;
return;
}
int mid = tr[rt].mid();
pushdown(rt);
if(r <= mid) update(rt<<1, l, r, arc);
else if(l > mid) update(rt<<1|1, l, r, arc);
else {
update(rt<<1, l, mid, arc);update(rt<<1|1, mid+1, r, arc);
}
pushup(rt);
}
const double pi = acos(-1.0);
double ang[maxn];
void solve() {
build(1, 1, n);
static int cnt = 0;
if(cnt++) printf("\n");
for(int i = 1; i <= n; i++) ang[i] = pi;
for(int i = 1; i <= m; i++) {
int p, c;scanf("%d%d", &p, &c);
double arc = c/360.0*2*pi;
update(1, p+1, n, ang[p]-arc);
ang[p] = arc;
printf("%.2f %.2f\n", tr[1].x, tr[1].y);
}
return;
}
int main() {
while(scanf("%d%d", &n, &m) == 2) {
solve();
}
return 0;
}