A Busiest Computing Nodes

在拥有k个计算节点的集群中,每个节点同一时间只能处理一个请求。新请求按照一定的规则分配给节点,如果所有节点都忙碌则请求被丢弃。给定请求的到达时间和处理时间,目标是确定最繁忙的节点,即处理请求最多的节点。问题涉及区间和、区间最小值的维护以及单点修改操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

You have a computing cluster with a total of k computing nodes, labelled from 0 to k−1. The cluster can handle multiple requests at the same time, but each node can process at most one request at the same time.
The rules for request assignment to computing nodes are as follows. Assume the i-th (i starts from 0) request arrives. If all nodes are occupied, the request is discarded (not processed at all). If the (i%k)-th node is available, it will process the request. Otherwise, the request will check the availability of the next node at (i+1)%k, (i+2)%k, and so on, until it finds an idle node.
Given a set of requests with their arrival time and the processing time, your task is to find the busiest computing nodes. A node that belongs to the busiest nodes when no other nodes serve more requests than it does.

区间和维护区间最小值,单点修改

#include<stdio.h>
#include<iostream>
using namespace std;
#define ll long long
ll a[100005*4];
ll query(int k,int l,int r,int L,int R)
{
    if(l<=L&&r>=R)
        return a[k];
    ll ans=1e18;
    int mid=L+R>>1;
    if(l<=mid)
        ans=min(ans,query(k<<1,l,r,L,mid));
    if(r>mid)
        ans=min(ans,query(k<<1|1,l,r,mid+1,R));
    return ans;
}
void modefy(int k,int x,int L,int R,int add)
{
    if(x==L&&x==R)
    {
        a[k]=add;
        return ;
    }
    int mid=L+R>>1;
    if(x<=mid)
        modefy(k<<1,x,L,mid,add);
    else
        modefy(k<<1|1,x,mid+1,R,add);
    a[k]=min(a[k<<1],a[k<<1|1]);
}
ll cnt[100005];
int main()
{
    int k,n;
    cin>>k>>n;
    ll ans=0;
    for(int i=0; i<n; i++)
    {
        ll a,b;
        scanf("%d%d",&a,&b);
        ll l=i%k+1,r=i%k+k;
        if(query(1,l,r,1,2*k)>a)
            continue;
        while(l<=r)
        {
            ll mid=l+r>>1;
            if(query(1,l,mid,1,2*k)<=a)
                r=mid-1;
            else
                l=mid+1;
        }
        modefy(1,l,1,2*k,a+b);
        modefy(1,(l+k-1)%(2*k)+1,1,2*k,a+b);
        ans=max(ans,++cnt[(l-1)%k+1]);
    }
    bool f=0;
    for(int i=1; i<=k; i++)

        if(cnt[i]==ans)
        {
            if(f)
                cout<<' ';
            f=1;
            cout<<(i-1);
        }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Prime me

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值