首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

线段树汇总

  • 25-02-22 03:01
  • 4100
  • 9654
blog.csdn.net

线段树是一种二叉搜索树,与区间树相似,它将一个区间划分成一些单元区间,每个单元区间对应线段树中的一个叶结点。
使用线段树可以快速的查找某一个节点在若干条线段中出现的次数,时间复杂度为O(logN)。而未优化的空间复杂度为2N,实际应用时一般还要开4N的数组以免越界,因此有时需要离散化让空间压缩。
区间更新(查询)的时间复杂度是O(logn),使用懒惰法只会影响以下四类节点,每类节点数量都不超过logn。一,左边界及其祖先。二,右边界及其祖先。三,第一类的兄弟节点。四,第二类的兄弟节点。
本封装类,都是使用数组模拟,如果不是连续的节点,需要离散化。如果是流,无法离散化。则需要用哈希映射或树。

封装类

单点初始化、更新

template<class TSave,class TRecord>
class CSingUpdateLineTree
{
public:
	CSingUpdateLineTree(int iEleSize):m_iEleSize(iEleSize), m_vSave(iEleSize*4){

	}
	void Update(int index, TRecord update) {
		Update(1, 1, m_iEleSize, index + 1, update);
	}
	void Query(int leftIndex, int leftRight) {
		Query(1, 1, m_iEleSize, leftIndex + 1, leftRight + 1);
	}
	void Init() {
		Init(1, 1, m_iEleSize);
	}
	const int m_iEleSize;
protected:
	void Init(int iNodeNO, int iSaveLeft, int iSaveRight)
	{
		if (iSaveLeft == iSaveRight) {
			OnInit(m_vSave[iNodeNO], iSaveLeft);
			return;
		}
		const int mid = iSaveLeft + (iSaveRight - iSaveLeft) / 2;
		Init(iNodeNO * 2, iSaveLeft, mid);
		Init(iNodeNO * 2+1, mid+1, iSaveRight);
		OnUpdateParent(m_vSave[iNodeNO], m_vSave[iNodeNO * 2], m_vSave[iNodeNO * 2 + 1], iSaveLeft, iSaveRight);
	}
	void Query(int iNodeNO, int iSaveLeft, int iSaveRight, int iQueryLeft,int iQueryRight) {
		if (( iSaveLeft >= iQueryLeft) && (iSaveRight <= iQueryRight )) {
			OnQuery(m_vSave[iNodeNO]);
			return;
		}
		if (iSaveLeft == iSaveRight) {//没有子节点
			return;
		}
		const int mid = iSaveLeft + (iSaveRight - iSaveLeft) / 2;
		if (mid >= iQueryLeft) {
			Query(iNodeNO * 2, iSaveLeft, mid, iQueryLeft, iQueryRight);
		}
		if( mid+1 <= iQueryRight ){
			Query(iNodeNO * 2+1, mid+1, iSaveRight, iQueryLeft, iQueryRight);
		}
	}
	void Update(int iNodeNO,int iSaveLeft,int iSaveRight,int iUpdateNO, TRecord update) {
		if (iSaveLeft == iSaveRight)
		{
			OnUpdate(m_vSave[iNodeNO], update);
			return;
		}
		const int mid = iSaveLeft + (iSaveRight - iSaveLeft) / 2;
		if (iUpdateNO <= mid) {
			Update(iNodeNO * 2, iSaveLeft, mid, iUpdateNO, update);
		}
		else {
			Update(iNodeNO * 2+1, mid+1, iSaveRight, iUpdateNO, update);
		}
		OnUpdateParent(m_vSave[iNodeNO], m_vSave[iNodeNO * 2], m_vSave[iNodeNO * 2+1],iSaveLeft,iSaveRight);
	}
	virtual void OnInit(TSave& save,int iSave)=0;
	virtual void OnQuery(TSave& save) = 0;
	virtual void OnUpdate(TSave& save, const TRecord& update) = 0;
	virtual void OnUpdateParent(TSave& par, const TSave& left, const TSave& r,int iSaveLeft,int iSaveRight) = 0;
	vector<TSave> m_vSave;
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66

区间更新、区间查询

template<class TSave, class TRecord>
class CLineTree
{
public:
	CLineTree(int iEleSize, TRecord recordNull=0)
		:m_iEleSize(iEleSize), m_vArr(m_iEleSize * 4), m_vRecord(m_iEleSize * 4, recordNull), m_recordNull(recordNull)
	{

	}
	void Update(int iLeftIndex, int iRightIndex, TRecord value)
	{
		Update(1, 1, m_iEleSize, iLeftIndex + 1, iRightIndex + 1, value);
	}
	void Query( int iLeftIndex, int iRightIndex)
	{
		Query( 1, 1, m_iEleSize, iLeftIndex + 1, iRightIndex + 1);
	}
private:
	virtual void OnQuery(TSave& save) = 0;
	virtual void OnUpdateRecord(TRecord& old, const TRecord& newRecord) = 0;
	virtual void OnUpdateParent(TSave& par, const TSave& left, const TSave& r) = 0;
	virtual void OnUpdate(TSave& save, const int& len, const TRecord& update) = 0;
	void Query( int iNode, int iSaveLeft, int iSaveRight, int iQueryLeft, int iQueryRight)
	{
		if ((iQueryLeft <= iSaveLeft) && (iQueryRight >= iSaveRight))
		{
			OnQuery(m_vArr[iNode]);
			return;
		}
		Fresh(iNode, iSaveLeft, iSaveRight);
		const int iMid = iSaveLeft + (iSaveRight - iSaveLeft) / 2;
		if (iMid >= iQueryLeft)
		{
			Query( iNode * 2, iSaveLeft, iMid, iQueryLeft, iQueryRight);
		}
		if (iMid + 1 <= iQueryRight)
		{
			Query( iNode * 2 + 1, iMid + 1, iSaveRight, iQueryLeft, iQueryRight);
		}
	}
	void Update(int iNode, int iSaveLeft, int iSaveRight, int iOpeLeft, int iOpeRight, TRecord value)
	{
		if (iNode >= m_vArr.size())
		{
			return;
		}
		if ((iOpeLeft <= iSaveLeft) && (iOpeRight >= iSaveRight))
		{
			OnUpdate(m_vArr[iNode], min(iSaveRight, iOpeRight) - max(iSaveLeft, iOpeLeft) + 1, value);
			OnUpdateRecord(m_vRecord[iNode], value);
			return;
		}
		Fresh(iNode, iSaveLeft, iSaveRight);
		const int iMid = iSaveLeft + (iSaveRight - iSaveLeft) / 2;
		if (iMid >= iOpeLeft)
		{
			Update(iNode * 2, iSaveLeft, iMid, iOpeLeft, iOpeRight, value);
		}
		if (iMid + 1 <= iOpeRight)
		{
			Update(iNode * 2 + 1, iMid + 1, iSaveRight, iOpeLeft, iOpeRight, value);
		}
		// 如果有后代,至少两个后代
		OnUpdateParent(m_vArr[iNode], m_vArr[iNode * 2], m_vArr[iNode * 2 + 1]);
	}
	void Fresh(int iNode, int iDataLeft, int iDataRight)
	{
		if (m_recordNull == m_vRecord[iNode])
		{
			return;
		}
		const int iMid = iDataLeft + (iDataRight - iDataLeft) / 2;
		Update(iNode * 2, iDataLeft, iMid, iDataLeft, iMid, m_vRecord[iNode]);
		Update(iNode * 2 + 1, iMid + 1, iDataRight, iMid + 1, iDataRight, m_vRecord[iNode]);
		m_vRecord[iNode] = m_recordNull;
	}
	const int m_iEleSize;
	vector<TSave> m_vArr;
	vector<TRecord> m_vRecord;
	const TRecord m_recordNull;
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81

样例汇总

【线段树】【前缀和】:1687从仓库到码头运输箱子

template<class TSave = int , class TRecord = int>
class CMinLineTree : public CLineTree<TSave, TRecord>
{
public:
	using CLineTree<TSave, TRecord>::CLineTree;
	int m_iQueryValue = INT_MAX;
protected:
	virtual void OnQuery(TSave& save) override
	{
		m_iQueryValue = min(m_iQueryValue, save);
	}
	virtual void OnUpdateRecord(TRecord& old, const TRecord& newRecord) override
	{
		old += newRecord;
	}
	virtual void OnUpdateParent(TSave& par, const TSave& left, const TSave& r) override
	{
		par = min(left, r);
	}
	virtual void OnUpdate(TSave& save, const int& len, const TRecord& update) override
	{
		save += update;
	}
	
};

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

【线段树】1622. 奇妙序列

