跳到正文

题解

题解:P9557 [SDCPC2023] Building Company

lifugui666约 3 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年2月14日
篇幅
约 3 分钟
题目
P9557

版本

  1. v1当前
C++
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define PII pair<int, int>
using namespace std;

const int maxn = 1e5 + 10;
int g, n, ans, m[maxn];
vector<PII> arr[maxn];
unordered_map<int, int> mp_int;
unordered_map<int, priority_queue<PII>> mp_pq;

void ac(int id)
{
    ans++;
    for (auto x : arr[id])
    {
        int c = x.first, d = x.second;
        mp_int[c] += d;
        while (mp_pq[c].size())
        {
            int num = -mp_pq[c].top().first;
            int nid = mp_pq[c].top().second;
            if (num > mp_int[c]) break;
            mp_pq[c].pop();
            m[nid]--;
            if (m[nid] == 0) ac(nid);
        }
    }
}

void solve()
{
    cin >> g;
    for (int i = 1; i <= g; i++)
    {
        int t, u;
        cin >> t >> u;
        mp_int[t] = u;
    }

    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int cnt = 0;
        cin >> m[i];
        for (int j = 1; j <= m[i]; j++)
        {
            int a, b;
            cin >> a >> b;
            if (b <= mp_int[a]) cnt++;
            else mp_pq[a].push({-b, i});
        }
        m[i] -= cnt;

        int k;
        cin >> k;
        for (int j = 1; j <= k; j++)
        {
            int c, d;
            cin >> c >> d;
            arr[i].push_back({c, d});
        }

        if (m[i] == 0) ac(i);
    }

    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}
原文