萌新全RE求助
查看原帖
萌新全RE求助
115359
phigy楼主2020/12/19 10:07

样例过了,评测RE

#include <iostream>
#include <cstdio>
#include <cmath>

#define int long long
using namespace std;

int n,m,p;
int a[1000000];
struct tree
{
    double sinn,coss;
    long long lazy;
}t[2000000];

int up(int o)
{
    t[o].sinn=t[o*2].sinn+t[o*2+1].sinn;
    t[o].coss=t[o*2].coss+t[o*2+1].coss;
}


int build(int o,int l,int r)
{
    if(l==r)
    {
        t[o].sinn=sin(a[l]);
        t[o].coss=cos(a[l]);
    }
    else
    {
        int mid=(l+r)/2;
        build(o*2,l,mid);
        build(o*2+1,mid+1,r);
        up(o);
    }
    return 0;
}

int down(int o)
{
    if(t[o].lazy)
    {
        long long z=t[o].lazy;
        double s=t[o*2].sinn,c=t[o*2].coss;
        t[o*2].sinn=s*cos(z)+c*sin(z);
        t[o*2].coss=c*cos(z)-s*sin(z);
        s=t[o*2+1].sinn,c=t[o*2+1].coss;
        t[o*2+1].sinn=s*cos(z)+c*sin(z);
        t[o*2+1].coss=c*cos(z)-s*sin(z);
        t[o*2].lazy+=t[o].lazy;
        t[o*2+1].lazy+=t[o].lazy;
        t[o].lazy=0;
    }
}

int add(int o,int l,int r,int x,int y,int z)
{

    if(x<=l&&r<=y)
    {
        t[o].lazy+=z;
        double s=t[o].sinn,c=t[o].coss;
        t[o].sinn=s*cos(z)+c*sin(z);
        t[o].coss=c*cos(z)-s*sin(z);
        return 0;
    }
    int mid=(l+r)/2;
    down(o);
    if(x<=mid)add(o*2,l,mid,x,y,z);
    if(y>mid)add(o*2+1,mid+1,r,x,y,z);
    up(o);
    return 0;
}

double query(int o,int l,int r,int x,int y)
{
    if(x<=l&&r<=y)return t[o].sinn;
    down(o);
    double ans=0;
    int mid=(l+r)/2;
    if(x<=mid)ans+=query(o*2,l,mid,x,y);
    if(y>mid)ans+=query(o*2+1,mid+1,r,x,y);
    return ans;
}

signed main()
{
    int i,j,k;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    build(1,1,n);
    cin>>m;
    for(i=1;i<=m;i++)
    {
        int od,x,y,z;
        cin>>od>>x>>y;
        if(x>y)swap(x,y);
        if(od==1)
        {
            cin>>z;
            add(1,1,n,x,y,z);
        }
        if(od==2)
        {
            double ans1=query(1,1,n,x,y);
            printf("%.1lf\n",ans1);
        }
    }
    return 0;
}

2020/12/19 10:07
加载中...