QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#713232#9528. New Energy Vehicle0x3fffffffWA 83ms11704kbC++232.5kb2024-11-05 18:42:112024-11-05 18:42:11

Judging History

This is the latest submission verdict.

  • [2024-11-05 18:42:11]
  • Judged
  • Verdict: WA
  • Time: 83ms
  • Memory: 11704kb
  • [2024-11-05 18:42:11]
  • 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];
    }
    priority_queue<PII, vector<PII>, greater<PII>>q;
    vector<int>x(m + 1), t(m + 1), vis(n + 1);
    vector<int>nxt(m + 4, m + 1), 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;
    }
    auto b = a;
    // for (int i = 1;i <= m;i++) {
    //     cout << nxt[t[i]] << " ";
    // }
    // cout << "\n";return;
    for (int i = m;i >= 1;i--) {
        nxt[i] = p[t[i]];
        p[t[i]] = i;
    }
    // for (int i = 1;i <= m;i++) {
    //     cout << nxt[i] << " ";
    // }
    // cout << "\n";return;

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

    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;
    queue<PII>que;
    for (int i = 1;i <= m;i++) {
        if (q.empty())break;
        while (not q.empty() and ans + b[q.top().second] < x[i]) {
            // cerr << "ok\n";
            ans += b[q.top().second];
            b[q.top().second] = 0;
            q.pop();
        }

        if (q.empty())break;
        auto [tt, id] = q.top();q.pop();
        b[id] = ans + b[id] - x[i];
        if (b[id] != 0 and id != t[i]) {
            q.emplace(id, id);
        }
        ans = x[i];
        // cerr << i << "now\n";
        // while (not que.empty()) {
        //     if (b[que.front().second]) {
        //         q.push(que.front());
        //     }
        //     que.pop();
        // }
        // look();
        if (nxt[i] != m + 1) {
            q.emplace(nxt[i], t[i]);
        }
        else {
            q.emplace(1e9, t[i]);
        }
        b[t[i]] = a[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: 3532kb

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: 3600kb

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: 83ms
memory: 11704kb

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:

35129630
73105341
2708868
91363873
29902597
94527559
1009494
115871259
1073530
1034416

result:

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