【Tyvj1601】魔兽争霸(主席树,树套树)
题意:要求在N个数的序列中支持以下操作:
1:将第X个元素加上Y
2:询问当前K大值
n<=30000,m<=50000
思路:树状数组套主席树
Tyvj又炸了,还不知道对不对
var t:array[..12]of record
l,r,s:longint;
end;
d:array[..,..]of longint;
a,save,q,root,hash:array[..]of longint;
b:array[..]of longint;
n,m,i,j,x,cnt,u,que,s,sum,tmp,len:longint;
ch:string; function lowbit(x:longint):longint;
begin
exit(x and (-x));
end; procedure update(l,r:longint;var p:longint;x,v:longint);
var mid:longint;
begin
inc(cnt); t[cnt]:=t[p];
p:=cnt; t[p].s:=t[p].s+v;
if l=r then exit;
mid:=(l+r)>>;
if x<=mid then update(l,mid,t[p].l,x,v)
else update(mid+,r,t[p].r,x,v);
end; function query(l,r,k:longint):longint;
var mid,s,i:longint;
begin
if l=r then exit(l);
s:=;
mid:=(l+r)>>;
for i:= to len do s:=s+t[t[q[i]].l].s;
if s>=k then
begin
for i:= to len do q[i]:=t[q[i]].l;
exit(query(l,mid,k));
end
else
begin
for i:= to len do q[i]:=t[q[i]].r;
exit(query(mid+,r,k-s));
end;
end; procedure swap(var x,y:longint);
var t:longint;
begin
t:=x; x:=y; y:=t;
end; procedure qsort(l,r:longint);
var i,j,mid:longint;
begin
i:=l; j:=r; mid:=b[(l+r)>>];
repeat
while mid<b[i] do inc(i);
while mid>b[j] do dec(j);
if i<=j then
begin
swap(b[i],b[j]);
inc(i); dec(j);
end;
until i>j;
if l<j then qsort(l,j);
if i<r then qsort(i,r);
end; function find(x:longint):longint;
var l,r,mid:longint;
begin
l:=; r:=u;
while l<=r do
begin
mid:=(l+r)>>;
if hash[mid]=x then exit(mid);
if hash[mid]>x then l:=mid+
else r:=mid-;
end;
end; begin
assign(input,'tyvj1601.in'); reset(input);
assign(output,'tyvj1601.out'); rewrite(output);
readln(n);
for i:= to n do
begin
read(a[i]); b[i]:=a[i];
end;
que:=n;
for i:= to n do save[i]:=a[i];
readln(m);
for i:= to m do
begin
readln(ch); x:=;
if ch[]='Q' then
begin
for j:= to length(ch) do x:=x*+ord(ch[j])-ord('');
d[i,]:=; d[i,]:=x; continue;
end;
d[i,]:=; s:=;
for j:= to length(ch) do
begin
if ch[j]=' ' then inc(s)
else d[i,s]:=d[i,s]*+ord(ch[j])-ord('');
end;
if ch[]='A' then d[i,]:=-d[i,];
end;
for i:= to m do
if d[i,]= then
begin
a[d[i,]]:=a[d[i,]]+d[i,];
if a[d[i,]]> then
begin
inc(que); b[que]:=a[d[i,]];
end;
end;
qsort(,que);
hash[]:=b[]; u:=;
for i:= to que do
if b[i]<>b[i-] then begin inc(u); hash[u]:=b[i]; end;
sum:=n;
for i:= to n do
begin
tmp:=find(save[i]);
j:=i;
while j<=n do
begin
update(,u,root[j],tmp,);
j:=j+lowbit(j);
end;
end;
for i:= to m do
if d[i,]= then
begin
len:=; j:=n;
while j> do
begin
inc(len); q[len]:=root[j];
j:=j-lowbit(j);
end;
if sum<d[i,] then writeln(-)
else writeln(hash[query(,u,d[i,])]);
end
else
begin
tmp:=find(save[d[i,]]);
j:=d[i,];
while j<=n do
begin
update(,u,root[j],tmp,-);
j:=j+lowbit(j);
end;
save[d[i,]]:=save[d[i,]]+d[i,];
if save[d[i,]]> then
begin
tmp:=find(save[d[i,]]);
j:=d[i,];
while j<=n do
begin
update(,u,root[j],tmp,);
j:=j+lowbit(j);
end;
end
else dec(sum);
end; writeln(sum);
close(input);
close(output);
end.
【Tyvj1601】魔兽争霸(主席树,树套树)的更多相关文章
- 洛谷P2617 Dynamic Ranking(主席树,树套树,树状数组)
洛谷题目传送门 YCB巨佬对此题有详细的讲解.%YCB%请点这里 思路分析 不能套用静态主席树的方法了.因为的\(N\)个线段树相互纠缠,一旦改了一个点,整个主席树统统都要改一遍...... 话说我真 ...
- [luogu2617][bzoj1901][Zju2112]Dynamic Rankings【树套树+树状数组+主席树】
题目网址 [传送门] 题目大意 请你设计一个数据结构,支持单点修改,区间查询排名k. 感想(以下省略脏话inf个字) 真的强力吹爆洛谷数据,一般的树套树还给我T了一般的点,加强的待修主席树还给我卡了几 ...
- 【bzoj1901】dynamic ranking(带修改主席树/树套树)
题面地址(权限题) 不用权限题的地址 首先说说怎么搞带修改主席树? 回忆一般的kth问题,我们的主席树求的是前缀和,这样我们在目标区间的左右端点的主席树差分下就能求出kth. 那么我们如何支持修改操作 ...
- ZOJ - 2112 主席树套树状数组
题意:动态第k大,可单点更新,操作+原数组范围6e4 年轻人的第一道纯手工树套树 静态第k大可以很轻易的用权值主席树作差而得 而动态第k大由于修改第i个数会影响[i...n]棵树,因此我们不能在原主席 ...
- [bzoj3196][Tyvj1730]二逼平衡树_树套树_位置线段树套非旋转Treap/树状数组套主席树/权值线段树套位置线段树
二逼平衡树 bzoj-3196 Tyvj-1730 题目大意:请写出一个维护序列的数据结构支持:查询给定权值排名:查询区间k小值:单点修改:查询区间内定值前驱:查询区间内定值后继. 注释:$1\le ...
- BZOJ 1146: [CTSC2008]网络管理Network 带修改主席树_树套树_DFS序
Description M公司是一个非常庞大的跨国公司,在许多国家都设有它的下属分支机构或部门.为了让分布在世界各地的N个 部门之间协同工作,公司搭建了一个连接整个公司的通信网络.该网络的结构由N个路 ...
- zoj2112 Dynamic Rankings (主席树 || 树套树)
The Company Dynamic Rankings has developed a new kind of computer that is no longer satisfied with t ...
- 【BZOJ】1901: Zju2112 Dynamic Rankings(区间第k小+树套树)
http://www.lydsy.com/JudgeOnline/problem.php?id=1901 这题调了我相当长的时间,1wa1a,我是第一次写树套树,这个是树状数组套splay,在每个区间 ...
- Uva 3767 Dynamic len(set(a[L:R])) 树套树
Dynamic len(set(a[L:R])) Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 https://uva.onlinejudge.org/in ...
- 「洛谷1903」「BZOJ2120」「国家集训队」数颜色【带修莫队,树套树】
题目链接 [BZOJ传送门] [洛谷传送门] 题目大意 单点修改,区间查询有多少种数字. 解法1--树套树 可以直接暴力树套树,我比较懒,不想写. 稍微口胡一下,可以直接来一个树状数组套主席树,也就是 ...
随机推荐
- pclint vc6/linux 工程,测试正常
下载:http://www.gimpel.compojie版搜索一下很好找 里面有vc6 和linux工程的lnt文件,实际使用可能要修改. http://files.cnblogs.com/file ...
- Downloader调用WCF服务返回文件
Generator using System; using System.Collections.Generic; using System.IO; namespace Downloader { pu ...
- java 集合的使用 (一)
1.使用整型列表 List<int> lstInt=new List<int>(); 结果不对,报的错误是:Syntax error, insert "Dimensi ...
- perl读取文件
1)文件读取的3中方法 按行读,存入标量 while (<FILE>) { print; } 按行读,存入数组 @array = <FILE>; 读入整个文件 ,存入标量 ...
- Perl Sort函数用法总结和使用实例
一) sort函数用法 sort LISTsort BLOCK LISTsort SUBNAME LIST sort的用法有如上3种形式.它对LIST进行排序,并返回排序后的列表.假如忽略了SUBNA ...
- [MongoDB] 高可用架构方案
一.缘由: 众所周知,Mongodb是在高速发展期,一些特性架构难免会发生变化.这里就总结下,我目前所知道的Mongodb 的高可用架构都有哪些.目前Mongodb版本3.2. 二.结构介绍: 1.R ...
- ASP.NET中进行消息处理(MSMQ) 三(转)
在本文的前两篇文章里对MSMQ的相关知识点进行了介绍,很多阅读过这前两篇文章的朋友都曾问到过这样一些问题: 1.如何把MSMQ应用到实际的项目中去呢? 2.可不可以介绍一个实际的应用实例? 3. ...
- the philosophy behind of the design of the STL
The concept of STL is based on a separation of data and operations. The data is managed by container ...
- python3实现简单爬虫功能
本文参考虫师python2实现简单爬虫功能,并增加自己的感悟. #coding=utf-8 import re import urllib.request def getHtml(url): page ...
- [Appium] 使用Appium过程中遇到的各种坑
以下问题都是以ios为背景: 1. 问题: Case: 在页面S1上,点击元素A后,判读B元素是否出现. Detail:一开始通过Appium Inspector, 可以找到B元素,所以直接取该元素的 ...