序列終結者

2021-07-08 16:50:46 字數 1415 閱讀 2662

時間限制: 1 sec 記憶體限制: 128 mb

題目描述

給定乙個長度為n的序列,每個序列的元素是乙個整數。

要支援以下三種操作:

1. 將[l,r]這個區間內的所有數加上v。

2. 將[l,r]這個區間翻轉,比如1 2 3 4變成4 3 2 1。

3. 求[l,r]這個區間中的最大值。

最開始所有元素都是0。

輸入

第一行兩個整數n,m。m為操作個數。 以下m行,每行最多四個整數,依次為k,l,r,v。k表示是第幾種操作,如果不是第1種操作則k後面只有兩個數。

n<=50000,m<=100000

輸出

對於每個第3種操作,給出正確的回答。

樣例輸入

4 4

1 1 3 2

1 2 4 -1

2 1 3

3 2 4

樣例輸出

2splay練習題

#include

#include

#include

#include

#include

#include

#include

#define inf 2100000000

using namespace std;

int n,m,null,root;

struct nodet[50010];

class splay_tree

void addup(int

x,int v)

void up(int

x)

void down(int

x)

void rotate(int

x,int k)

public:

void splay(int

x,int

pos)

if(x==t[fa].s[0]&&fa==t[fb].s[0])

if(x==t[fa].s[1]&&fa==t[fb].s[1])

rotate(x,t[fa].s[0]==x?0:1);rotate(x,t[fb].s[0]==x?0:1);

}up(x);if(pos==root)root=x;

} void build(int

x,int l,int r)

void select(int

x,int des,int

pos)

if(x!=pos)splay(x,pos);

}}t;

int main()

return

0;}

序列終結者 Splay

1.注意在 split 和 merge 時要特判一下邊界,否則就會出現邊界錯誤的情況。2.隨時都要維護父指標。3.在更新 maxv 和翻轉標記時要判一下左右兒子是否都存在。include include includeusing namespace std const int maxn 100000...

序列終結者 Splay

1.注意在 split 和 merge 時要特判一下邊界,否則就會出現邊界錯誤的情況。2.隨時都要維護父指標。3.在更新 maxv 和翻轉標記時要判一下左右兒子是否都存在。include include includeusing namespace std const int maxn 100000...

序列終結者(bzoj 1521)

網上有許多題,就是給定乙個序列,要你支援幾種操作 a b c d。一看另一道題,又是乙個序列 要支援幾種操作 d c b a。尤其是我們這裡的某人,出模擬試題,居然還出了一道這樣的,真是沒技術含量 這樣 我也出一道題,我出這一道的目的是為了讓大家以後做這種題目有乙個 庫 可以依靠,沒有什麼其他的意思...