没什么好说的,树套树应该随便搞
我在128MB空间下大胆的写了主席树
当然要把原树和修改树分开来建
没有然后了

 type node=record
l,r,s:longint;
end; var tree:array[..] of node;
c:array[..] of int64;
h,ph,a,b,d1,d2:array[..] of longint;
dd1,dd2:array[..,..] of longint;
d,t1,t2,i,x,y,n,m,t:longint;
ans:int64; function lowbit(x:longint):longint;
begin
exit(x and (-x));
end; procedure add(x:longint);
begin
while x<=n do
begin
c[x]:=c[x]+;
x:=x+lowbit(x);
end;
end; function get(x:longint):int64;
begin
get:=;
while x> do
begin
get:=get+c[x];
x:=x-lowbit(x);
end;
end; procedure update(i:longint);
begin
tree[i].s:=tree[tree[i].l].s+tree[tree[i].r].s;
end; function build(l,r:longint):longint;
var m,q:longint;
begin
inc(t);
if l=r then
exit(t)
else begin
m:=(l+r) shr ;
q:=t;
tree[q].l:=build(l,m);
tree[q].r:=build(m+,r);
exit(q);
end;
end; function insert(l,r,last,x,y:longint):longint;
var m,q:longint;
begin
inc(t);
if l=r then
begin
tree[t].s:=tree[last].s+y;
exit(t);
end
else begin
m:=(l+r) shr ;
q:=t;
if x<=m then
begin
tree[q].r:=tree[last].r;
last:=tree[last].l;
tree[q].l:=insert(l,m,last,x,y);
end
else begin
tree[q].l:=tree[last].l;
last:=tree[last].r;
tree[q].r:=insert(m+,r,last,x,y);
end;
update(q);
exit(q);
end;
end; function getans(l,r,x,y:longint):longint;
var m,s,i:longint;
begin
if (x<=l) and (y>=r) then
begin
s:=;
for i:= to t2 do
s:=s+tree[d2[i]].s;
for i:= to t1 do
s:=s-tree[d1[i]].s;
exit(s);
end
else begin
m:=(l+r) shr ;
s:=;
if (x<=m) then
begin
inc(d);
for i:= to t1 do
begin
dd1[d,i]:=d1[i];
d1[i]:=tree[d1[i]].l;
end;
for i:= to t2 do
begin
dd2[d,i]:=d2[i];
d2[i]:=tree[d2[i]].l;
end;
s:=s+getans(l,m,x,y);
for i:= to t1 do
d1[i]:=dd1[d,i];
for i:= to t2 do
d2[i]:=dd2[d,i];
dec(d);
end;
if y>m then
begin
for i:= to t1 do
d1[i]:=tree[d1[i]].r;
for i:= to t2 do
d2[i]:=tree[d2[i]].r;
s:=s+getans(m+,r,x,y);
end;
exit(s);
end;
end; function ask(l,r,x,y:longint):longint;
var i:longint;
begin
if r= then exit();
if l=n+ then exit();
if x=n+ then exit();
if y= then exit();
dec(l);
t1:=;
t2:=;
d1[]:=ph[l];
d2[]:=ph[r];
i:=l;
while i> do
begin
if h[i]<> then
begin
inc(t1);
d1[t1]:=h[i];
end;
i:=i-lowbit(i);
end;
i:=r;
while i> do
begin
if h[i]<> then
begin
inc(t2);
d2[t2]:=h[i];
end;
i:=i-lowbit(i);
end;
d:=;
exit(getans(,n,x,y));
end; procedure del(x,y:longint);
begin
while x<=n do
begin
h[x]:=insert(,n,h[x],y,-);
x:=x+lowbit(x);
end;
end; begin
readln(n,m);
for i:= to n do
begin
readln(a[i]);
b[a[i]]:=i;
end;
for i:=n downto do
begin
ans:=ans+get(a[i]-);
add(a[i]);
end;
h[]:=build(,n);
ph[]:=h[];
for i:= to n do
ph[i]:=insert(,n,ph[i-],a[i],);
for i:= to m do
begin
readln(x);
y:=b[x];
writeln(ans);
ans:=ans-ask(,y-,x+,n)-ask(y+,n,,x-);
del(y,x);
end;
end.

