QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#779261#9791. Intrusive DonkeyPHarrWA 0ms3612kbC++203.2kb2024-11-24 18:05:102024-11-24 18:05:18

Judging History

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

  • [2024-11-24 18:05:18]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3612kb
  • [2024-11-24 18:05:10]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;


using i32 = int32_t;
using i64 = long long;

const i32 inf = INT_MAX / 2;
const i64 INF = LLONG_MAX / 2;

struct Info{
	i64 value, mul;

	Info(i64 value = 0) : value(value) {
		mul = 1;
	}

	i64 val() const {
		return value * mul;
	}

	Info operator+(const Info &b) {
		Info ret;
		ret.value = val() + b.val();
		ret.mul = 1;
		return ret;
	}
};

struct Node {
	i32 l, r;
	Info info;
	Node *left, *right;

	Node(i32 p, i64 v = 1) : info(v) {
		l = r = p;
		left = right = nullptr;
	}

	Node(i32 l, i32 r, Node *left, Node *right) 
		: l(l), r(r), left(left), right(right) {
		info = left -> info + right -> info;
	}

};

void maintain(Node *cur) {
	if(cur -> left == nullptr) return;
	cur -> info = cur -> left -> info + cur -> right -> info;
	return;
}

void pushdown(Node *cur) {
	if(cur -> info.mul == 1) return;
	if(cur -> left != nullptr) {
		cur -> left -> info.mul *= cur -> info.mul;
		cur -> right -> info.mul *= cur -> info.mul;
	}
	cur -> info.mul = 1;
	return;
}

Node *build(i32 l, i32 r) {
	if(l == r) return new Node(l);
	i32 mid = (l + r) / 2;
	auto left = build(l, mid) , right = build(mid + 1, r);
	return new Node(l, r, left, right);
}

Info query(i32 l, i32 r, Node *cur) {
	if(cur == nullptr) return Info();
	if(cur -> r < l or cur -> l > r) return Info();
	if(l <= cur -> l and cur -> r <= r) return cur -> info;
	pushdown(cur);
	return query(l, r, cur -> left) + query(l, r, cur -> right);
}

i64 pre(i32 i, Node *cur) {
	return query(-inf, i, cur).val();
}


void update_add(i32 p, i64 x, Node *cur) {
	if(cur == nullptr) return;
	if(p > cur -> r or cur -> l > p) return;
	pushdown(cur);
	if(p == cur -> l and cur -> r == p) {
		cur -> info.value += x;
		return;
	}
	update_add(p, x, cur -> left), update_add(p, x, cur -> right);
	maintain(cur);
	return;
}

void modify_mul(i32 l, i32 r, i64 x, Node *cur) {
	if(cur == nullptr) return;
	if(l > cur -> r or r < cur -> l) return;
	pushdown(cur);
	if(l <=cur -> l and cur -> r <= r) {
		cur -> info.mul *= x;
		return;
	}
	modify_mul(l, r, x, cur -> left), modify_mul(l, r, x, cur  -> right);
	maintain(cur);
	return;
} 


i32 upper(i64 x, Node *cur){
	if(cur -> l == cur -> r) return cur -> l;
	pushdown(cur);
	if(cur -> left -> info.val() < x) {
		x -= cur -> left -> info.val();
		return upper(x, cur -> right);
	} else {
		return upper(x, cur -> left);
	}
}

i32 main() {
	ios::sync_with_stdio(false), cin.tie(nullptr);

	int n, q;
	cin >> n >> q;

	string s;
	cin >> s;
	s = " " + s;

	auto root = build(1, n);

	while(q --) {
		int op;
		cin >> op;
		if(op == 1) {
			i64 l, r;
			cin >> l >> r;
			i64 idxl = upper(l, root);
			i64 idxr = upper(r, root);
			if(idxl != idxr) {
				i64 addl = pre(idxl, root) - l + 1;
				i64 addr = query(idxr, idxr, root).val() - (pre(idxr, root) - r);
				update_add(idxr, addr, root);
				if(idxl + 1 <= idxr - 1) {
					modify_mul(idxl + 1, idxr - 1, 2, root);
				}
				update_add(idxl, addl, root);
			} else {
				update_add(idxl, r - l + 1, root);
			}
		} else {
			i64 x;
			cin >> x;
			cout << s[upper(x, root)] << "\n";
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3544kb

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: 0ms
memory: 3544kb

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: 0ms
memory: 3580kb

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: 0ms
memory: 3492kb

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: 0ms
memory: 3544kb

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
Wrong Answer
time: 0ms
memory: 3612kb

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:

d
v
m
u
s
k
u
g
u
u
x
u
u
u
b
u
u
u
x
u
u
u
u
u
u
u

result:

wrong answer 7th lines differ - expected: 'q', found: 'u'