QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#98711#4429. Gebyte's GrindUnique_HanpiRE 0ms0kbC++142.8kb2023-04-19 20:59:242023-04-19 20:59:28

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-19 20:59:28]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-04-19 20:59:24]
  • 提交

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 = 1e6+5;
const int B = 1000;
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: 0
Runtime Error

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:


result: