当前位置:网站首页>Tree array and St table
Tree array and St table
2022-07-19 02:32:00 【HYYyyying】
Tree array and ST surface
dynamic : Tree array static state :ST surface
Tree array :cnt=x End of binary 0 The number of , Array d[x] Store 2^cnt Number .
Inquire about : such as 13,13 = 1101, Only one number is stored a[13], Now? , seek 13 The prefix of this position and :
( There are several 1 Divided into several parts ) Divided into three parts : ( Every time, the last one is erased 1,log Grade )
1101 d[13] 2^0
1100 d[12] 2^2
1000 d[8] 2^3
Single query complexity logn
modify : Modify the value of a node , You need to modify the value of the node that overrides him .
How to get the last end 1 Where is the location ?( principle , Complement or something )
Lowbit(int x){// Returns the... At the end of the binary 1 Where is the
return x & (-x);
}
summary : The query subtracts 1, Modify to add 1.
To solve : Interval query ( Prefixes and ideas ), Single point modification (lowbit Keep looking for his points to cover )
#include <stdio.h>
#include <string>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <queue>
#include <math.h>
#include <map>
#include <bitset>
#include <stdlib.h>
#include <vector>
using namespace std;
typedef long long ll;
#define pb push_back
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
/******** Single point modification , Interval query **********/
int lowbit(int x){
return x & (-x);
}
int ask(int x){
//[1, x], Satisfy prefix and
int res = 0;
while(x){
res += d[x];
}
x -= lowbit(x);
return res;
}
void add(int x, int v){
while(x <= n){
d[x] += v;
x += lowbit(x);
}
}
/********** Two dimensional tree array single point modification , Interval query ****************/
void update(int x, int y, int v){
for( ; x <= n; x += lowbit(x)){
for(int j = y; j <= n; j += lowbit(j)){
d[x][j] += v;
}
}
}
int getsum(int x, int y){
int res = 0;
for( ; x > 0; x -= lowbit(x)){
for(int j = y; j; j -= lowbit(j)){
res += d[x][j];
}
}
return res;
}
int main(){
return 0;
}
Single point query , Interval modification ( Difference thinking )
Maximum / Small value ( The segment tree is better , It's just that the constant is a little larger ,ST The watch is OK, too )
cf755D poj2352 bzoj1878 bzoj2743 bzoj1452
Two dimensional tree array
ST surface :RMQ problem
Line segment tree :O(n) Preprocessing Single inquiry O(logn) Space O(n)
ST surface :O(nlogn) Preprocessing Single inquiry O(1) Space O(nlogn)
d[i][j] An organization representing such a range : The left endpoint is i, The length is 2^j, signify , It governs [i,i + 2^j - 1]
CDOJ1591(ST surface )
边栏推荐
- 初识阿里云环境搭建:无法远程连接,入过的坑:服务器ping不通,FTP搭建,服务器搭建数据库,远程连接服务器数据库
- 【Unity编辑器扩展】Unity内部Asset资源配置ScriptableObject
- 【AntV G2】如何解决 G2 造成的内存泄露
- Signal and system experiment
- 网络层协议和IP数据包的格式(详解)
- 仅以此篇纪念负数取模
- 去中心化边缘渲染元宇宙协议Caduceus受邀出席CBAIA 2022峰会,以技术赋能更多Web3应用场景
- [antv G2] how to add a click event to the line chart (click anywhere to get the value of the point on the line)
- 最短路/次短路/K短路
- uniapp微信小程序登录(先授权微信后授权手机号)-- (1)
猜你喜欢

General knowledge of network (detailed)

Software testing technology interim testing summary | software testing foundation & Executive testing & test design and development

Jmeter响应时间测试组件&多接口并发

【HDRP高清渲染管道】创建HDRP工程,把内置管线工程升级为HDRP工程

Post man JSON script to JMX script of JMeter

逆元(名字太多人用我就加这几个字)

网络层传输协议(详解)

Logic vulnerability - login verification code security

【Unity编辑器扩展】Unity资产预处理和后处理图片自动转Sprite2D

SSTI模板注入
随机推荐
初识阿里云环境搭建:无法远程连接,入过的坑:服务器ping不通,FTP搭建,服务器搭建数据库,远程连接服务器数据库
Gdb+vscode debugging -- how to debug the release version
Logical vulnerability - authentication vulnerability
SSTI模板注入
status 500 reading AftersaleService#getAftersaleList(Long)+com.sun.proxy.$Proxy214.getAftersaleList
仅以此篇纪念负数取模
uniapp微信小程序登录(先授权微信后授权手机号)-- (1)
网络一般知识(详)
Buaaos-lab0 experimental report
Decentralized edge rendering meta universe protocol cadeus was invited to attend the cbaia 2022 summit to enable more Web3 application scenarios with technology
性能测试实施规范指南
[tools] unity2d character controller, which controls 2D players to move and jump in four directions and horizontal directions
流量回放工具gor使用经验
Logic vulnerability - login verification code security
逆元(名字太多人用我就加这几个字)
bugku题解
[unity Editor Extension] unity makes its own exclusive editor panel
《Visual C#从入门到精通》个人学习整理
How to configure multiple SSH keys for novices (easy to understand hand-in-hand teaching)
bugku----正则匹配,cookies