QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#98722 | #4429. Gebyte's Grind | Unique_Hanpi | TL | 4123ms | 45152kb | C++14 | 2.8kb | 2023-04-19 21:08:28 | 2023-04-19 21:08:31 |
Judging History
answer
#include <bits/stdc++.h>
#define lowbit(x) (x & -x)
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define pos(x) (x / B + 1)
using namespace std;
typedef long long ll;
const int N = 2e6+5;
const int B = 300;
const ll INF = 2e18;
inline ll read() {
ll x = 0; char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x;
}
int n, q;
int top[N / B + 2], ba[N / B + 2][B + 2], bl[N / B + 2], br[N / B + 2];
char t[N];
bool ext2[N / B + 2];
ll bb[N / B + 2][B + 2], bd[N / B + 2], bmx[N / B + 2], bcur[N / B + 2];
ll H0, a[N];
inline void rebuild(int id) {
top[id] = 0;
ll d = 0, mx = 1;
ext2[id] = 0;
for (int i = bl[id]; i <= br[id]; i++) {
if (t[i] == 'B') {
d += a[i];
if (d >= mx) {
mx = d + 1;
top[id]++;
bb[id][top[id]] = d;
ba[id][top[id]] = i;
}
} else if (t[i] == 'C') {
mx = max(mx, d + a[i]);
} else {
ext2[id] = 1;
if (d + a[i] > mx) {
top[id]++;
bb[id][top[id]] = d + a[i] - 1;
ba[id][top[id]] = i;
}
ll cur = a[i];
for (int j = i + 1; j <= br[id]; j++) {
if (t[j] == 'B') {
cur -= a[j];
if (cur <= 0) {
top[id]++;
bb[id][top[id]] = INF;
ba[id][top[id]] = j;
break;
}
} else if (t[j] == 'K') {
if (cur < a[j]) {
top[id]++;
bb[id][top[id]] = INF;
ba[id][top[id]] = j;
break;
}
cur = a[j];
} else {
cur = max(cur, a[j]);
}
}
bcur[id] = cur;
return;
}
}
bd[id] = d, bmx[id] = mx;
}
void solve() {
n = read(), q = read(), H0 = read();
for (int i = 1; i <= n; i++) scanf(" %c", &t[i]), a[i] = read();
for (int i = 1; i <= pos(n); i++) {
bl[i] = max(1, i * B - B), br[i] = min(i * B - 1, n);
rebuild(i);
}
while (q--) {
char op; int x;
scanf(" %c", &op); x = read();
if (op == 'Z') {
scanf(" %c", &t[x]), a[x] = read();
rebuild(pos(x));
} else {
ll cur = H0; int tmp = x;
while (x <= br[pos(tmp)]) {
if (t[x] == 'B') {
cur -= a[x];
if (cur <= 0) break;
} else if (t[x] == 'K') {
if (cur < a[x]) break;
cur = a[x];
} else {
cur = max(cur, a[x]);
}
x++;
}
if (x <= n && x > br[pos(tmp)])
for (int i = pos(x); i <= pos(n); i++) {
if (!top[i] || cur > bb[i][top[i]]) {
x = br[i] + 1;
if (ext2[i]) cur = bcur[i];
else cur = max(cur - bd[i], bmx[i] - bd[i]);
} else {
int p = lower_bound(bb[i] + 1, bb[i] + top[i] + 1, cur) - bb[i];
x = ba[i][p];
break;
}
}
printf("%d\n", tmp == x ? -1 : x - 1);
}
}
}
int main() {
int T;
scanf("%d", &T);
while (T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 4123ms
memory: 44988kb
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: 0
Accepted
time: 1472ms
memory: 45152kb
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:
ok 1999947 lines
Test #3:
score: -100
Time Limit Exceeded
input:
1 2000000 4000000 1000000000000 B 17342013 B 14555766 B 26630469 B 66103720 B 62383790 B 17433493 B 66256092 B 74496332 B 66470344 B 17971159 B 46755192 B 33871545 B 47843886 B 17737257 B 91180218 B 2450298 B 31650513 B 2066148 B 82311128 B 56600828 B 12144701 B 83637831 B 73789298 B 108092 B 684688...
output:
6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 6137 ...