线段树维护角度,把线段看成向量然后旋转这个部分有点不好想
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int MAXN=11111;
const double pi=acos(-1.0);
struct node
{
double x,y;
}stree[MAXN<<2];
double cont[MAXN<<2];
void pushup(int rt){
stree[rt].x=stree[rt<<1].x+stree[rt<<1|1].x;
stree[rt].y=stree[rt<<1].y+stree[rt<<1|1].y;
}
void build(int l,int r,int rt)
{
if(l==r)
{
double y;
scanf("%lf",&y);
stree[rt].x=0;
stree[rt].y=y;
return;
}
int mid=(l+r)>>1;
build(lson);
build(rson);
pushup(rt);
}
void f(int rt,double at)
{
double x=stree[rt].x;
double y=stree[rt].y;
stree[rt].x=x*cos(at)-y*sin(at);
stree[rt].y=x*sin(at)+y*cos(at);
}
void pushdown(int rt)
{
if(cont[rt]!=0)
{
cont[rt<<1]+=cont[rt];
cont[rt<<1|1]+=cont[rt];
f(rt<<1,cont[rt]);
f(rt<<1|1,cont[rt]);
cont[rt]=0;
}
}
void update(int L,int R,double at,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
cont[rt]+=at;
f(rt,at);
return;
}
pushdown(rt);
int mid=(l+r)>>1;
if(L<=mid) update(L,R,at,lson);
if(R>mid) update(L,R,at,rson);
pushup(rt);
}
int main()
{
int n,c;
int kace=0;
while(scanf("%d%d",&n,&c)!=EOF)
{
if(kace++) puts("");
memset(cont,0,sizeof(cont));
build(1,n,1);
int angle[MAXN<<2];
for(int i=1;i<=n;i++)
angle[i]=180;
while(c--)
{
int a,b;
scanf("%d%d",&a,&b);
int at1=(b-angle[a]+360)%360;
update(a+1,n,at1*1.0/180.0*pi,1,n,1);
angle[a]=b;
printf("%.2lf %.2lf\n",stree[1].x,stree[1].y);
}
}
return 0;
}