普通线段树模板,分块模板,树状数组模板存档

这篇博客详细介绍了三种经典的数据结构模板:线段树,包括基本功能如区间查询、区间修改、单点查询和单点修改,以及维护区间最值的能力;分块算法,展示了其基本操作;还有树状数组,同样涵盖了基本应用。通过这些内容,读者可以更好地理解和运用这些数据结构解决问题。
摘要由CSDN通过智能技术生成

目录

线段树(具备基本功能:区间查询,区间修改,单点查询,单点修改)

线段树(维护区间最值并查询)

分块算法(具备基本功能)

树状数组(具备基本功能)


线段树(具备基本功能:区间查询,区间修改,单点查询,单点修改)

#include<pch.h>
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
#include <queue>
#include <map>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <cstring>
#include <cmath>
#define DETERMINATION main
#pragma GCC optimize(2)
#pragma warning(disable:4996)
#define lldin(a) scanf("%lld", &a)
#define println(a) printf("%lld\n", a)
#define print(a) printf("%lld ", a)
#define reset(a, b) memset(a, b, sizeof(a))
#define debug cout<<"procedures above are available"<<endl;
#define BigInteger __int128
using namespace std;
const int INF = 2e9 + 2;
const double PI = acos(-1);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int mod = 1e9 + 7;
//template<typename T>
//inline BigInteger nextBigInteger()
//{
//    BigInteger tmp = 0, si = 1;char c;    c = getchar();
//    while (!isdigit(c))
//{if (c == '-')si = -1;c = getchar();}
//    while (isdigit(c))
//    {tmp = tmp * 10 + c - '0';c = getchar();}
//    return si * tmp;    
//}            
//std::ostream& operator<<(std::ostream& os, __int128 T)
//{
//    if (T<0) os<<"-";if (T>=10 ) os<<T/10;if (T<=-10) os<<(-(T/10));
//    return os<<( (int) (T%10) >0 ? (int) (T%10) : -(int) (T%10) ) ;
//}
//void output(BigInteger x)
//{
//    if (x < 0)
//    {x = -x;putchar('-');}
//    if (x > 9) output(x / 10);
//    putchar(x % 10 + '0');
//    }
/**Maintain your determination.Nobody knows the magnificent landscape
at his destination before the arrival with stumble.**/
/**Last Remote**/
struct node
{
	ll left, right, value;
	ll laziness;
}nodes[599999];
ll arr[599999];
void construction(ll current,ll left, ll right)
{
	nodes[current].left = left, nodes[current].right = right;
	if (left == right)
	{
		nodes[current].value = arr[left];
		return ;
	}
	else
	{
		ll mid = (left + right) >> 1;
		construction(2 * current, left, mid);
		construction(2 * current + 1, mid + 1, right);
		nodes[current].value = nodes[2 * current].value + nodes[2 * current + 1].value;
	}
}
void LazyDown(ll current)
{
	nodes[2 * current].laziness+= nodes[current].laziness;
	nodes[2 * current + 1].laziness += nodes[current].laziness;
	nodes[2 * current].value += (nodes[2 * current].right - nodes[2 * current].left + 1)*nodes[current].laziness;
	nodes[2 * current + 1].value += (nodes[2 * current + 1].right - nodes[2 * current + 1].left + 1)*nodes[current].laziness;
	nodes[current].laziness = 0;
}
ll investigation(ll current, ll lower, ll upper)
{
	if (nodes[current].left >= lower && nodes[current].right <= upper)
	{
		//cout << nodes[current].value << endl;
		return nodes[current].value;
	}
	else
	{
		if (nodes[current].laziness
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值