QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#684904 | #9528. New Energy Vehicle | lonelywolf | WA | 0ms | 3548kb | C++20 | 1.8kb | 2024-10-28 16:28:41 | 2024-10-28 16:28:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
constexpr int inf = 1e18;
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> x(m + 1), t(m + 1);
vector<vector<int>> l(n + 1);
for (int i = 1; i <= m; i++) {
cin >> x[i] >> t[i];
l[t[i]].push_back(x[i]);
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
for (int i = 1; i <= n; i++) {
if (l[i].size()) {
q.push({l[i][0], i});
} else {
q.push({inf, i});
}
}
auto now = a;
int ans = 0;
for (int i = 1; i <= m; i++) {
int d = x[i] - x[i - 1];
while (q.size() && q.top().first <= x[i - 1]) {
q.pop();
}
while (q.size() && d > 0) {
auto [tx, id] = q.top();
// cerr << tx << " " << id << "\n";
if (now[id] > d) {
ans += d;
now[id] -= d;
d = 0;
} else {
ans += now[id];
d -= now[id];
now[id] = 0;
q.pop();
int lo = -1, hi = l[id].size();
while (lo + 1 != hi) {
int mid = (lo + hi) / 2;
if (l[id][mid] > tx) {
hi = mid;
} else {
lo = mid;
}
}
if (hi != l[id].size()) {
q.push({l[id][hi], id});
}
}
}
if (d == 0) {
now[t[i]] = a[t[i]];
int lo = -1, hi = l[t[i]].size();
while (lo + 1 != hi) {
int mid = (lo + hi) / 2;
if (l[t[i]][mid] > x[i]) {
hi = mid;
} else {
lo = mid;
}
}
if (hi != l[i].size()) {
q.push({l[t[i]][hi], t[i]});
}
} else {
break;
}
}
for (int i = 1; i <= n; i++) {
ans += now[i];
}
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
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: 3532kb
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 8 4 8 999999999 2000000000
result:
wrong answer 2nd lines differ - expected: '11', found: '8'