Splay解決區間問題 單點更新,區間最值詢問

2021-06-12 13:13:17 字數 678 閱讀 1237

/*

/*單點更新,區間詢問 splay實現*/

/*注意寫rotateto的時候。。*/

#include#include#include#includeusing namespace std;

const int maxn = 222222;

class splaytree

void read(int n)

void push_up(int rt)

void rotate(int x,int f)

void splay(int x,int goal)elseelse}}

push_up(x);

if(goal==0) root = x;

}void rotateto(int x,int goal)else

}splay(k,goal);

}void buildtree(int l,int r,int &rt,int f)

int query(int l,int r)

void update(int pos,int c)

void debug()

void dfs(int rt)

};splaytree spt;

int main()else}}

return 0;

}

Splay解決區間問題 區間更新,區間求和

區間更新,區間求和 注意各種編碼細節,特別是splay buildtree和 rotateto 仔細體會與線段樹解決區間問題的不同點,如結點記錄的資訊是不同的 lazy思想 include include includeusing namespace std const int maxn 11111...

區間翻轉問題 Splay

問題描述 給你乙個長度為n的序列和m個操作 1.查詢第k個數的值 2.將第k個數增加d 3.查詢一段區間的和 4.查詢一段區間的最大值 5.將一段區間鏡面翻轉 例如序列,將從2到5的區間翻轉後得到序列 對於除操作2,5以外的操作,輸出相應的答案 輸入格式 第一行兩個正整數n,m 第二行n個整數,為初...

Splay之區間翻轉問題

給你 n 個數 分別為 1,2,3,4 n 然後有 m 個操作,每個操作對應一段區間,將區間的數進行翻轉。比如 1,2,3,4,5 這段序列 操作區間為 2 4 翻轉完成後的序列為 1,4,3,2,5 第一行分別輸入 n,m 第2行到m 1行每行輸入兩個數 對應操作的區間 輸出最後翻轉完成後的序列 ...