1 solutions

  • 0
    @ 2025-4-29 11:14:57

    (n+m)log(n+m)(n+m)log(n+m)

    使用优先队列进行处理,其它增加,等价于最大值减少,我们储存相对差值.

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    int main()
    {
        priority_queue<LL> heap;
        LL n,m,q,u,v,t;
        cin>>n>>m>>q>>u>>v>>t;
        for(int i=1;i<=n;i++) //储存n个元素
        {
            LL x;
            cin>>x;
            heap.push(x);
        }
        LL delta=0;
        for(int i=1;i<=m;i++)
        {
            LL x=heap.top()+delta; //找到最大值
            if(i%t==0)
            {
                cout<<x<<" ";
            }
            heap.pop();
            LL left=x*u/v; //计算左边的长度
            LL right=x-left; //计算右边的长度
            heap.push(left-delta-q); //储存到优先队列之中(相对值)
            heap.push(right-delta-q);
            delta+=q; //下一个的偏移量
        }
        cout<<endl;
        for(int i=1;i<=n+m;i++)
        {
            LL x=heap.top()+delta;
            heap.pop();
            if(i%t==0)
            {
                cout<<x<<" ";
            }
        }
        return 0;
    }
    

    O(m+nlogn)O(m+nlogn)

    将所有序列从大到小排序,切割以后的蚯蚓一定也是从大到小的,这样我们就可以做一个三路归并.

    #include<bits/stdc++.h>
    using namespace std;
    const int N=100010,M=7000010;
    int n,m,inc,u,v,t;
    int q[3][M],hh[3],tt[3];
    int delta;
    int get_max()
    {
        int x=-2e9;
        for(int i=0;i<3;i++) //找到最大值
        {
            if(hh[i]<tt[i])
            {
                x=max(x,q[i][hh[i]]);
            }
        }
        for(int i=0;i<3;i++) //找到需要切割的蚯蚓
        {
            if(hh[i]<tt[i]&&x==q[i][hh[i]])
            {
                hh[i]++;
                break;
            }
        }
        return x;
    }
    int main()
    {
        cin>>n>>m>>inc>>u>>v>>t;
        for(int i=1;i<=n;i++)
        {
            cin>>q[0][tt[0]++];
        }
        sort(q[0],q[0]+tt[0],greater<int>());//从大到小排序
        for(int i=1;i<=m;i++)
        {
            int x=get_max()+delta;
            if(i%t==0) cout<<x<<" "; 
            int left=x*1ll*u/v; //计算左边
            int right=x-left;   //计算右边
            q[1][tt[1]++]=left-delta-inc;   //存相对差值
            q[2][tt[2]++]=right-delta-inc;  //存相对差值
            delta+=inc; //增加
        }
        cout<<endl;
        for(int i=1;i<=n+m;i++)
        {
            int x=get_max()+delta;
            if(i%t==0) cout<<x<<" ";
        }
        return 0;
    }
    
    • 1

    Information

    ID
    1122
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    # Submissions
    2
    Accepted
    1
    Uploaded By