  template<class TSave = C1097Int<>, class TRecord = pair<C1097Int<>,C1097Int<>> >
  class CMyLineTree : public CLineTree<TSave, TRecord>
  {
  public:
	  using CLineTree<TSave, TRecord>::CLineTree;	  
  protected:
	  virtual void OnUpdateRecord(TRecord& old, const TRecord& newRecord) override
	  {
		  old.first *= newRecord.first;
		  old.second = old.second * newRecord.first + newRecord.second;
	  }
	  virtual void OnUpdateParent(TSave& par, const TSave& left, const TSave& r) override
	  {
	  }
	  virtual void OnUpdate(TSave& save, const int& len, const TRecord& iUpdate) override
	  {
		  save = save * iUpdate.first + iUpdate.second;
	  }
  };
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

【最大值线段树】【二分查找】2286. 以组为单位订音乐会的门票

template<class TSave, class TRecord, TRecord RecordNull = 0>
class CMaxLineTree : public CLineTree<TSave, TRecord, RecordNull>
{
	using CLineTree< TSave, TRecord, RecordNull>::CLineTree;
	virtual void OnUpdateRecord(TRecord& old, const TRecord& newRecord) override
	{
		old = newRecord;
	}
	virtual void OnUpdateParent(TSave& par, const TSave& left, const TSave& r) override
	{
		par = max(left, r);
	}
	virtual void OnUpdate(TSave& save, const int& len, const TRecord& iUpdate) override
	{
		save = iUpdate;
	}
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

【线段树】【区间更新】2916. 子数组不同元素数目的平方和 II

class CPOW2LineTree : public CLineTree<pair<C1097Int<>, C1097Int<>>,int>
{
public:
	typedef  pair<C1097Int<>, C1097Int<>> TSave;
	typedef int TRecord;
	const TRecord RecordNull = 0 ;
	using CLineTree::CLineTree;
	// 通过 CLineTree 继承
	virtual void OnUpdateRecord(TRecord& old, const TRecord& newRecord) override
	{
		old += newRecord;
	}
	// 通过 CLineTree 继承
	virtual void OnUpdateParent(TSave& par, const TSave& left, const TSave& r) override
	{
		par.first = left.first + r.first;
		par.second = left.second + r.second;
	}
	virtual void OnUpdate(TSave& save, const int& len, const TRecord& iUpdate) override
	{
		save.second += save.first * 2 * iUpdate + C1097Int<>(len) * iUpdate * iUpdate;
		save.first += C1097Int<>(iUpdate) * len;
	}
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

单点初始化

【线段树】【众数】1157数组中占绝大多数的元素

template<class TSave = std::pair<int,int>, class TRecord = int >
class CMyLineTree : public CSingUpdateLineTree<TSave, TRecord>
{
public:
	CMyLineTree(const vector<int>& arr):m_moreNum(arr),CSingUpdateLineTree<TSave,TRecord>(arr.size()){
		m_arr = arr;		
		CSingUpdateLineTree<TSave, TRecord>::Init();
	}
	int Query(int left, int r, int threshold)
	{
		m_vCan.clear();
		CSingUpdateLineTree<TSave, TRecord>::Query(left,r);
		auto [i1, i2] = m_moreNum.Query(left, r, m_vCan);
		return (i2 >= threshold) ? i1 : -1;
	}
protected:
	vector<int> m_vCan;
	virtual void OnQuery(TSave& save) override	{
		m_vCan.emplace_back(save.first);
	}
	virtual void OnUpdate(TSave& save, const TRecord& update) override{};
	virtual void OnUpdateParent(TSave& par, const TSave& left, const TSave& r, int iSaveLeft, int iSaveRight) override	{
		vector<int> vCan = { left.first,r.first };
		par = m_moreNum.Query(iSaveLeft - 1, iSaveRight - 1, vCan);
	}	
	vector<int> m_arr;
	CMoreNum m_moreNum;
	virtual void OnInit(TSave& save, int iSave) override	{
		save = { m_arr[iSave - 1],1 };
	}
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

【线段树】2213. 由单个字符重复的最长子字符串

template<class TSave = std::tuple<int,int,int>, class TRecord = char, class TSaveCon = CUnorderMapSave<TSave> >
class CMyLineTree :public CSingUpdateLineTree<TSave,TRecord, TSaveCon>
{
public:
	CMyLineTree(const string& s) :m_s(s), CSingUpdateLineTree<TSave, TRecord, TSaveCon>(s.length() ,{ 0,0,0 }) {

	}
	void Update(int index, TRecord update) {
		m_s[index] = update;
		CSingUpdateLineTree<TSave, TRecord, TSaveCon>::Update(index, update);
	}
protected:
	virtual void OnInit(TSave& save, int iSave) override
	{
		save = { 1,1,1 };
	}
	virtual void OnQuery(TSave& save) override
	{
	}
	virtual void OnUpdate(TSave& save, int iSaveLeft, const TRecord& update) override
	{
		save = { 1,1,1 };
	}
	virtual void OnUpdateParent(TSave& par, const TSave& left, const TSave& r, int iSaveLeft, int iSaveRight) override
	{
		int i1 = get<0>(left);//最长前缀
		int i2 = max(get<1>(left), get<1>(r));//最长字符串
		int i3 = get<2>(r);//最长后缀
		const int mid = iSaveLeft + (iSaveRight - iSaveLeft) / 2;
		if (m_s[mid] == m_s[mid + 1])
		{//拼接
			i2 = max(i2, get<2>(left) + get<0>(r));
			if (mid - iSaveLeft + 1 == i1) {
				i1 += get<0>(r);
			}
			if (iSaveRight - mid == i3) {
				i3 += get<2>(left);
			}
		}
		par = { i1,i2,i3 };
	}
	 string m_s;
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43

【线段树】2276. 统计区间中的整数数目

template<class TSave=int, class TRecord =int >
class CMyTreeRangeLineTree : public CTreeRangeLineTree<TSave, TRecord>
{	
public:
	using CTreeRangeLineTree<TSave, TRecord>::CTreeRangeLineTree;
protected:
	virtual void OnQuery(TSave& save) override
	{
	}
	virtual void OnUpdate(TSave& save, int iSaveLeft, int iSaveRight, const TRecord& update) override
	{ 
		save = update*(iSaveRight-iSaveLeft+1);
	}
	virtual void OnUpdateParent(TSave& par, const TSave& left, const TSave& r, int iSaveLeft, int iSaveRight) override
	{
		par = left + r;
	}
	virtual void OnUpdateRecord(TRecord& old, const TRecord& newRecord) override
	{
		old = newRecord;
	}
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

【线段树 有序映射】715. Range 模块

template<class TSave=int, class TRecord =int >
class CMyTreeRangeLineTree : public CTreeRangeLineTree<TSave, TRecord>
{	
public:
	using CTreeRangeLineTree<TSave, TRecord>::CTreeRangeLineTree;
	bool queryRange(int left, int right) {
		m_bHas = true;
		CTreeRangeLineTree<TSave, TRecord>::Query(left, right);
		return m_bHas;
	}
protected:
	bool m_bHas = true;
	virtual void OnQuery(const TSave& save, const int& iSaveLeft, const int& iSaveRight) override
	{
		m_bHas &= (save == (iSaveRight - iSaveLeft + 1));
	}
	virtual void OnUpdate(TSave& save, const int& iSaveLeft, const int& iSaveRight, const TRecord& update) override
	{ 
		save = update*(iSaveRight-iSaveLeft+1);
	}
	virtual void OnUpdateParent(TSave& par, const TSave& left, const TSave& r, const int& iSaveLeft, const int& iSaveRight) override
	{
		par = left + r;
	}
	virtual void OnUpdateRecord(TRecord& old, const TRecord& newRecord) override
	{
		old = newRecord;
	}
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

其它有题解的题目

【键值皆有序map 线段树 数学 】100240. 最小化曼哈顿距离|最小线段树,单点更新,区间查询

template<class TSave=int, class TRecord =int >
class CMyTreeRangeLineTree : public CTreeRangeLineTree<TSave, TRecord>
{	
public:
	using CTreeRangeLineTree<TSave, TRecord>::CTreeRangeLineTree;
	bool queryRange(int left, int right) {
		m_bHas = true;
		CTreeRangeLineTree<TSave, TRecord>::Query(left, right);
		return m_bHas;
	}
protected:
	bool m_bHas = true;
	virtual void OnQuery(TSave& save, int iSaveLeft, int iSaveRight) override
	{
		m_bHas &= (save == (iSaveRight - iSaveLeft + 1));
	}
	virtual void OnUpdate(TSave& save, int iSaveLeft, int iSaveRight, const TRecord& update) override
	{ 
		save = update*(iSaveRight-iSaveLeft+1);
	}
	virtual void OnUpdateParent(TSave& par, const TSave& left, const TSave& r, int iSaveLeft, int iSaveRight) override
	{
		par = left + r;
	}
	virtual void OnUpdateRecord(TRecord& old, const TRecord& newRecord) override
	{
		old = newRecord;
	}
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

【线段树 区间位运算模板】3117划分数组得到最小的值之和

template<class TSave = int , class TRecord = int >
class CMyLineTree : public CVectorRangeUpdateLineTree<TSave, TRecord>
{
public:
	CMyLineTree(int iSize,int iNotMay) :CVectorRangeUpdateLineTree<TSave, TRecord>(iSize,iNotMay,iNotMay){

	}
	void Query(int leftIndex, int leftRight) {
		m_iQuery = CVectorRangeUpdateLineTree<TSave, TRecord>::m_recordNull;
		CVectorRangeUpdateLineTree<TSave, TRecord>::Query(leftIndex, leftRight);
	}
	int m_iQuery;
protected:
	virtual void OnQuery(const TSave& save, const int& iSaveLeft, const int& iSaveRight)	{
		m_iQuery = min(m_iQuery, save);
	}
	virtual void OnUpdate(TSave& save, const int& iSaveLeft, const int& iSaveRight, const TRecord& update) {
		save = min(save,update);
	}
	virtual void OnUpdateParent(TSave& par, const TSave& left, const TSave& r, const int& iSaveLeft, const int& iSaveRight) {
		par = min(left, r);
	}
	virtual void OnUpdateRecord(TRecord& old, const TRecord& newRecord) {
		old = min(newRecord,old);
	}
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

无题解的题目

LeetCode
LeetCode 218 际线问题最大值 离散化后 线段树区间修改,单点查询
LeetCode 315. 计算右侧小于当前元素的个数求和,单点修改,区间查询
LeetCode 327. 区间和的个数求和,前缀和是已知的,所以离散化。单点修改,区间查询
LeetCode 493. 翻转对求和,离散化后,单点修改,区间查询
LeetCode 699. 掉落的方块最大值,区间修改区间查询
LeetCode 715. Range 模块求和,无法离散化,麻烦。直接模拟或差分数组+树状数组。 区间修改,区间查询。
LeetCode 732. 我的日程安排表 III最大值,区间更新,区间查询
LeetCode 850. 矩形面积 II求和,离散化+扫描线。线段树实现维护当前x,各y是否被覆盖。可以覆盖多次,也可以解除覆盖。有覆盖时,求和时为1,没覆盖为0。
LeetCode 1505. 最多 K 次交换相邻数位后得到的最小整数求和,单点更新,单点查询
1521. 找到最接近目标值的函数值与和+二分查找。除了练习,没有任何必要使用线段树。
1649. 通过指令创建有序数组求和,单点更新,区间修改
2179. 统计数组中好三元组数目等价转换(重新编码)+求和,单点更新,区间求和
2213. 由单个字符重复的最长子字符串最长,单点修改,区间查询
2276. 统计区间中的整数数目无法离散化,用哈希。区间修改、区间查询
2407. 最长递增子序列 II最大值,单点修改,区间查询
2426. 满足不等式的数对数目离散化,求和,单点修改
2569. 更新数组后处理求和查询01反转,区间修改
2736. 最大和查询离线查询,最大值。单点更新,区间查找
2926. 平衡子序列的最大和最大值,单点更新,区间查询
2940. 找到 Alice 和 Bob 可以相遇的建筑二分查找+最大值线段树
3072. 将元素分配到两个数组中 II求和,单点修改,区间查询
LCP 05. 发 LeetCoinDFS时间序,求和线段树。区间修改、区间查询
LCP 09. 最小跳跃次数最小值,单点更新,区间查询

扩展阅读

视频课程

有效学习:明确的目标 及时的反馈 拉伸区(难度合适),可以先学简单的课程,请移步CSDN学院,听白银讲师(也就是鄙人)的讲解。
https://edu.csdn.net/course/detail/38771

如何你想快

速形成战斗了,为老板分忧,请学习C#入职培训、C++入职培训等课程
https://edu.csdn.net/lecturer/6176

相关

下载

想高屋建瓴的学习算法,请下载《喜缺全书算法册》doc版
https://download.csdn.net/download/he_zhidan/88348653

我想对大家说的话
闻缺陷则喜是一个美好的愿望,早发现问题,早修改问题,给老板节约钱。
子墨子言之:事无终始,无务多业。也就是我们常说的专业的人做专业的事。
如果程序是一条龙,那算法就是他的是睛

测试环境

操作系统:win7 开发环境: VS2019 C++17
或者 操作系统:win10 开发环境: VS2022 C++17
如无特殊说明,本算法用**C++**实现。

文章知识点与官方知识档案匹配,可进一步学习相关知识
算法技能树首页概览60345 人正在系统学习中
群中有博文配套源码
QQ群名片
注:本文转载自blog.csdn.net的闻缺陷则喜何志丹的文章"https://blog.csdn.net/he_zhidan/article/details/137177601"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

101
推荐
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2025 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top