QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#785548#9786. Magical Bagsjaker#WA 1ms5828kbC++173.9kb2024-11-26 18:13:082024-11-26 18:13:09

Judging History

This is the latest submission verdict.

  • [2024-11-26 18:13:09]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5828kb
  • [2024-11-26 18:13:08]
  • Submitted

answer

#pragma GCC optimize("Ofast")
#define DEBUG 0
#include <queue>
#include <climits>
#include <cassert>
#include <iostream>
#include <vector>
template <class T> using Arr = std::vector<T>;
#define LS (p << 1)
#define RS (LS | 1)
#define MID ((l + r) >> 1)
typedef long long LL;

const int MAXN = 200002;
int n, q;
char s[MAXN];
LL tag[MAXN << 2], val[MAXN << 2];

inline LL lmerge(LL u, LL v) { return u == -1 || v == -1 ? -1 : u > LLONG_MAX - v ? -1 : u + v; }
inline LL lmul(LL u, LL x) {
#if DEBUG
	// assert(u != -1 && x != -1);
#endif
	if (u == -1 || x == -1 || __int128(u) * x > LLONG_MAX)
		return -1;
	else
		return u * x;
}
inline bool lless(LL u, LL x) {
	if (u == -1)
		return false;
	return u < x;
}

inline void push(int p, int l, int r) {
	if (tag[p] != 1 && l != r) {
#if DEBUG
		printf("(push %d %d %d %lld)\n", p, l, r, tag[p]);
#endif
		if (tag[p] == -1) {
			val[LS] = val[RS] = -1;
		} else {
			val[LS] = lmul(val[LS], tag[p]);
			val[RS] = lmul(val[RS], tag[p]);
		}
		// tag[LS] = lmul(tag[LS], tag[p]);
		// tag[RS] = lmul(tag[RS], tag[p]);
		tag[LS] *= tag[p];
		tag[RS] *= tag[p];
		tag[p] = 1;
	}
}

inline void upd(int p, int l, int r) {
	if (l == r) return;
	val[p] = lmerge(val[LS], val[RS]);
}

void build(int p, int l, int r) {
	tag[p] = 1;
	if (l == r) {
		val[p] = 1;
		return;
	}
	build(LS, l, MID);
	build(RS, MID + 1, r);
	upd(p, l, r);
}

LL ask(int p, int l, int r, int tp) {
	if (tp < l || tp > r)
		return 0;
	if (l == r)
		return val[p];
	push(p, l, r);
	return ask(LS, l, MID, tp) | ask(RS, MID + 1, r, tp);
	// return lmerge(ask(LS, l, MID, tp), ask(RS, MID + 1, r, tp));
}

LL ask_int(int p, int l, int r, int lp, int rp) {
	if (r < lp || l > rp)
		return 0;
	if (l == r)
		return val[p];
	push(p, l, r);
	return lmerge(ask_int(LS, l, MID, lp, rp), ask_int(RS, MID + 1, r, lp, rp));
}

void multiply(int p, int l, int r, int lp, int rp, int v) {
#if DEBUG
	if (p == 1) {
		printf("(multi %d %d %d)\n", lp, rp, v);
	}
#endif
	if (rp < l || lp > r)
		return;
	push(p, l, r);
	if (lp <= l && r <= rp) {
		// tag[p] = lmul(tag[p], v);
		tag[p] *= tag[v];
		val[p] = lmul(val[p], v);
#if DEBUG
		printf("== (%d %d)\n", l, r);
#endif
		return;
	}
	multiply(LS, l, MID, lp, rp, v);
	multiply(RS, MID + 1, r, lp, rp, v);
	upd(p, l, r);
}

void sp_add(int p, int l, int r, int tp, LL v) {
#if DEBUG
	if (p == 1) {
		printf("(sp_add %d %lld)\n", tp, v);
	}
#endif
	if (r < tp || l > tp)
		return;
	if (l == r)
		return val[p] = lmerge(val[p], v), void();
	push(p, l, r);
	sp_add(LS, l, MID, tp, v);
	sp_add(RS, MID + 1, r, tp, v);
	upd(p, l, r);
}

int bins(int p, int l, int r, LL v) {
	if (l == r)
		return l;
	push(p, l, r);
	if (lless(val[LS], v))
		return bins(RS, MID + 1, r, v - val[LS]);
	else
		return bins(LS, l, MID, v);
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin >> n >> q;
	std::cin >> (s + 1);
	build(1, 1, n);

	for (int i = 1; i <= q; ++i) {
		int op;
		std::cin >> op;
		if (op == 1) {
			LL l, r;
			std::cin >> l >> r;
			int lp = bins(1, 1, n, l);
			int rp = bins(1, 1, n, r);
			LL lsz = ask_int(1, 1, n, 1, lp);
			LL rsz = ask_int(1, 1, n, 1, rp - 1);
			if (lp + 1 < rp)
				multiply(1, 1, n, lp + 1, rp - 1, 2);
#if DEBUG
			printf("$ ");
			for (int j = 1; j <= n; ++j)
				printf("%lld ", ask(1, 1, n, j));
			puts("");
			printf("(lp %d) (rp %d)\n", lp, rp);
			printf("(lsz %lld) (rsz %lld)\n", lsz, rsz);
#endif
			if (lsz == -1)
				continue;
			assert(lsz != -1 && lsz >= l);
			assert(rsz != -1 && rsz < r);
			if (lp == rp)
				sp_add(1, 1, n, lp, r - l + 1);
			else {
				sp_add(1, 1, n, lp, lsz - l + 1);
				sp_add(1, 1, n, rp, r - rsz);
			}
#if DEBUG
			printf("$ ");
			for (int j = 1; j <= n; ++j)
				printf("%lld ", ask(1, 1, n, j));
			puts("");
#endif
		} else {
			LL x;
			std::cin >> x;
			printf("%c\n", s[bins(1, 1, n, x)]);
		}
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5828kb

input:

4
3 4 7 10
2 1 9
4 11 2 8 14
3 6 12 13

output:


result:

wrong answer 1st numbers differ - expected: '7', found: '0'