bzoj3295
没什么好说的,树套树应该随便搞
我在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的更多相关文章
- 【CQOI2011】动态逆序对 BZOJ3295
Description 对于序列A,它的逆序对数定义为满足i<j,且Ai>Aj的数对(i,j)的个数.给1到n的一个排列,按照某种顺序依次删除m个元素,你的任务是在每次删除一个元素之前统计 ...
- 【bzoj3295】 Cqoi2011—动态逆序对
http://www.lydsy.com/JudgeOnline/problem.php?id=3295 (题目链接) 题意 给出某种排列,按照某种顺序依次删除m个数,在每次删除一个数前统计序列中逆序 ...
- 【BZOJ3295】动态逆序对(线段树,树状数组)
[BZOJ3295]动态逆序对(线段树,树状数组) 题面 Description 对于序列A,它的逆序对数定义为满足iAj的数对(i,j)的个数.给1到n的一个排列,按照某种顺序依次删除m个元素,你的 ...
- BZOJ3295 [Cqoi2011]动态逆序对 分治 树状数组
原文链接http://www.cnblogs.com/zhouzhendong/p/8678185.html 题目传送门 - BZOJ3295 题意 对于序列$A$,它的逆序对数定义为满足$i< ...
- 【bzoj3295】动态逆序对
Portal --> bzoj3295 Solution 虽然说这个可能原本是一道愉快的树套树但是 没有强制在线并且是三维限制那就大力cdq分治啊! 看到"按照某个顺序依次删除 ...
- 【BZOJ3295】[Cqoi2011]动态逆序对 cdq分治
[BZOJ3295][Cqoi2011]动态逆序对 Description 对于序列A,它的逆序对数定义为满足i<j,且Ai>Aj的数对(i,j)的个数.给1到n的一个排列,按照某种顺序依 ...
- BZOJ3295动态逆序对
一道比较傻的CDQ分治 CDQ: 主要用于解决三位偏序的问题 #include<cstdio> #include<cctype> #include<algorithm&g ...
- 【BZOJ3295】动态逆序对(BIT套动态加点线段树)
题意:对于序列A,它的逆序对数定义为满足i<j,且Ai>Aj的数对(i,j)的个数. 给1到n的一个排列,按照某种顺序依次删除m个元素,你的任务是在每次删除一个元素之前统计整个序列的逆序对 ...
- bzoj3295 [Cqoi2011]动态逆序对 cdq+树状数组
[bzoj3295][Cqoi2011]动态逆序对 2014年6月17日4,7954 Description 对于序列A,它的逆序对数定义为满足i<j,且Ai>Aj的数对(i,j)的个数. ...
- bzoj3295 洛谷P3157、1393 动态逆序对——树套树
题目:bzoj3295 https://www.lydsy.com/JudgeOnline/problem.php?id=3295 洛谷 P3157(同一道题) https://www.luogu.o ...
随机推荐
- C# 日期字符串转成javascript日期
1.c# date to js date var csharpStr='/Date(1479694396330)/'; //替换掉非数字 csharpStr=csharpStr.replace(/[^ ...
- angular应用前景
完成了angularJs的学习,突然想到,angularJS是否会影响到seo.于是查阅了很多资料,技术博客,这种想法得到了证实. 爬虫不能识别js渲染的内容.所以引起了我对angular应用前景的思 ...
- 使用Convert 类和Parse方法将字符串转换为数值类型
//用Parse方法将字符串转换为数值类型; long num=Int64.Parse(args[2]) //用别名为Int64c#类型long; long num=long.Parse(args[2 ...
- JavaScript Window - 浏览器对象模型
浏览器对象模型 (BOM) 使 JavaScript 有能力与浏览器"对话". 浏览器对象模型 (BOM) 浏览器对象模型(Browser Object Model (BOM))尚 ...
- C# Dll动态链接库
新建一个类库. 2 编写一个简单的类库实例,例如:DllTest在默认名为:calss1.cs里编写代码一下是一个简单的:在控制台显示 “你以成功调用了动态连接!”sing System;us ...
- Python:if-while-for
#!/usr/bin/python3 #if elif else print("开始猜数字游戏") num = int(input("请输入数字")) stan ...
- mac 下maven的安装
最近在学习mahout,这些安装相关软件的步骤先记下来,避免以后忘记. 1.首先在mac上查看本机的java版本,如果没有需要自己去安装: 我的电脑上安装的java是1.7.0_79 2.在http: ...
- Bootstrap_表单_图标
在Bootstrap框架中是通过给元素添加“glyphicon”类名来实现,然后通过伪元素“:before”的“content”属性调取对应的icon编码: <span class=" ...
- openerp report image
webkit : 再mako 文件中插入以下代码, <% %>标签用于再mako中定义代码或者函数. 然后 ${ embed_image('图片类型', 图片字段 , 宽度,高度) } ...
- 得到某个进程所有线程ID和入口地址
#include <windows.h> #include <tlhelp32.h> #include "iostream" using namespace ...