HDU 5700 区间交 线段树暴力
枚举左端点,然后在线段树内,更新所有左边界小于当前点的区间的右端点,然后查线段树二分查第k大就好
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = ;
LL a[N];
struct Node{
int l,r;
bool operator<(const Node &rhs)const{
if(l==rhs.l)return r<rhs.r;
return l<rhs.l;
}
}p[N];
int c[N<<];
void add(int rt,int l,int r,int x){
++c[rt];
if(l==r)return;
int m=(l+r)>>;
if(x<=m)add(rt<<,l,m,x);
else add(rt<<|,m+,r,x);
}
int ask(int rt,int l,int r,int k){
if(l==r)return l;
int m=(l+r)>>;
if(c[rt<<|]>=k)ask(rt<<|,m+,r,k);
else ask(rt<<,l,m,k-c[rt<<|]);
}
int main(){
int n,k,m;
while(~scanf("%d%d%d",&n,&k,&m)){
for(int i=;i<=n;++i){
LL x;scanf("%I64d",&x);
a[i]=a[i-]+x;
}
for(int i=;i<=m;++i){
scanf("%d%d",&p[i].l,&p[i].r);
}
sort(p+,p++m);
memset(c,,sizeof(c));
int cnt=;
LL res=;
for(int i=;i<=m;++i){
for(;cnt<=m&&p[cnt].l<=p[i].l;++cnt)
add(,,n,p[cnt].r);
if(c[]<k)continue;
int cur=ask(,,n,k);
if(cur>=p[i].l)res=max(res,a[cur]-a[p[i].l-]);
}
printf("%I64d\n",res);
}
return ;
}
HDU 5700 区间交 线段树暴力的更多相关文章
- hdu 5700区间交(线段树)
区间交 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...
- HDU 5700 区间交 离线线段树
区间交 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5700 Description 小A有一个含有n个非负整数的数列与m个区间.每个区间可以表示为 ...
- HDU 5700 区间交(线段树)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5700 [题目大意] 给出一个长度为n的数列和m个区间,现在求k个区间,使得他们的区间交内的数列项和 ...
- HDU 5700——区间交——————【线段树+枚举】
区间交 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...
- HDU 5700 区间交
枚举起点 二分终点 树状数组check #include<iostream> #include<cstring> #include<cmath> #include& ...
- HDU 1540 区间合并线段树
题目大意: 就是给定一堆位置,进行删除还原,最后找到 t 位置上的最大连续位置 #include <cstdio> #include <cstring> #include &l ...
- Snacks HDU 5692 dfs序列+线段树
Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...
- 【BZOJ4653】【NOI2016】区间(线段树)
[BZOJ4653][NOI2016]区间(线段树) 题面 BZOJ 题解 \(NOI\)良心送分题?? 既然是最大长度减去最小长度 莫名想到那道反复减边求最小生成树 从而求出最小的比值 所以这题的套 ...
- BZOJ_4653_[Noi2016]区间_线段树+离散化+双指针
BZOJ_4653_[Noi2016]区间_线段树+离散化+双指针 Description 在数轴上有 n个闭区间 [l1,r1],[l2,r2],...,[ln,rn].现在要从中选出 m 个区间, ...
随机推荐
- bnuoj 1053 EASY Problem (计算几何)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=1053 [题意]:基本上就是求直线与圆的交点坐标 [题解]:这种题我都比较喜欢用二分,三分做,果然可以 ...
- The 5th Zhejiang Provincial Collegiate Programming Contest------ProblemK:Kinds of Fuwas
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1974 题意:问四个角都有同一个福娃的矩形有多少个. #include<b ...
- dijkstra,bellman-ford,floyd分析比较
http://www.cnblogs.com/mengxm-lincf/archive/2012/02/11/2346288.html 其实我一直存在疑惑是什么导致dijkstra不能处理负权图? 今 ...
- KafkaSpout的处理流程
基于0.93版本Storm 首先,如果自己写KafkaSpout,该怎么办?有哪些地方需要考虑呢 1. 得实现Storm指定的接口.这样Storm才能够使用它.那么需要实现什么接口?需要提供什么功能给 ...
- POJ3034+DP
题意:给定一个N*N的矩阵, 然后在这个矩阵的每个格子在任意时间会出现一个鼹鼠,这个出现 出现鼹鼠的时间是输出信息所确定的. 现在你手里有一把锤子能够去锤这些鼹鼠. 你能 够移动锤子, ...
- hdu 1847 Good Luck in CET-4 Everybody! 博弈论
方法一:找规律,很容易知道 #include<stdio.h> int main(){ int n; while(scanf("%d",&n)!=EOF){ p ...
- 李洪强iOS开发本人集成环信的经验总结_06_发送好友请求
李洪强iOS开发本人集成环信的经验总结_06_发送好友请求 同步好友请求 异步好友请求
- Web开发的绝美网站
http://paranimage.com/ http://sixrevisions.com/graphics-design/
- 212. Word Search II
题目: Given a 2D board and a list of words from the dictionary, find all words in the board. Each word ...
- Fisher's exact test( 费希尔精确检验)
Fisher's exact test[1][2][3] is a statistical significance test used in the analysis ofcontingency t ...