HDU 4251 The Famous ICPC Team Again 主席树
The Famous ICPC Team Again
Moreover, when collecting the problems, Mr. B had also known an estimation of each problem’s difficultness. When he was asked to choose a problem, if he chose the easiest one, Mr. G would complain that “Hey, what a trivial problem!”; if he chose the hardest one, Mr. M would grumble that it took too much time to finish it. To address this dilemma, Mr. B decided to take the one with the medium difficulty. Therefore, he needed a way to know the median number in the given interval of the sequence.
5 3 2 4 1
3
1 3
2 4
3 5
5
10 6 4 8 2
3
1 3
2 4
3 5
3
3
2
Case 2:
6
6
4
#include<bits/stdc++.h>
using namespace std; #pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair typedef long long LL;
const long long INF = 1e18;
const double Pi = acos(-1.0);
const int N = 1e5+, M = 1e6+, mod = 1e6+, inf = 2e9; int n,a[N],q,san[N],fsan[N],b[N],c;
struct cooltree{
int root[N],l[N*],r[N*],v[N*];
int sz;
void init()
{
memset(root,,sizeof(root));
memset(l,,sizeof(l));
memset(r,,sizeof(r));
memset(v,,sizeof(v));
sz = ;
}
void update(int &k,int ll,int rr,int x)
{
++sz;
l[sz] = l[k];
r[sz] = r[k];
v[sz] = v[k] + ;
k = sz;
if(ll == rr) return ;
if(x <= mid) update(l[k],ll,mid,x);
else update(r[k],mid+,rr,x);
}
int ask(int x,int y,int k)
{
int ll = , rr = c;
x = root[x-], y = root[y];
while(ll != rr)
{
int md = (ll+rr)>>, now = v[l[y]] - v[l[x]];
if(k <= now) x = l[x], y = l[y], rr = md;
else x = r[x], y = r[y], ll = mid + ,k-=now;
}
return b[ll];
}
}T;
int main() {
int cas = ;
while(scanf("%d",&n)!=EOF) {
T.init();
for(int i = ; i <= n; ++i) scanf("%d",&a[i]), b[i] = a[i];
sort(b+,b+n+);
c = unique(b+,b+n+) - b - ; for(int i = ; i <= n; ++i) san[i] = lower_bound(b+,b+c+,a[i]) - b;
for(int i = ; i <= n; ++i) T.update(T.root[i] = T.root[i-],,c,san[i]); scanf("%d",&q);
printf("Case %d:\n",cas++);
for(int i = ; i <= q; ++i) {
int x,y;
scanf("%d%d",&x,&y);
printf("%d\n",T.ask(x,y,(T.v[T.root[y]] - T.v[T.root[x-]] +)/));
}
}
return ;
}
HDU 4251 The Famous ICPC Team Again 主席树的更多相关文章
- HDU 4251 The Famous ICPC Team Again(划分树)
The Famous ICPC Team Again Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- hdu 4251 The Famous ICPC Team Again划分树入门题
The Famous ICPC Team Again Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDOJ 4251 The Famous ICPC Team Again
划分树水题..... The Famous ICPC Team Again Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 3276 ...
- 【HDOJ】4251 The Famous ICPC Team Again
划分树模板题目,主席树也可解.划分树. /* 4251 */ #include <iostream> #include <sstream> #include <strin ...
- HDU 4247 A Famous ICPC Team
Problem Description Mr. B, Mr. G, Mr. M and their coach Professor S are planning their way to Warsaw ...
- HDU 4729 An Easy Problem for Elfness 主席树
题意: 给出一棵树,每条边有一个容量. 有若干次询问:\(S \, T \, K \, A \, B\),求路径\(S \to T\)的最大流量. 有两种方法可以增大流量: 花费\(A\)可以新修一条 ...
- HDU - 6601 Keen On Everything But Triangle 主席树
Keen On Everything But Triangle 感觉最近多校好多主席树的亚子,但是本人菜得很,还没学过主席树,看着队友写题就只能划水,\(WA\)了还不能帮忙\(debug\),所以深 ...
- HDU 6621"K-th Closest Distance"(二分+主席树)
传送门 •题意 有 $m$ 次询问,每次询问求 $n$ 个数中, $[L,R]$ 区间距 $p$ 第 $k$ 近的数与 $p$ 差值的绝对值: •题解 二分答案,假设当前二分的答案为 $x$,那么如何 ...
- HDU4251-The Famous ICPC Team Again(划分树)
Problem Description When Mr. B, Mr. G and Mr. M were preparing for the 2012 ACM-ICPC World Final Con ...
随机推荐
- 开源工作流 Bonita BPM (JAVA)
Bonita BPM 开源工作流 Bonita BPM (JAVA) http://www.bonitasoft.com/
- 抓取网页内容生成kindle电子书
参考: http://calibre-ebook.com/download_linux http://blog.codinglabs.org/articles/convert-html-to-kind ...
- percona-toolkit 之 【pt-summary】、【pt-mysql-summary】、【pt-config-diff】、【pt-variable-advisor】说明
摘要: 通过下面的这些命令在接触到新的数据库服务器的时候能更好更快的了解服务器和数据库的状况. 1:pt-summary:查看系统摘要报告 执行: pt-summary 打印出来的信息包括:CPU.内 ...
- ffmpeg-20160714-git-bin.7z
ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...
- YY 神曲 李明霖 14部合集
http://pan.baidu.com/s/1i5JIvXV
- 2014 12th GDCPC 总结
这次真的需要好好总结反思.... 5月11日,今天是省赛...开赛前,有个人用麦说“balabala”之类的,终于有用麦讲话了=.=像点样了... 跟昨天热身赛一样,我来开VS,建项目云云... 开赛 ...
- 用原生DOM 遍历页面节点
代码丢失,直接上图:
- WP8图片缩放功能实现
最近在学习WP8,想实现WP微信中查看图片时的放大缩小功能. 网上找了两个解决方案: 1 利用GestureListener 这个类在Microsoft.Phone.Controls.Toolkit中 ...
- SpringMVC java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name
当跳转到一个含有form表单的页面的时候 如<form:form commandName="useCarInfo" 必须要new一个useCarInfo的同名实例给jsp来接 ...
- 【leetcode】 Unique Binary Search Trees (middle)☆
Find the contiguous subarray within an array (containing at least one number) which has the largest ...