QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#692130 | #9528. New Energy Vehicle | WA_automaton | WA | 68ms | 11444kb | C++20 | 3.3kb | 2024-10-31 13:53:06 | 2024-10-31 13:53:07 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
void debug() {std::cerr << "\n";}
template<class T, class... OtherArgs>
void debug(T &&var, OtherArgs &&... args) {
std::cerr << std::forward<T>(var) << " ";
debug(std::forward<OtherArgs>(args)...);
}
#define SZ(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
using i64 = long long;
using u64 = unsigned long long;
using LD = long double;
using PII = pair<int, int>;
constexpr int N = 200010;
constexpr int P = 1e9 + 7;
struct info {
int sum;
};
info operator + (const info &a, const info &b) {
info c;
c.sum = a.sum + b.sum;
return c;
}
struct tag {
int t;
};
struct Node {
info v;
tag t;
} tr[N << 2];
void pushup(int u) {
tr[u].v = tr[u << 1].v + tr[u << 1 | 1].v;
}
void settag(int u, int l, int r, tag t) {
tr[u].v.sum += (r - l + 1) * t.t;
tr[u].t.t += t.t;
}
void pushdown(int u, int l, int r) {
if (tr[u].t.t) {
int m = l + r >> 1;
settag(u << 1, l, m, tr[u].t);
settag(u << 1 | 1, m + 1, r, tr[u].t);
tr[u].t = {0};
}
}
void build(int u, int l, int r) {
tr[u].t = {0};
if (l == r) return tr[u].v = {0}, void();
int m = l + r >> 1;
build(u << 1, l, m), build(u << 1 | 1, m + 1, r);
pushup(u);
}
void modify(int u, int l, int r, int x, int y, tag v) {
if (x <= l && r <= y) return settag(u, l, r, v);
int m = l + r >> 1;
pushdown(u, l, r);
if (x <= m) modify(u << 1, l, m, x, y, v);
if (y > m) modify(u << 1 | 1, m + 1, r, x, y, v);
pushup(u);
}
info query(int u, int l, int r, int x, int y) {
if (x <= l && r <= y) return tr[u].v;
int m = l + r >> 1;
pushdown(u, l, r);
if (x > m) return query(u << 1 | 1, m + 1, r, x, y);
if (y <= m) return query(u << 1, l, m, x, y);
return query(u << 1, l, m, x, y) + query(u << 1 | 1, m + 1, r, x, y);
}
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n);
int tot = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
tot += a[i];
}
vector<PII> xt(m);
for (int i = 0; i < m; i++) {
auto &[x, t] = xt[i];
cin >> x >> t;
t--;
}
int ans = 0, lst = 0, add = 0;
build(1, 0, n - 1);
for (int i = 0; i < m; i++) {
auto &[x, t] = xt[i];
if (tot < x - lst) {
ans = lst + tot;
tot = 0;
break;
}
modify(1, 0, n - 1, 0, n - 1, {x - lst});
// add += x - lst;
int add = query(1, 0, n - 1, t, t).sum;
tot += min(add, a[t]) - (x - lst);
modify(1, 0, n - 1, 0, n - 1, {-min(add, a[t])});
add = query(1, 0, n - 1, t, t).sum;
modify(1, 0, n - 1, t, t, {-add});
// add -= min(add, a[t]);
// debug("?", tot, query(1, 0, n - 1, t, t).sum);
lst = ans = x;
}
// debug("?", ans, tot);
ans += tot;
cout << ans << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(20);
int _ = 1;
cin >> _;
while (_--) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
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: 3832kb
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: 68ms
memory: 11444kb
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:
1543020 1577881 1504029 1527381 1547404 1564631 1041055 1548178 1114609 1072216
result:
wrong answer 2nd lines differ - expected: '1578939', found: '1577881'