当前位置:网站首页>Kodori tree board
Kodori tree board
2022-07-01 04:36:00 【HeartFireY】
Kodori is the happiest girl in the world !!!

JUST Save a board , Convenient for later use
Remember to handle it set::iterator == set::begin()/end() The situation of !
namespace ct{
struct node{
int l, r;
mutable int val;
node (int lpos): l(lpos) {
}
node (int lpos, int rpos, int vall): l(lpos), r(rpos), val(vall) {
}
bool operator< (const node &a) const {
return l < a.l; }
};
set<node> s;
using sit = set<node>::iterator;
//^ChthollyTree-SetSplit
sit split(int pos){
sit it = s.lower_bound(node(pos));
if(it != s.end() && it -> l == pos) return it;
--it;
int l = it -> l, r = it -> r, val = it -> val;
s.erase(it);
if(l <= pos - 1) s.insert(node(l, pos - 1, val));
if(r >= pos) return s.insert(node(pos, r, val)).first;
return s.end();
}
//^ChthollyTree-PartValueAssign
void assign(int l, int r, int val){
sit itr = split(r + 1), itl = split(l);
s.erase(itl, itr);
s.insert(node(l, r, val));
}
//^ChthollyTree-PartValueAddition
void add(int l, int r, int val){
sit itr = split(r + 1), itl = split(l);
while(itl != itr) itl -> val += val, itl++;
}
//^ChthollyTree-Get_K-th_Value
int kth(int l, int r, int k){
sit itr = split(r + 1), itl = split(l);
vector<pair<int, int>> v;
v.clear();
for(sit it = itl; it != itr; it++) v.emplace_back(make_pair(it -> val, it -> r - it -> l + 1));
sort(v.begin(), v.end());
for(int i = 0; i < v.size(); i++){
k -= v[i].second;
if(k <= 0) return v[i].first;
}
return -1;
}
//^ChthollyTree-SinglePointQuery
sit query(int pos){
auto it = prev(s.upper_bound(pos));
return it;
}
//^ChthollyTree-PartQuery
int query_part(int l, int r, int x, int y){
sit itr = split(r + 1), itl = split(l);
int res(0);
for(sit it = itl; it != itr; it++) res += it -> val;
return res;
}
}
边栏推荐
- The junior college students were angry for 32 days, four rounds of interviews, five hours of soul torture, and won Ali's offer with tears
- MySQL function variable stored procedure
- 什么是权限?什么是角色?什么是用户?
- Jenkins automatically cleans up construction history
- Programs and processes, process management, foreground and background processes
- Maixll-Dock 使用方法
- 如何看待智慧城市建设中的改变和机遇?
- Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition
- [deep learning] (4) decoder mechanism in transformer, complete pytoch code attached
- Applications and features of VR online exhibition
猜你喜欢
![[human version] Web3 privacy game in the dark forest](/img/89/e16789b7f3892002748aab309c45e6.png)
[human version] Web3 privacy game in the dark forest

Offline installation of Wireshark 2.6.10

Execution failed for task ‘:app:processDebugResources‘. > A failure occurred while executing com. and

2022 polymerization process test questions and simulation test

Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition

Do280 management application deployment --rc

跳槽一次涨8k,5年跳了3次...

Coinbase in a bear market: losses, layoffs, stock price plunges

【发送邮件报错】535 Error:authentication failed
![[pat (basic level) practice] - [simple simulation] 1064 friends](/img/37/0ef0f8aae15ae574be1d76c97497c9.jpg)
[pat (basic level) practice] - [simple simulation] 1064 friends
随机推荐
Unity's 3D multi-point arrow navigation
2022年上海市安全员C证考试题模拟考试题库及答案
25.k sets of flipped linked lists
Introduction of Spock unit test framework and its practice in meituan optimization___ Chapter I
[send email with error] 535 error:authentication failed
Rule method: number of effective triangles
Do280 management application deployment --rc
Some small knowledge points
1. Mobile terminal touch screen event
嵌入式系统开发笔记80:应用Qt Designer进行主界面设计
Extension fragment
TASK04|数理统计
PgSQL failed to start after installation
Codeforces Round #721 (Div. 2)B1. Palindrome Game (easy version)B2. Palindrome game (hard version)
Announcement on the list of Guangdong famous high-tech products to be selected in 2021
为什么香港服务器最适合海外建站使用
细数软件研发效能的七宗罪
2022-02-15 (399. Division evaluation)
Collect the annual summary of laws, regulations, policies and plans related to trusted computing of large market points (national, ministerial, provincial and municipal)
Mallbook: how can hotel enterprises break the situation in the post epidemic era?