Segment Tree POJ 2991

Source: Internet
Author: User
Tags cos

All we have to do is sum up these vectors, and the final point is the end point, so we just maintain the bounds of the vector and we can. For the second problem, we can use an array degree[i] to represent the i-1 vector and the current angle of the first vector, so that there is the current state, each read into the operation will be convenient to get the equivalent of the rotation of how many angles of operation, and then update the degree[i] can. And each time we read an operation that affects only one degree[] value, it does not affect the other degree[].

All in all, we want to think of each segment as a vector, and maintain the interval of these vectors, as well as the operation of adding a value to each element in the interval.

#include <stdio.h>#include<string.h>#include<algorithm>#include<math.h>using namespacestd;#defineMAXN 10010Const DoublePi =acos (-1.0);intz[maxn],deg[maxn],re[maxn<<3];structnode{intL,r; Doublex, y;} X[MAXN<<3];DoubleGetrad (inta) {    returna*pi/ the;}voidBuild (intLintRinta) {X[A].L=l; X[A].R=R; x[a].x=0; X[a].y=z[r]-z[l-1]; Re[a]=0; if(l==R)return ; intMid= (l+r) >>1; Build (L,mid,a<<1); Build (Mid+1,r,a<<1|1);}voidRotate (Double&AMP;DX,Double&dy,Doublerad) {    Doublex=dx,y=dy; DX=x*cos (RAD)-y*sin (RAD); Dy=x*sin (RAD) +y*cos (RAD);}voidPush_down (inta) {    DoubleRad=Getrad (Re[a]); intls=a<<1,rs=a<<1|1; if(Re[a]) {Re[ls]+=Re[a]; RE[RS]+=Re[a];        Rotate (X[ls].x,x[ls].y,rad);        Rotate (X[rs].x,x[rs].y,rad); Re[a]=0; }}voidPUSH_UP (inta) {x[a].x=x[a<<1].x+x[a<<1|1].x; X[a].y=x[a<<1].y+x[a<<1|1].y;}voidUpdateintLintRintA1,intWinta) {    DoubleRad=Getrad (W); if(l==r) {Rotate (X[a].x,x[a].y,rad); return ;    } push_down (a); intMid= (l+r) >>1; if(mid<A1) Update (Mid+1,r,a1,w,a<<1|1); Else{update (L,mid,a1,w,a<<1); Rotate (X[a<<1|1].x,x[a<<1|1].y,rad); Re[a<<1|1]+=W; } push_up (a);}intMain () {intN,m,ca=1;  while(SCANF ("%d%d", &n,&m)! =EOF) {        if(ca!=1) printf ("\ n"); CA++;  for(intI=1; i<=n;i++) {scanf ("%d",&Z[i]); Z[i]=z[i-1]+Z[i]; } memset (deg,0,sizeof(deg)); Build (1N1);  for(intI=1; i<=m;i++)        {            intS,a; scanf ("%d%d",&s,&a); S++; A=a- the; intdelta=a-Deg[s]; Deg[s]=A; Update (1, N,s,delta,1); printf ("%.2LF%.2lf\n", x[1].x,x[1].y); }    }    return 0;}

Segment Tree POJ 2991

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.