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);
}
}