线段树25分求调(调对送你个MM)
查看原帖
线段树25分求调(调对送你个MM)
528287
多喝岩浆楼主2022/7/13 16:38
#include<bits/stdc++.h>
#define int long long
#define PP pair <long long, long long>
using namespace std;
const int N = 1e5 + 10;
struct SegmentTree {
	int Max, l, r, lazy, Max_p;
	bool f;
} tree[N * 4];
int n, a[N], T;
int ans_yyy;
void build (int p, int l, int r) {
	tree[p].l = l, tree[p].r = r, tree[p].f = false;;
	if (l == r) {
		tree[p].Max = a[l];
		tree[p].Max_p = l;
		return;
	}
	int mid = (l + r) >> 1;
	build (p * 2, l, mid);
	build (p * 2 + 1, mid + 1, r);
	if (tree[p * 2].Max > tree[p * 2 + 1].Max) tree[p].Max = tree[p * 2].Max, tree[p].Max_p = tree[p * 2].Max_p;
	else tree[p].Max = tree[p * 2 + 1].Max, tree[p].Max_p = tree[p * 2 + 1].Max_p;
}
inline void down (int p) {
	if (tree[p].lazy != 0) {
		tree[p * 2].Max += tree[p].lazy;
		tree[p * 2 + 1].Max += tree[p].lazy;
		tree[p * 2].lazy += tree[p].lazy;
		tree[p * 2 + 1].lazy += tree[p].lazy;
		tree[p].lazy = 0;
	}
	if (tree[p].f != false) {
		tree[p * 2].Max = 0;
		tree[p * 2 + 1].Max = 0;
		tree[p * 2].f = true;
		tree[p * 2 + 1].f = true;
		tree[p].f = false;
	}
}
void change_1 (int p, int l, int r, int z) {
	if (tree[p].l == l && tree[p].r == r) {
		int num = z - tree[p].Max;
		tree[p].Max = num;
		tree[p].lazy = num;
		return;
	}
	down (p);
	int mid = (tree[p].l + tree[p].r) >> 1;
	if (l <= mid) change_1 (p * 2, l, r, z);
	if (mid < r) change_1 (p * 2 + 1, l, r, z);
	if (tree[p * 2].Max > tree[p * 2 + 1].Max) tree[p].Max = tree[p * 2].Max, tree[p].Max_p = tree[p * 2].Max_p;
	else tree[p].Max = tree[p * 2 + 1].Max, tree[p].Max_p = tree[p * 2 + 1].Max_p;
}
void change_2 (int p, int l, int r, int z) {
	if (tree[p].l == l && tree[p].r == r) {
		tree[p].Max = z;
		tree[p].lazy = z;
		tree[p].f = true;
		return;
	}
	down (p);
	int mid = (tree[p].l + tree[p].r) >> 1;
	if (l <= mid) change_2 (p * 2, l, r, z);
	if (mid < r) change_2 (p * 2 + 1, l, r, z);
	if (tree[p * 2].Max > tree[p * 2 + 1].Max) tree[p].Max = tree[p * 2].Max, tree[p].Max_p = tree[p * 2].Max_p;
	else tree[p].Max = tree[p * 2 + 1].Max, tree[p].Max_p = tree[p * 2 + 1].Max_p;
}
void change_3 (int p, int l, int r, int z) {
	if (tree[p].l >= l && tree[p].r <= r) {
		tree[p].Max += z;
		tree[p].lazy += z;
		return;
	}
	down (p);
	int mid = (tree[p].l + tree[p].r) >> 1;
	if (l <= mid) change_3 (p * 2, l, r, z);
	if (mid < r) change_3 (p * 2 + 1, l, r, z);
	if (tree[p * 2].Max > tree[p * 2 + 1].Max) tree[p].Max = tree[p * 2].Max, tree[p].Max_p = tree[p * 2].Max_p;
	else tree[p].Max = tree[p * 2 + 1].Max, tree[p].Max_p = tree[p * 2 + 1].Max_p;
}
PP query (int p, int l, int r) {
	if (tree[p].l >= l && tree[p].r <= r) return {tree[p].Max, tree[p].Max_p};
	int mid = (tree[p].l + tree[p].r) >> 1;
	down (p);
	PP res = {0, 0};
	if (l <= mid) {
		PP o = query (p * 2, l, r);
		if (o.first >= res.first) res = o;
	}
	if (mid < r) {
		PP o = query (p * 2 + 1, l, r);
		if (o.first >= res.first) res = o;
	}
	return res;
}
signed main () {
	ios::sync_with_stdio (false);
	cin.tie (0), cout.tie (0);
	cin >> n >> T;
	for (int i = 1; i <= n; i ++ ) cin >> a[i];
	build (1, 1, n);
	while (T -- ) {
		int op;
		cin >> op;
		if (op == 1) {
			int x, z;
			cin >> x >> z;
			change_1 (1, x, x, z);
		}
		if (op == 2) {
			int l, r;
			cin >> l >> r;
			PP ans = query (1, l, r);
			cout << ans.first << ' ' << ans.second << endl;
			ans_yyy += ans.first;
			change_2 (1, ans.second, ans.second, 0);
		}
		if (op == 3) {
			int l, r, z;
			cin >> l >> r >> z;
			change_3 (1, l, r, z);
		}
	}
	if (ans_yyy < 10000) cout << "QAQ" << endl;
	else if (ans_yyy >= 10000 && ans_yyy < 10000000) cout << "Sakura" << endl;
	else cout << "ice" << endl;
	return 0;
}
/*
10 10
1 2 3 4 5 6 7 8 9 10
1 1 114514
2 1 1
2 1 1
2 2 2
2 2 2
3 1 2 5
2 1 1
2 1 1
2 2 2
2 2 2

*/
2022/7/13 16:38
加载中...