QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#693676#9528. New Energy Vehiclecrychic#WA 1ms3552kbC++172.4kb2024-10-31 16:33:162024-10-31 16:33:19

Judging History

This is the latest submission verdict.

  • [2024-10-31 16:33:19]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3552kb
  • [2024-10-31 16:33:16]
  • Submitted

answer

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;



void solve() {
    int n, m;
    cin >> n >> m;
    std::vector<int> a(n + 1);
    vector<pii> b(n + m + n + 1);
    for(int i = 1; i <= n; i ++ ) {
        cin >> a[i];
    }
    set<int> heap;
    vector<int> st(n + 1);
    vector<int> vis(n + 1);
    vector<int> lst(n + 1), nxt(n + 1);
    for(int i = 1; i <= m; i ++ ) {
        cin >> b[i].first >> b[i].second;
        nxt[lst[b[i].second]] = i;
        if(!st[b[i].second]) {
            st[b[i].second] = 1;
            heap.insert(i);
        }
    }
    int offest = m;
    for(int i = 1; i <= n; i ++ ) {
        if(!st[i]) {
            heap.insert( ++ offest);
            b[offest].second = i;
        }
    }
    vector<int> remain(n + 1);
    for(int i = 1; i <= n; i ++ ) {
        remain[i] = a[i];
    }
    ll ans = 0;
    for(int i = 1; i <= m; i ++ ) {
        int x = b[i].first - b[i - 1].first;
        while(heap.size()) {
            int idx = *heap.begin();
            int u = b[idx].second;
            // cerr << idx << '\n';
            if(remain[u] > x) {
                ans += x;
                remain[u] -= x;
                x = 0;
                break;
            } else {
                x -= remain[u];
                ans += remain[u];
                remain[u] = 0;
                heap.erase(idx);
            }
        }
        // cerr << "!" << '\n';
        if(x) break;
        else {
            if(heap.find(i) != heap.end()) {
                heap.erase(i);
            }
            // cerr << "?" << nxt[i] << '\n';
            if(nxt[i]) {
                heap.insert(nxt[i]);
            } else {
                heap.insert( ++ offest);
                b[offest].second = b[i].second; 
            }
            remain[b[i].second] = a[b[i].second];
        }
    }
    while(heap.size()) {
        int idx = *heap.begin();
        // cerr << idx << '\n';
        int u = b[idx].second;
        // cerr << u << '\n';
        // cout << remain[u] << '\n';
        ans += remain[u];
        heap.erase(idx);
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    
    int t = 1;
    cin >> t;
    while(t -- ) {
        solve();
    }
    
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3524kb

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:

11
11
4
11
999999999
2000000000

result:

wrong answer 1st lines differ - expected: '9', found: '11'