QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#713431#9528. New Energy Vehicle0x3fffffffWA 97ms69748kbC++232.5kb2024-11-05 19:21:412024-11-05 19:21:41

Judging History

This is the latest submission verdict.

  • [2024-11-05 19:21:41]
  • Judged
  • Verdict: WA
  • Time: 97ms
  • Memory: 69748kb
  • [2024-11-05 19:21:41]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define int long long
using PII = pair<int, int>;


void solve() {
    int n, m;cin >> n >> m;
    vector<int>a(n + 1);
    for (int i = 1;i <= n;i++) {
        cin >> a[i];
    }
    auto b = a;
    priority_queue<PII, vector<PII>, greater<PII>>q;
    vector<int>x(m + 1), t(m + 1), vis(n + 1);
    vector<int>p(n + 1, m + 1);

    for (int i = 1;i <= m;i++) {
        cin >> x[i] >> t[i];
        q.emplace(i, t[i]);
        vis[t[i]] = 1;
        p[t[i]] = i;
    }

    for (int i = 1;i <= n;i++) {
        if (!vis[i])q.emplace(m + 1, i);
    }

    fill(vis.begin(), vis.end(), 0);
    queue<int>que[n + 3];
    for (int i = 1;i <= m;i++) {
        que[t[i]].push(i);
    }
    for (int i = 1;i <= n;i++) {
        if (!vis[i]) {
            que[i].push(m + 1);
        }
        vis[i] = 1;
    }

    auto look = [&]() {
        auto tmp = q;
        while (tmp.size()) {
            auto [xx, y] = tmp.top();
            tmp.pop();
            cerr << xx << " " << y << "\n";
        }
        cerr << "\n";
        for (int i = 1;i <= n;i++) {
            cerr << format("b[{}]={}\n", i, b[i]);
        }
        cerr << "\n";
    };

    LL ans = 0;
    for (int i = 1;i <= m;i++) {
        int tp = -1, pid = 0;
        while (not q.empty() and ans < x[i]) {
            auto [tt, id] = q.top();q.pop();
            if (ans + b[id] < x[i]) {
                ans += b[id];
                b[id] = 0;
            }
            else {
                b[id] = ans + b[id] - x[i];
                ans = x[i];
                if (b[id] == 0)break;
                tp = tt, pid = id;
            }
        }
        if (ans < x[i])break;
        if (tp == -1 or (tp != -1 and pid == t[i])) {
            while (!que[t[i]].empty() and p[t[i]] <= i) {
                p[t[i]] = que[t[i]].front();que[t[i]].pop();
            }
        }
        else {
            q.emplace(tp, pid);
            while (!que[t[i]].empty() and p[t[i]] <= i) {
                p[t[i]] = que[t[i]].front();que[t[i]].pop();
            }
        }
        b[t[i]] = a[t[i]];
        q.emplace(p[t[i]], t[i]);
    }
    while (not q.empty()) {
        ans += b[q.top().second];q.pop();
    }
    cout << ans << "\n";
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    cin >> T;
    while (T--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1

output:

12
9

result:

ok 2 lines

Test #2:

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

input:

6
3 2
2 2 2
6 1
7 1
2 2
3 3
2 1
6 2
2 3
2 2
5 1
7 2
9 1
2 2
3 3
2 1
6 2
1 1
999999999
1000000000 1
1 1
1000000000
1000000000 1

output:

9
11
4
11
999999999
2000000000

result:

ok 6 lines

Test #3:

score: -100
Wrong Answer
time: 97ms
memory: 69748kb

input:

10
230 8042
599 1039 69 1011 1366 824 14117 1523 806 5002 332 55 3769 996 359 1040 255 1135 3454 3609 6358 2509 3695 8785 3890 1304 3394 14611 33 89 2245 508 22 1043 10411 628 1279 714 903 585 7413 5099 845 148 4689 2110 8683 1613 143 3263 2599 110 244 3297 4742 1571 425 1822 15692 572 9397 328 1691...

output:

20982438
39582087
3094287
50717921
18833392
52174036
1045651
61564062
1107079
1065868

result:

wrong answer 1st lines differ - expected: '1543020', found: '20982438'