問題を解決するには、[[Ynoi2012] NOIP2015は希望に満ちました]

\ [\ texttt {はじめ} \]

道路Ynoiのメモリ内の2番目のタイトル、。

これはおそらく、私は自分自身が被写体をYnoi行うことができる唯一のことです。
\ [\ Texttt {説明} \
] 長さを維持するためには、\(N- \)列の数である\(A \) 支持体の2つの動作モードは:

  • 1 l r v\(a_l、A_ {L + 1}、...、A_R \) をそれぞれ加えた\(V \)
  • 2 l r询问\(\和\ limits_ {I = L} \制限は^ {R} \ SIN(a_iを)\)

\ [\ texttt {解決} \]

  • インターバル間隔は、変更とクエリは、私たちは木のラインを思わせます。

  • 木の線分の間隔を維持するようにします\(\罪を\)と。

  • 私たちは、時間間隔を加えたオリジナルのことがわかった\(\罪(a_iを)\は ) となっている\(\ SIN(a_iを+ V)\) 直接メンテナンスすることは容易ではありません。

  • これら2つの式を考える:
    \ [\ SIN(A + V)= \ AのSiN \ COS + V \ A COS \のSiN V \]

    \ [\ \ V無し無しのCos(+のV)= \ COS \ COS V- \ \]

  • 明らかに間隔プラス間隔\([L、R] \ ) の\(\のSiN \)\(\和\ limits_ {I = L} \制限が^ {R} \ SIN(a_iを)\) となります\(\ SUM \ limits_ {I = L} \限界^ {R&LT} \ SIN(a_iを+ V)\) さらに、ある:
    \ [\ SUM \ limits_ {I = L} \制限は^ {R&LT} \のSiN a_iを\ COS V + \ COS a_iを \罪のV \]

\ [\ V COS \和\ limits_ {I = L} \制限が^ {R} \罪a_iを+ \罪V \和\ limits_ {I = L} \制限が^ {R} \ COS a_iを\]

  • 我々はより長い間隔維持できるように、(\ COS \)\と、間隔を加えた上で([L、R] \ \ ) の\(\ COS \)の影響をとなります。

\ [\ V COS \和\ limits_ {I = L} \制限は^ {R} \ COS a_iを - \罪のV \和\ limits_ {iはLを=} \限界^ {R} \罪a_iを\]

  • 上記の式の更新間隔の適用\(\ SiNから\)との間隔と、\(\ COS \)をし、素人のマークを覚えています。

\ [\ texttt {コード} \]

#include<cstdio>
#include<cmath>

#define RI register int

using namespace std;

namespace IO
{
    static char buf[1<<20],*fs,*ft;
    inline char gc()
    {
        if(fs==ft)
        {
            ft=(fs=buf)+fread(buf,1,1<<20,stdin);
            if(fs==ft)return EOF;
        }
        return *fs++;
    }
    #define gc() getchar()
    inline int read()
    {
        int x=0,f=1;char s=gc();
        while(s<'0'||s>'9'){if(s=='-')f=-f;s=gc();}
        while(s>='0'&&s<='9'){x=x*10+s-'0';s=gc();}
        return x*f;
    }
}using IO::read;

const int N=200100;

int n,m;

int a[N];

struct SegmentTree{
    int l,r;
    double sinv,cosv;
    long long tag;
}t[N*4];

void upd(int p)
{
    t[p].sinv=t[p*2].sinv+t[p*2+1].sinv;
    t[p].cosv=t[p*2].cosv+t[p*2+1].cosv;
}

void spread(int p)
{
    if(t[p].tag)
    {
        double sina,cosa,sinx=sin(t[p].tag),cosx=cos(t[p].tag);
        sina=t[p*2].sinv,cosa=t[p*2].cosv;
        t[p*2].sinv=sina*cosx+cosa*sinx;
        t[p*2].cosv=cosa*cosx-sina*sinx;
        sina=t[p*2+1].sinv,cosa=t[p*2+1].cosv;
        t[p*2+1].sinv=sina*cosx+cosa*sinx;
        t[p*2+1].cosv=cosa*cosx-sina*sinx;
        t[p*2].tag+=t[p].tag;
        t[p*2+1].tag+=t[p].tag;
        t[p].tag=0;
    }
}

void build(int p,int l,int r)
{
    t[p].l=l,t[p].r=r;
    if(l==r)
    {
        t[p].sinv=sin(a[l]),t[p].cosv=cos(a[l]);
        return;
    }
    int mid=(l+r)/2;
    build(p*2,l,mid);
    build(p*2+1,mid+1,r);
    upd(p);
}

void change(int p,int l,int r,int val)
{
    if(l<=t[p].l&&t[p].r<=r)
    {
        double sina=t[p].sinv,cosa=t[p].cosv,sinx=sin(val),cosx=cos(val);
        t[p].sinv=sina*cosx+cosa*sinx;
        t[p].cosv=cosa*cosx-sina*sinx;
        t[p].tag+=val;
        return;
    }
    spread(p);
    int mid=(t[p].l+t[p].r)/2;
    if(l<=mid)
        change(p*2,l,r,val);
    if(mid<r)
        change(p*2+1,l,r,val);
    upd(p);
}

double ask(int p,int l,int r)
{
    if(l<=t[p].l&&t[p].r<=r)return t[p].sinv;
    spread(p);
    int mid=(t[p].l+t[p].r)/2;
    double val=0;
    if(l<=mid)
        val+=ask(p*2,l,r);
    if(mid<r)
        val+=ask(p*2+1,l,r);
    return val;
}

int main()
{
    n=read();

    for(RI i=1;i<=n;i++)
        a[i]=read();

    build(1,1,n);

    m=read();

    while(m--)
    {
        int opt=read(),l=read(),r=read();

        switch(opt)
        {
            case 1:{

                double val; scanf("%lf",&val);
                change(1,l,r,val);

                break;
            }

            case 2:{

                printf("%.1lf\n",ask(1,l,r));

                break;
            }
        }
    }

    return 0;
}

\ [\ texttt {ありがとう} \ \ texttt \ \ \ texttt {見} {用}]

おすすめ

転載: www.cnblogs.com/cjtcalc/p/12324869.html