QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#293219 | #4429. Gebyte's Grind | ahsoltan | WA | 3366ms | 134304kb | C++20 | 3.1kb | 2023-12-29 00:55:38 | 2023-12-29 00:55:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 2137
#endif
const ll INF64 = 2e18;
struct segtree {
struct node {
ll h = 0;
ll v, mx = 0;
ll add = 0;
void read() {
char t;
ll x;
cin >> t >> x;
if (t == 'B') {
h = x + 1;
v = 1;
mx = x + 2;
add = -x;
} else if (t == 'K') {
h = x;
v = x;
mx = INF64;
} else {
v = x;
mx = x + 1;
}
}
};
int n;
vector<node> tree;
segtree(int _n = 0) {
n = 1;
while (n < _n) {
n *= 2;
}
tree.resize(2 * n);
}
node join(const node& a, const node& b) {
if (a.h == INF64 || b.h == INF64) {
node res;
res.h = INF64;
return res;
}
node res;
res.h = a.h;
res.add = a.add + b.add;
if (a.v >= b.mx) {
res.v = a.v + b.add;
res.mx = a.mx;
return res;
}
if (a.v >= b.h) {
res.v = b.v;
res.mx = max(a.mx, b.mx - a.add);
return res;
}
if (a.mx != INF64) {
res.h = max(a.mx, b.h - a.add);;
res.v = b.v;
res.mx = max(a.mx, b.mx - a.add);
} else {
res.h = INF64;
}
return res;
}
template<typename F>
void run(int u, int ul, int ur, int l, int r, bool mod, F&& f) {
if (ul >= l && ur <= r) {
f(u, ur - ul + 1);
return;
}
if (ul > r || ur < l) {
return;
}
int mid = (ul + ur) / 2;
run(2 * u, ul, mid, l, r, mod, f);
run(2 * u + 1, mid + 1, ur, l, r, mod, f);
if (mod) {
tree[u] = join(tree[2 * u], tree[2 * u + 1]);
}
}
node get(int l, int r) {
node res;
run(1, 0, n - 1, l, r, false, [&] (int u, int) {
res = join(res, tree[u]);
});
return res;
}
void modify(int i, node x) {
i += n;
tree[i] = x;
for (i /= 2; i > 0; i /= 2) {
tree[i] = join(tree[2 * i], tree[2 * i + 1]);
}
}
int search(int l, int r, ll h0) {
node res;
int ans = 0;
bool ch = false;
run(1, 0, n - 1, l, r, false, [&] (int u, int len) {
if (ch) {
return;
}
node rr = join(res, tree[u]);
if (rr.h <= h0) {
res = rr;
ans += len;
} else {
int v = u;
while (v < n) {
node r2 = join(res, tree[2 * v]);
if (r2.h <= h0) {
res = r2;
ans += len / 2;
v = 2 * v + 1;
} else {
v = 2 * v;
}
len /= 2;
}
ch = true;
}
});
return ans;
}
};
void solve() {
int n, q;
ll h0;
cin >> n >> q >> h0;
segtree t(n);
for (int i = 0; i < n; i++) {
segtree::node x;
x.read();
t.modify(i, x);
}
while (q--) {
char op;
int i;
cin >> op >> i;
i--;
if (op == 'Z') {
segtree::node x;
x.read();
t.modify(i, x);
} else {
int x = t.search(i, n - 1, h0);
cout << (x > 0 ? i + x : -1) << '\n';
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 3366ms
memory: 134304kb
input:
1 2000000 4000000 1000000000000 B 2982992025 B 1226542907 B 2299259203 B 1223702056 B 1407121251 B 340783317 B 1259091208 B 2101980047 B 2611543443 B 2010658889 B 4233714406 B 3112120167 B 2311876255 B 2789960428 B 3008572010 B 1 B 2464951378 B 1364240867 B 2829584762 B 2511437438 B 692948679 B 1113...
output:
833302 238155 1007466 1912727 1483707 996123 913464 595444 1956432 168794 1224759 214012 1606540 541216 578117 1279590 1652446 647870 900696 1010723 1723225 1909185 765245 1770241 994028 135066 146309 423001 379625 188229 561102 1020950 25262 1007466 624537 1150303 892424 856521 175916 1187336 16896...
result:
ok 2911608 lines
Test #2:
score: -100
Wrong Answer
time: 2701ms
memory: 134208kb
input:
1 2000000 4000000 900000000000 B 18921988072 B 1 B 162148155907 C 1000000000000 B 331992393119 K 428836058413 B 440712983778 B 534362851268 B 923013640108 B 472973869469 B 21294011490 B 1 B 1000000000000 B 76485869786 C 1000000000000 C 333159763195 B 1 B 277856669933 B 1 C 445619227450 B 86360111824...
output:
1625020 1618321 511712 1446036 1302385 244605 534722 1807821 1673978 -1 -1 1286986 650766 1419851 -1 -1 510520 -1 1996906 814567 719623 1737532 180266 285086 -1 1455059 11092 1030131 1479157 372584 399911 1897918 1585202 566085 1522965 63081 1721860 673731 1530763 -1 -1 134340 1467445 -1 1410807 -1 ...
result:
wrong answer 527th lines differ - expected: '1546335', found: '1546336'