QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#701785 | #9561. 树数叔术 | comeintocalm | 0 | 0ms | 0kb | C++20 | 1.3kb | 2024-11-02 14:42:50 | 2024-11-02 14:42:51 |
answer
#include <bits/stdc++.h>
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n, m;
scanf("%d%d", &n, &m);
std::vector<int> a(n + 1), cap(n + 1);
std::vector<int> x(m + 1), t(m + 1), next(m + 1);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
cap[i] = a[i];
}
std::map<int,int> last;
std::priority_queue<std::pair<int,int>> q;
for (int i = 1; i <= m; ++i) {
scanf("%d%d", &x[i], &t[i]);
if (last.find(t[i]) != last.end()) {
next[last[t[i]]] = i;
last[t[i]] = i;
} else {
q.push(std::make_pair(-x[i], t[i]));
last[t[i]] = i;
}
}
for (int u = 1; u <= n; ++u) {
if (!last.count(u)) {
q.push(std::make_pair(-1e9 - 9, u));
}
}
long long pos = 0;
for (int i = 1; i <= m; ++i) {
std::vector<int> tmp;
while (pos < x[i] && !q.empty()) {
auto [_, u] = q.top(); q.pop();
if (a[u] > x[i] - pos) {
a[u] -= x[i] - pos;
pos = x[i];
break;
} else {
pos += a[u];
a[u] = 0;
tmp.emplace_back(u);
}
}
if (pos < x[i]) {
break;
}
a[t[i]] = cap[t[i]];
for (auto u : tmp) {
if (next[u] != 0) {
q.push(std::make_pair(-x[next[u]], next[u]));
}
}
}
while (!q.empty()) {
auto [_, u] = q.top(); q.pop();
pos += a[t[u]];
}
printf("%lld\n", pos);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
1 1 624295285
output:
result:
Subtask #2:
score: 0
Memory Limit Exceeded
Test #6:
score: 0
Memory Limit Exceeded
input:
6 4 956647977
output:
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #11:
score: 0
Time Limit Exceeded
input:
48 26 424594716
output:
result:
Subtask #4:
score: 0
Time Limit Exceeded
Test #16:
score: 0
Time Limit Exceeded
input:
150 526250070 197316869