求std
查看原帖
求std
578004
02Ljh楼主2022/11/20 19:08

赛时口胡了个做法 不知道怎么维护线段树只拿了30pts

my code

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 100019
#define INF 0x3f3f3f3f
#define int long long
struct lxy
{
    int num;//编号
    int jia;//加和
} ;
int input[MAXN],out[MAXN],ans[MAXN];
struct lxy_
{
    vector<lxy> q;
} maxn[MAXN];
int top=0;//存储q2的个数 编号亦用此
int n;
void init()
{
    top=0;
    memset(input,0,sizeof(input));
    //memset(tree,0,sizeof(tree));
    memset(out,0,sizeof(out));
    memset(ans,INF,sizeof(ans));
    return ;
}
void pu(int pos,int num_,int jia_)
{
    lxy temp;
    temp.jia=jia_;
    temp.num=num_;
    maxn[pos].q.push_back(temp);
    return ;
}
void pr()
{
    cout<<"\nstart print:\n";
    for(int i=1;i<=n;i++)
    {
        for(auto &j:maxn[i].q)
        {
            cout<<j.num<<" ";
        }
        cout<<"\n";
        for(auto &j:maxn[i].q)
        {
            cout<<j.jia<<" ";
        }
        cout<<"\n\n";
    }
}
 main()
{
    freopen("restore3.in","r",stdin);
    freopen("out.ans","w",stdout);
    //system("check.exe restore2.in restore2.ans out.ans");
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TT;
    cin>>TT;
    while(TT--)
    {
        cin>>n;
        init();
        int _;
        cin>>_;
        for(int i=1;i<=n;i++)
        {
            cin>>input[i];
            maxn[i].q.clear();
            pu(i,-1,input[i]);
        }
        while(_--)
        {
            int op,l,r,x;
            cin>>op;
            if(op==1)
            {
                cin>>l>>r>>x;
                for(int i=l;i<=r;i++)
                {
                    for(int j=0;j<maxn[i].q.size();j++)
                    {
                        maxn[i].q[j].jia+=x;
                    }
                }
            }
            else
            {
                cin>>l>>r;
                top++;
                for(int i=l;i<=r;i++)
                {
                    pu(i,top,0);
                }
            }
        }
        for(int i=1;i<=n;i++)
        {
            cin>>out[i];
        }
        //pr();
        int te=-1;
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<maxn[i].q.size();j++)
            {
                te=maxn[i].q[j].num;
                if(te!=-1)
                {
                    //cout<<te<<"\n";
                    ans[te]=min(ans[te],out[i]-maxn[i].q[j].jia);
                }
            }
        }
        for(int i=1;i<=top;i++)
        {
            cout<<ans[i]<<" ";
        }
        cout<<"\n";
    }
    return 0;
}

2022/11/20 19:08
加载中...