当前位置:网站首页>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;
}
}
边栏推荐
- 什么是权限?什么是角色?什么是用户?
- 如何看待智慧城市建设中的改变和机遇?
- LM小型可编程控制器软件(基于CoDeSys)笔记二十:plc通过驱动器控制步进电机
- Ten wastes of software research and development: the other side of research and development efficiency
- One job hopping up 8K, three times in five years
- 2022 hoisting machinery command registration examination and hoisting machinery command examination registration
- Common thread methods and daemon threads
- Daily question - line 10
- Valid @suppresswarnings warning name
- Maixll-Dock 使用方法
猜你喜欢

Extension fragment

Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling

2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis

js 图片路径转换base64格式

TASK04|數理統計

Common thread methods and daemon threads

Loop filtering based on Unet

【发送邮件报错】535 Error:authentication failed

Ten wastes of software research and development: the other side of research and development efficiency

Rule method: number of effective triangles
随机推荐
Applications and features of VR online exhibition
ThreeJS开篇
2022年上海市安全员C证考试题模拟考试题库及答案
2022 a special equipment related management (elevator) simulation test and a special equipment related management (elevator) certificate examination
嵌入式系統開發筆記80:應用Qt Designer進行主界面設計
Redis (VII) optimization suggestions
分账技术赋能农贸市场,重塑交易管理服务效能
Web server: how to choose a good web server these five aspects should be paid attention to
Tencent has five years of testing experience. It came to the interview to ask for 30K, and saw the so-called software testing ceiling
[leetcode skimming] February summary (updating)
Simple implementation of slf4j
Announcement on the list of Guangdong famous high-tech products to be selected in 2021
In the innovation community, the "100 cities Tour" of the gold warehouse of the National People's Congress of 2022 was launched
Dual contractual learning: text classification via label aware data augmentation reading notes
2022年聚合工艺考试题及模拟考试
Recommend the best product development process in the Internet industry!
Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记
做网站数据采集,怎么选择合适的服务器呢?
2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
2022 polymerization process test questions and simulation test