bzoj1012(线段树模板题)

题目读了三遍才读懂,对于蒟蒻来说,看上去很难得样子,实际就是线段树的单点更新,然后求区间最值,无奈之前还想着怎么建树插进去。。结果RE n次,感觉自己水的一匹,唉~
做题效率极低。。。。
真是被自己蠢哭了

#include
#include
#include
#include
#include
#pragma warning  (disable :4996);
#define ll long long
using namespace std;
ll n=200000, m;
ll t[2000005 ];

ll maxx = 0;
ll max1 = 0;
void build(ll l, ll r, ll rt) {
	if (l == r)return;	
	ll mid = (l + r) >> 1;
	build(l, mid, rt << 1);
	build(mid + 1, r, rt << 1 | 1);
}

void update(ll l, ll r, ll rt, ll k, ll val) {
	if (l == r) {
		t[rt] = val;
		return;
	}
	ll mid = (l + r) >> 1;
	if (mid >= k)update(l, mid, rt << 1, k, val);
	else update(mid + 1, r, rt << 1 | 1, k, val);
	t[rt] = max(t[rt << 1], t[rt << 1 | 1]);
}

//查询 
void query(ll l, ll r, ll rt,ll L,ll R) {
	if (l >= L && r <= R) {
		maxx = max(maxx, t[rt]);
		return;
	}
	ll mid = (l + r) >> 1;
	if (mid >= L)query(l, mid, rt << 1, L, R);
	if (mid < R)query(mid + 1, r, rt << 1 | 1, L, R);
	return;
}

int main() {

	ll a, b;
	char x[3];
	ll t=0;
	ll mod,num,cnt=0;
	scanf("%lld%lld", &m, &mod);
	for (ll i = 0; i 

你可能感兴趣的:(线段树)