bzoj3295的更多相关文章

  1. 【CQOI2011】动态逆序对 BZOJ3295

    Description 对于序列A,它的逆序对数定义为满足i<j,且Ai>Aj的数对(i,j)的个数.给1到n的一个排列,按照某种顺序依次删除m个元素,你的任务是在每次删除一个元素之前统计 ...

  2. 【bzoj3295】 Cqoi2011—动态逆序对

    http://www.lydsy.com/JudgeOnline/problem.php?id=3295 (题目链接) 题意 给出某种排列,按照某种顺序依次删除m个数,在每次删除一个数前统计序列中逆序 ...

  3. 【BZOJ3295】动态逆序对(线段树,树状数组)

    [BZOJ3295]动态逆序对(线段树,树状数组) 题面 Description 对于序列A,它的逆序对数定义为满足iAj的数对(i,j)的个数.给1到n的一个排列,按照某种顺序依次删除m个元素,你的 ...

  4. BZOJ3295 [Cqoi2011]动态逆序对 分治 树状数组

    原文链接http://www.cnblogs.com/zhouzhendong/p/8678185.html 题目传送门 - BZOJ3295 题意 对于序列$A$,它的逆序对数定义为满足$i< ...

  5. 【bzoj3295】动态逆序对

    Portal --> bzoj3295 Solution 虽然说这个可能原本是一道愉快的树套树但是 ​ 没有强制在线并且是三维限制那就大力cdq分治啊! ​ 看到"按照某个顺序依次删除 ...

  6. 【BZOJ3295】[Cqoi2011]动态逆序对 cdq分治

    [BZOJ3295][Cqoi2011]动态逆序对 Description 对于序列A,它的逆序对数定义为满足i<j,且Ai>Aj的数对(i,j)的个数.给1到n的一个排列,按照某种顺序依 ...

  7. BZOJ3295动态逆序对

    一道比较傻的CDQ分治 CDQ: 主要用于解决三位偏序的问题 #include<cstdio> #include<cctype> #include<algorithm&g ...

  8. 【BZOJ3295】动态逆序对(BIT套动态加点线段树)

    题意:对于序列A,它的逆序对数定义为满足i<j,且Ai>Aj的数对(i,j)的个数. 给1到n的一个排列,按照某种顺序依次删除m个元素,你的任务是在每次删除一个元素之前统计整个序列的逆序对 ...

  9. bzoj3295 [Cqoi2011]动态逆序对 cdq+树状数组

    [bzoj3295][Cqoi2011]动态逆序对 2014年6月17日4,7954 Description 对于序列A,它的逆序对数定义为满足i<j,且Ai>Aj的数对(i,j)的个数. ...

  10. bzoj3295 洛谷P3157、1393 动态逆序对——树套树

    题目:bzoj3295 https://www.lydsy.com/JudgeOnline/problem.php?id=3295 洛谷 P3157(同一道题) https://www.luogu.o ...

随机推荐

  1. iOS-UICollectionView自定义布局

    UICollectionView自定义布局 转载: http://answerhuang.duapp.com/index.php/2013/11/20/custom_collection_view_l ...

  2. bootstrap3学习1:响应式布局layout

    在去年的这个时候写过关于bootstrap的相关文章(见:bootstrap2学习1:基本CSS样式),然后就搁置了,原因是因为当时对bootstrap的了解不深,并且当时v2版本对响应式设计的不是非 ...

  3. Encapsulation.

    Access control is often referred to as implementation hiding. Wrapping data and methods within class ...

  4. How to customize authentication to my own set of tables in asp.net web api 2?

    ssuming your table is called AppUser, convert your own AppUser domain object to IUser(using Microsof ...

  5. 解决vim不能使用方向键和退格键问题

    1.使用vi命令时,不能正常编辑文件,使用方向键时老是出现很多字母,或者退格键却变成方向键的功能 只要重装一下vi的依赖包即可完美解决vi编辑器方向键变字母的问题.rpm -e vim-enhance ...

  6. NSDate和NSString的转换及判定是昨天,今天,明天

    用于uidate,picker.. +(NSDate*) convertDateFromString:(NSString*)uiDate{    NSDateFormatter *formatter ...

  7. 几种不同存储形式下的数据挖掘问题[ZZ]

    从原理上说,数据挖掘应该可以应用到任何信息存储方式的知识挖掘中,但是挖掘的挑战性和技术会因为源数据的存储类型的不同而不同.特别是,近年来的研究表明数据挖掘所涉及的数据存储类型越来越丰富,除了一些有通用 ...

  8. 第五篇、 WebSphere8.5的安装

    一.前言 WebSphere Application  Server 是IBM企业级应用服务器,与WAS6,WAS7相比较而言 WAS8发生了很大的改变,其安装介质和以前截然不同,该篇章中对于不同的安 ...

  9. Fedora上配置一个安全FTP

    现在流行的FTP服务器,比较著名的有WU-FTP(Washington University FTP)和VSFTP(Very Secure FTP 非常安全的FTP)以及Proftp,pureftp等 ...

  10. ubuntu 安装 open in teminal

    sudo apt-get install nautilus-open-terminalnautilus -q