QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#712636#9528. New Energy Vehicle0x3fffffffWA 0ms3552kbC++232.3kb2024-11-05 16:27:522024-11-05 16:27:53

Judging History

This is the latest submission verdict.

  • [2024-11-05 16:27:53]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3552kb
  • [2024-11-05 16:27:52]
  • 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(n + 1, 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(m + 1, 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;
    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) {
            q.emplace(nxt[id], id);
        }
        ans = x[i];
        // cerr << i << "now\n";

        if (id != t[i])
            q.emplace(nxt[i], t[i]);
        b[t[i]] = a[t[i]];
        // look();
    }
    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;
}

詳細信息

Test #1:

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

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: -100
Wrong Answer
time: 0ms
memory: 3552kb

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
1000000000

result:

wrong answer 6th lines differ - expected: '2000000000', found: '1000000000'