QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#425916#6692. Building Companyxorzj#RE 0ms3624kbC++172.7kb2024-05-30 18:55:372024-05-30 18:55:38

Judging History

你现在查看的是最新测评结果

  • [2024-05-30 18:55:38]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3624kb
  • [2024-05-30 18:55:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define ALL(x) (x).begin(), (x).end()
void solve()
{
    int g;
    cin >> g;
    vector<pair<int, int>> arr(g);
    vector<int> lisan;
    lisan.reserve(g);
    for (auto &i : arr)
    {
        cin >> i.first >> i.second;
        lisan.push_back(i.first);
    }
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> task(n); // ren renshu
    vector<vector<pair<int, int>>> get(n);
    for (int i = 0; i < n; i++)
    {
        int m;
        cin >> m;
        for (int j = 0; j < m; j++)
        {
            int a, b;
            cin >> a >> b;
            task[i].push_back({a, b});
            lisan.push_back(a);
        }
        cin >> m;
        for (int j = 0; j < m; j++)
        {
            int a, b;
            cin >> a >> b;
            get[i].push_back({a, b});
            lisan.push_back(a);
        }
    }
    sort(lisan.begin(), lisan.end());
    lisan.erase(unique(lisan.begin(), lisan.end()), lisan.end());
    vector<ll> cnt(lisan.size());
    vector<int> wait(n);
    for (auto [i, j] : arr)
    {
        int d = lower_bound(lisan.begin(), lisan.end(), i) - lisan.begin();
        cnt[d] += j;
    }
    vector<priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>> que(lisan.size());
    int ans = 0;
    vector<int> vis(lisan.size());
    for (int i = 0; i < n; i++)
    {
        for (auto [x, y] : task[i])
        {
            x = lower_bound(lisan.begin(), lisan.end(), x) - lisan.begin();
            if (cnt[x] < y)
            {
                que[x].push({y, i});
                wait[i]++;
            }
        }
        stack<int> sta;
        if (wait[i] == 0)
            sta.push(i);
        vis[i] = 1;
        while (sta.size())
        {
            int d = sta.top();
            ans++;
            sta.pop();
            vis[d] = 0;
            for (auto [x, y] : get[d])
            {
                x = lower_bound(lisan.begin(), lisan.end(), x) - lisan.begin();
                cnt[x] += y;
                while (que[x].size() && que[x].top().first <= cnt[x])
                {
                    wait[que[x].top().second]--;
                    if (wait[que[x].top().second] == 0)
                    {
                        sta.push(que[x].top().second);
                    }
                    que[x].pop();
                }
            }
        }
    }
    cout << ans << endl;
}
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

input:

2 2 1 1 2
5
1 3 1
0
2 1 1 2 1
2 3 2 2 1
3 1 5 2 3 3 4
1 2 5
3 2 1 1 1 3 4
1 1 3
0
1 3 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

3 610031727 590328742 816793299 18485566 654221125 47823436
10
3 610031727 224714165 816793299 491951703 654221125 593479446
1 610031727 538596643
1 610031727 551036304
3 816793299 262985484 610031727 52580932 654221125 424397787
1 654221125 889197190
3 654221125 126924193 610031727 963399336 816793...

output:

10

result:

ok 1 number(s): "10"

Test #3:

score: -100
Runtime Error

input:

10 720543365 814021419 777649737 273919247 339754140 472967790 545693058 298289557 949226024 176807538 267294560 819212220 337794335 504610276 137418995 614590802 632556957 783062334 587607535 115519693
100
5 949226024 327424834 777649737 117746775 137418995 152960310 720543365 423301366 267294560 4...

output:


result: