QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#713446 | #9528. New Energy Vehicle | 0x3fffffff | WA | 84ms | 69744kb | C++23 | 2.5kb | 2024-11-05 19:25:23 | 2024-11-05 19:25:24 |
Judging History
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];
}
auto b = a;
priority_queue<PII, vector<PII>, greater<PII>>q;
vector<int>x(m + 1), t(m + 1), vis(n + 1);
vector<int>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;
p[t[i]] = i;
}
for (int i = 1;i <= n;i++) {
if (!vis[i])q.emplace(m + 1, i);
}
fill(vis.begin(), vis.end(), 0);
queue<int>que[n + 3];
for (int i = 1;i <= m;i++) {
que[t[i]].push(i);
}
for (int i = 1;i <= n;i++) {
if (!vis[i]) {
que[i].push(m + 1);
}
vis[i] = 1;
}
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++) {
int tp = -1, pid = 0;
while (not q.empty() and ans < x[i]) {
auto [tt, id] = q.top();q.pop();
if (ans + b[id] < x[i]) {
ans += b[id];
b[id] = 0;
}
else {
b[id] = ans + b[id] - x[i];
ans = x[i];
if (b[id] == 0)break;
tp = tt, pid = id;
}
}
if (ans < x[i])break;
if (tp == -1 or (tp != -1 and pid == t[i])) {
while (!que[t[i]].empty() and p[t[i]] <= i) {
p[t[i]] = que[t[i]].front();que[t[i]].pop();
}
}
else {
q.emplace(tp, pid);
while (!que[t[i]].empty() and p[t[i]] <= i) {
p[t[i]] = que[t[i]].front();que[t[i]].pop();
}
}
b[t[i]] = a[t[i]];
q.emplace(p[t[i]], t[i]);
}
for (int i = 1;i <= n;i++) {
ans += b[i];
}
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: 3568kb
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: 3868kb
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: 84ms
memory: 69744kb
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:
1500941 1558950 1324341 1518804 1531226 1552335 1045651 1536048 1107079 1065868
result:
wrong answer 1st lines differ - expected: '1543020', found: '1500941'