https://codeforces.com/gym/104417/problem/B

这篇文章描述了一个在Codeforces竞赛中的问题,涉及使用C++编程语言实现一个动态优先队列,用于解决与整数数组和插入操作相关的计数问题。

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

Problem - B - Codeforces

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
#define P pair<ll,ll>
#define PP map<ll,priority_queue<P,vector<P>,greater<P> > >
int A[N][2];
PP ma;
vector<P> jl[N];
map<ll,ll> qa;
int num[N];
queue<int> qqa;
void insert(int x,int y)
{
    ll &u = qa[x];
    u+=y;
    priority_queue<P,vector<P>,greater<P> > &temp = ma[x];
    while(!temp.empty())
    {
        P x = temp.top();
        if(x.first<=u)
        {
            temp.pop();
            num[x.second]--;
            if(num[x.second]==0) qqa.push(x.second);
        }else{
            break;
        }
    }
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int g;
    cin>>g;
    for(int i=1;i<=g;i++)
    {
        cin>>A[i][0]>>A[i][1];
    }
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>num[i];
        for(int j=1;j<=num[i];j++)
        {
            ll a,b;
            cin>>a>>b;
            ma[a].push({b,i});
        }
        int k;
        cin>>k;
        for(int j=1;j<=k;j++)
        {
            ll a,b;
            cin>>a>>b;
            jl[i].push_back({a,b});
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(num[i]==0)
            qqa.push(i);
    }
    for(int i=1;i<=g;i++) insert(A[i][0],A[i][1]);
    int cnt=0;
    while(!qqa.empty())
    {
        int x = qqa.front();
        qqa.pop();
        cnt++;
        for(auto j:jl[x])
        {
            insert(j.first,j.second);
        }
    }
    cout<<cnt<<endl;
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值