QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#785549#9791. Intrusive Donkeyjaker#RE 1ms7804kbC++173.9kb2024-11-26 18:13:242024-11-26 18:13:25

Judging History

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

  • [2024-11-26 18:13:25]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:7804kb
  • [2024-11-26 18:13:24]
  • 提交

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: 100
Accepted
time: 1ms
memory: 5704kb

input:

4 7
abac
2 2
2 3
1 2 3
2 3
2 4
2 5
2 6

output:

b
a
b
a
a
c

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 5776kb

input:

5 4
shrek
1 1 2
2 7
1 1 7
2 7

output:

k
h

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 1ms
memory: 7804kb

input:

4 7
abac
2 2
2 3
1 2 3
2 3
2 4
2 5
2 6

output:

b
a
b
a
a
c

result:

ok 6 lines

Test #4:

score: 0
Accepted
time: 1ms
memory: 7752kb

input:

5 4
shrek
1 1 2
2 7
1 1 7
2 7

output:

k
h

result:

ok 2 lines

Test #5:

score: 0
Accepted
time: 1ms
memory: 5840kb

input:

3 55
vfe
1 2 3
1 2 2
1 3 5
2 4
1 1 2
2 9
2 7
2 5
1 10 10
1 1 1
2 9
1 8 12
2 8
1 7 10
2 1
1 5 6
1 1 4
1 20 24
1 14 32
1 19 38
2 48
1 56 64
2 58
2 19
1 64 72
1 36 86
2 11
1 117 124
2 38
2 108
2 85
1 112 118
2 153
2 40
2 114
2 80
1 11 18
2 27
2 73
1 159 162
2 84
1 130 164
2 163
2 65
1 150 156
1 101 109...

output:

f
e
f
f
f
f
v
f
e
f
f
f
e
e
e
f
e
e
f
e
e
e
f
e
f
e
v

result:

ok 27 lines

Test #6:

score: -100
Runtime Error

input:

60 51
ranhfkbjhkxckkcbhgsspsjcbjgpwcfvmqqlvlfualndmqqsihsfdyqviowu
2 53
2 37
2 33
2 60
1 1 32
2 44
1 87 92
1 7 77
1 56 86
2 17
1 128 184
1 26 159
2 323
2 55
1 24 316
1 435 652
2 316
2 444
1 819 868
2 27
2 912
2 313
1 555 576
1 510 942
1 1118 1269
2 365
2 84
1 595 650
2 1468
2 258
1 1557 1607
2 938
1...

output:


result: