hihococer 1077 线段树

HIHO 1077



裸题, 直接zkw线段树



code:

/*
adrui's submission 
language : C++
Result : Accepted
love : ll
favorite : Dragon Balls

Standing in the Hall of Fame
*/

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

#define debug 0
#define inf 0x3f3f3f3f
#define M(a, b) memset(a, b, sizeof(a))

const int maxn = 1e6 + 5;

int mx[maxn << 2], n, M;


void build() {
	M(mx, inf);

	for (M = 1; M <= n + 1; M <<= 1);
	for (int i = M + 1; i <= M + n; i++) {
		scanf("%d", &mx[i]);
	}
	for (int i = M - 1; i; i--) {
		mx[i] = min(mx[i << 1], mx[i << 1 | 1]);
	}
}

void update() {

	int a, b;
	scanf("%d%d", &a, &b);

	for (mx[a += M] = b, a >>= 1; a; a >>= 1)
		mx[a] = min(mx[a << 1], mx[a << 1 | 1]);
}
int query() {
	int l, r;
	scanf("%d%d", &l, &r);
	l += M - 1;
	r += M + 1;
	int ans = inf;
	while (r ^ l ^ 1) {
		if (~l & 1) {
			ans = min(ans, mx[l + 1]);
		}
		if (r & 1) {
			ans = min(ans, mx[r - 1]);
		}

		r >>= 1;
		l >>= 1;
	}

	return ans;
}
int main() {
#if debug
	freopen("in.txt", "r", stdin);
#endif //debug
	int q, t;
	while (~scanf("%d", &n)) {

		build();
		scanf("%d", &q);
		while (q--) {
			scanf("%d", &t);
			if (t)
				update();
			else
				printf("%d\n", query());
		}
	}

	return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值