bzoj1500 NOI2005 維修數列

2021-07-29 12:50:06 字數 1785 閱讀 4067

description

input

輸入檔案的第1行包含兩個數n和m,n表示初始時數列中數的個數,m表示要進行的運算元目。第2行包含n個數字,描述初始時的數列。以下m行,每行一條命令,格式參見問題描述中的**。

output

對於輸入資料中的get-sum和max-sum操作,向輸出檔案依次列印結果,每個答案(數字)佔一行。

sample input

9 8

2 -6 3 5 1 -5 -3 6 3

get-sum 5 4

max-sum

insert 8 3 -5 7 2

delete 12 1

make-same 3 3 2

reverse 3 6

get-sum 5 4

max-sum

sample output

-1 10

1 10

hint

題解 splay基本操作,參見黃學長部落格(本人**基本仿照)

**

#include

#include

#include

#include

#include

#include

#define inf 1000000000

#define n 1000005

using

namespace

std;

int n,m,rt,cnt;

int a[n],id[n],fa[n],c[n][2];

int sum[n],size[n],v[n],mx[n],lx[n],rx[n];

bool tag[n],rev[n];

queue

q;int read()

while(ch>='0'&&ch<='9')

return x*f;

}void update(int x)

void pushdown(int x)

else

}if(rev[x])

}void rotate(int x,int &k)

void splay(int x,int &k)

rotate(x,k);

}}int find(int k,int x)

void build(int l,int r,int f)

else build(l,mid-1,mid),build(mid+1,r,mid);

fa[now]=last;v[now]=a[mid];

update(now);

c[last][mid>=f]=now;

}void insert(int k,int tot)

else id[i]=++cnt;

}build(1,tot,0);int z=id[(1+tot)>>1];

int x=find(rt,k+1),y=find(rt,k+2);

splay(x,rt);splay(y,c[x][1]);

fa[z]=y;c[y][0]=z;

update(y);update(x);

}void rec(int x)

void del(int k,int tot)

void rever(int k,int tot)

}void query_sum(int k,int tot)

void change(int st,int tot,int val)

int main()}}

return

0;}

BZOJ1500 NOI2005 維修數列

description input 輸入檔案的第1行包含兩個數n和m,n表示初始時數列中數的個數,m表示要進行的運算元目。第2行包含n個數字,描述初始時的數列。以下m行,每行一條命令,格式參見問題描述中的 output 對於輸入資料中的get sum和max sum操作,向輸出檔案依次列印結果,每個...

bzoj1500 NOI2005 維修數列

splay鼻祖級的題目?霧。insert 把第pos個數 有哨兵節點 轉到root,把第pos 1個數轉到root的右兒子,然後對c建樹然後把這棵樹插到root右兒子的左兒子處 delete 把第pos個數轉到root,把第pos tot 1個數轉到root右兒子,刪掉root右兒子的左兒子 變成0...

BZOJ 1500 NOI2005 維修數列

輸入的第1 行包含兩個數n 和m m 20 000 n 表示初始時數列中數的個數,m表示要進行的運算元目。第2行包含n個數字,描述初始時的數列。以下m行,每行一條命令,格式參見問題描述中的 任何時刻數列中最多含有500 000個數,數列中任何乙個數字均在 1 000,1 000 內。插入的數字總數不...