QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#317152#6692. Building CompanysqzTL 9ms47984kbC++143.6kb2024-01-28 16:43:492024-01-28 16:43:50

Judging History

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

  • [2024-01-28 16:43:50]
  • 评测
  • 测评结果:TL
  • 用时:9ms
  • 内存:47984kb
  • [2024-01-28 16:43:49]
  • 提交

answer

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>

#include<queue>
using namespace std;
const int N = 200000;

int t[N + 5], u[N + 5], m[N + 5], k[N + 5];
vector<long long> a[N + 5], b[N + 5], c[N + 5], d[N + 5];
long long cnt[3 * N + 5];
int limit[N + 5];
int tmp[3 * N + 5];
queue<int> Q;
priority_queue<pair<long long, int> > X[3 * N + 5];

int main()
{
    int g, num = 0;
    scanf("%d", &g);
    for (int i = 1; i <= g; i++) {
        scanf("%d %d", &t[i], &u[i]);
        tmp[++num] = t[i];
    }
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &m[i]);
        a[i].push_back(0);
        b[i].push_back(0);
        c[i].push_back(0);
        d[i].push_back(0);
        for (int j = 1; j <= m[i]; j++) {
            int aa, bb;
            scanf("%d %d", &aa, &bb);
            a[i].push_back(aa);
            b[i].push_back(bb);
            tmp[++num] = aa;
        }
        scanf("%d", &k[i]);
        for (int j = 1; j <= k[i]; j++) {
            int cc, dd;
            scanf("%d %d", &cc, &dd);
            c[i].push_back(cc);
            d[i].push_back(dd);
            tmp[++num] = cc;
        }
    }
    
    sort(tmp + 1, tmp + num + 1);
    num = unique(tmp + 1, tmp + num + 1) - (tmp + 1);
    // printf("%d\n", num);
    for (int i = 1; i <= n; i++)
    {
        limit[i] = m[i];
        for (int j = 1; j <= m[i]; j++) {
            
        // printf("bbb%d %d %d\n", i, a[i][j], lower_bound(tmp + 1, tmp + num + 1, a[i][j]) - tmp);
            a[i][j] = lower_bound(tmp + 1, tmp + num + 1, a[i][j]) - tmp, X[a[i][j]].push(make_pair(-b[i][j], i));
        }
        for (int j = 1; j <= k[i]; j++) {
        // printf("ccc%d %d %d\n", i, c[i][j], lower_bound(tmp + 1, tmp + num + 1, c[i][j]) - tmp);
            c[i][j] = lower_bound(tmp + 1, tmp + num + 1, c[i][j]) - tmp;
        }
        // printf("finish %d\n", i);
    }
    for (int i = 1; i <= g; i++) 
    {
        // printf("aaa%d %d %d\n", i, t[i], lower_bound(tmp + 1, tmp + num + 1, t[i]) - tmp);
        t[i] = lower_bound(tmp + 1, tmp + num + 1, t[i]) - tmp;
        cnt[t[i]] += u[i];
        while (-X[t[i]].top().first <= cnt[t[i]])
        {
            limit[X[t[i]].top().second]--;
            X[t[i]].pop();
        }
    }
    // printf("after\n");
    
    int ans = 0;
    for (int i = 1; i <= n; i++) 
        if (limit[i] <= 0) ans++, Q.push(i);
    while (!Q.empty())
    {
        int i = Q.front();
        // printf("pop %d\n", i);
        Q.pop();
        for (int j = 1; j <= k[i]; j++)
        {
            cnt[c[i][j]] += d[i][j];
            // printf("ffff%d %d %d %d \n", j, c[i][j], cnt[c[i][j]], X[c[i][j]].size());
            while (!X[c[i][j]].empty() && -X[c[i][j]].top().first <= cnt[c[i][j]])
            {
                int nxt = X[c[i][j]].top().second;
                // if (limit[nxt] >= 0) {
                    // printf("unlimit %d %d\n", nxt, limit[nxt]);
                    // printf("%d %d %d\n", X[c[i][j]].top().first, X[c[i][j]].top().second, X[c[i][j]].size());
                // }
                limit[nxt]--;
                if (limit[nxt] <= 0) {
                    ans++;
                    Q.push(nxt);
                }
                X[c[i][j]].pop();
                // if (limit[nxt] >= 0) {
                //     printf("%d %d %d\n", X[c[i][j]].top().first, X[c[i][j]].top().second, X[c[i][j]].size());
                // }
            }
        }
    }
    
    printf("%d\n", ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 46336kb

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: 9ms
memory: 47984kb

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: 0
Accepted
time: 0ms
memory: 47756kb

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:

100

result:

ok 1 number(s): "100"

Test #4:

score: 0
Accepted
time: 7ms
memory: 46396kb

input:

33 598906111 952747266 214206082 308472115 773699301 71970369 334282917 266176016 861160505 745480638 397625705 130382274 75028923 106125916 739923352 754152044 493886549 212094717 352869179 727757279 697376464 343501623 916521518 80952344 90959088 722016125 286878647 329186592 770901193 30277256 92...

output:

100

result:

ok 1 number(s): "100"

Test #5:

score: -100
Time Limit Exceeded

input:

380 562284409 583959039 705240193 694592025 91058796 151967354 775570098 571811699 457579493 117213529 684664737 33837962 60865228 186423701 316573783 868301583 744570505 934432338 790259030 364551324 145817136 961903964 737096543 759008968 865899868 681823261 273067044 247683791 186025557 756452454...

output:


result: