QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#688853#9528. New Energy Vehiclerxzfn639RE 0ms3552kbC++231.4kb2024-10-30 13:57:242024-10-30 13:57:24

Judging History

This is the latest submission verdict.

  • [2024-10-30 13:57:24]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 3552kb
  • [2024-10-30 13:57:24]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const i64 P = 998244353;
void solve() {
    int n, m;
    cin >> n >> m;
    vector<i64> a(n + 1), b(n + 1), nxt(n + 1, m + 1), lst(n + 1, m + 1), x(m + 1), t(m + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }
    for (int i = 1; i <= m; i++) cin >> x[i] >> t[i];
    for (int i = m; i > 0; i--) {
        nxt[i] = lst[t[i]];
        lst[t[i]] = i;
    }
    set<pair<int, int>> st;
    for (int i = 1; i <= n; i++) {
        st.insert({lst[i], i});
    }
    i64 pos = 0;
    for (int i = 1; i <= m; i++) {
        while (pos < x[i] && st.size()) {
            auto tmp = *st.begin();
            i64 d = min(x[i] - pos, a[tmp.second]);
            pos += d;
            a[tmp.second] -= d;
            if (a[tmp.second] == 0) {
                st.erase(tmp);
            }
        }
        while (st.size() && st.begin()->first <= i) {
            st.erase(st.begin());
        }
        if (pos == x[i]) {
            a[t[i]] = b[t[i]];
            st.insert({nxt[i], t[i]});
        }
    }
    for (int i = 1; i <= n; i++) pos += a[i];
    cout << pos << '\n';
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
    int t = 1; 
    cin >> t;
    while(t--) solve();
    return 0;
}
/*
1
2 2
3 3
2 1
6 2
*/

詳細信息

Test #1:

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

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
Runtime Error

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:


result: