二合一……

#include <iostream>
#include <cstdio>
using namespace std;
int r, c, m, a[205][205], val[205][205][1005], num[205][205][1005];
int xu, yu, xv, yv, hi, rot[500005], lson[7200005], rson[7200005];
int sum[7200005], siz[7200005], cnt, w[500005];
int getVal(int xu, int yu, int xv, int yv, int hi){
return val[xv][yv][hi]-val[xu-1][yv][hi]-val[xv][yu-1][hi]+val[xu-1][yu-1][hi];
}
int getNum(int xu, int yu, int xv, int yv, int hi){
return num[xv][yv][hi]-num[xu-1][yv][hi]-num[xv][yu-1][hi]+num[xu-1][yu-1][hi];
}
void work1(){
for(int i=1; i<=r; i++)
for(int j=1; j<=c; j++)
scanf("%d", &a[i][j]);
for(int k=1; k<=1000; k++)
for(int i=1; i<=r; i++)
for(int j=1; j<=c; j++){
val[i][j][k] = val[i-1][j][k] + val[i][j-1][k] - val[i-1][j-1][k] + ((a[i][j]>=k)?a[i][j]:0);
num[i][j][k] = num[i-1][j][k] + num[i][j-1][k] - num[i-1][j-1][k] + ((a[i][j]>=k)?1:0);
}
while(m--){
scanf("%d %d %d %d %d", &xu, &yu, &xv, &yv, &hi);
if(getVal(xu, yu, xv, yv, 1)<hi) printf("Poor QLW\n");
else{
int l=1, r=1000, mid, ans;
while(l<=r){
mid = (l + r) >> 1;
if(getVal(xu, yu, xv, yv, mid)>=hi){
ans = mid;
l = mid + 1;
}
else r = mid - 1;
}
ans = getNum(xu, yu, xv, yv, ans) - (getVal(xu, yu, xv, yv, ans)-hi) / ans;//并不是说>=ans的都要选,==ans的只选一部分
printf("%d\n", ans);
}
}
}
int build(int l, int r){
int rt=++cnt;
int mid=(l+r)>>1;
if(l==r) return rt;
if(l<=mid) lson[rt] = build(l, mid);
if(mid<r) rson[rt] = build(mid+1, r);
return rt;
}
int update(int pre, int l, int r, int x){
int rt=++cnt;
int mid=(l+r)>>1;
lson[rt] = lson[pre]; rson[rt] = rson[pre];
siz[rt] = siz[pre] + 1;
sum[rt] = sum[pre] + x;
if(l==r) return rt;
if(x<=mid) lson[rt] = update(lson[pre], l, mid, x);
if(mid<x) rson[rt] = update(rson[pre], mid+1, r, x);
return rt;
}
int query(int qwq, int qaq, int l, int r, int h){
int mid=(l+r)>>1;
int tmp=sum[rson[qaq]]-sum[rson[qwq]];
if(l==r) return (h%l==0)?(h/l):(h/l+1);
if(h<=tmp) return query(rson[qwq], rson[qaq], mid+1, r, h);
else return query(lson[qwq], lson[qaq], l, mid, h-tmp)+siz[rson[qaq]]-siz[rson[qwq]];
}
void work2(){
for(int i=1; i<=c; i++)
scanf("%d", &w[i]);
rot[0] = build(1, 1000);
for(int i=1; i<=c; i++)
rot[i] = update(rot[i-1], 1, 1000, w[i]);
while(m--){
scanf("%d %d %d %d %d", &xu, &yu, &xv, &yv, &hi);
if(sum[rot[yv]]-sum[rot[yu-1]]<hi) printf("Poor QLW\n");
else printf("%d\n", query(rot[yu-1], rot[yv], 1, 1000, hi));
}
}
int main(){
cin>>r>>c>>m;
if(r!=1) work1();
else work2();
return 0;
}

luogu2468 [SDOI2010]粟粟的书架的更多相关文章

  1. bzoj1926[Sdoi2010]粟粟的书架 二分 主席树

    1926: [Sdoi2010]粟粟的书架 Time Limit: 30 Sec  Memory Limit: 552 MBSubmit: 1064  Solved: 421[Submit][Stat ...

  2. bzoj 1926: [Sdoi2010]粟粟的书架 (主席树+二分)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1926 题面; 1926: [Sdoi2010]粟粟的书架 Time Limit: 30 Se ...

  3. [bzoj1926][Sdoi2010]粟粟的书架_二分_主席树

    粟粟的书架 bzoj-1926 Sdoi-2010 题目大意:题目链接 注释:略 想法:分成两个题 前面的我们可以二分,直接二分出来检验即可. 对于R=1的,相当一个数列,我们在上面建立主席树. 然后 ...

  4. Bzoj 1926: [Sdoi2010]粟粟的书架(二分答案+乱搞+主席树)

    1926: [Sdoi2010]粟粟的书架 Time Limit: 30 Sec Memory Limit: 552 MB Description 幸福幼儿园 B29 班的粟粟是一个聪明机灵.乖巧可爱 ...

  5. [SDOI2010]粟粟的书架 [主席树]

    [SDOI2010]粟粟的书架 考虑暴力怎么做 显然是提取出来 (x2-x1+1)*(y2-y1+1) 个数字拿出来 然后从大到小排序 然后就可以按次取数了- 然而接下来看数据范围 \(50\%\ r ...

  6. [BZOJ1926][SDOI2010]粟粟的书架

    BZOJ Luogu Description 幸福幼儿园 B29 班的粟粟是一个聪明机灵.乖巧可爱的小朋友,她的爱好是画画和读书,尤其喜欢 Thomas H. Cormen 的文章.粟粟家中有一个 R ...

  7. BZOJ1926[Sdoi2010]粟粟的书架——二分答案+主席树

    题目描述 幸福幼儿园 B29 班的粟粟是一个聪明机灵.乖巧可爱的小朋友,她的爱好是画画和读书,尤其喜欢 Thomas H. Co rmen 的文章.粟粟家中有一个 R行C 列的巨型书架,书架的每一个位 ...

  8. 【刷题】BZOJ 1926 [Sdoi2010]粟粟的书架

    Description 幸福幼儿园 B29 班的粟粟是一个聪明机灵.乖巧可爱的小朋友,她的爱好是画画和读书,尤其喜欢 Thomas H. Cormen 的文章.粟粟家中有一个 R行C 列的巨型书架,书 ...

  9. BZOJ1926:[SDOI2010]粟粟的书架——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1926 https://www.luogu.org/problemnew/show/P2468 幸福幼 ...

  10. 【BZOJ1926】【SDOI2010】粟粟的书架 [主席树]

    粟粟的书架 Time Limit: 30 Sec  Memory Limit: 552 MB[Submit][Status][Discuss] Description 幸福幼儿园 B29 班的粟粟是一 ...

随机推荐

  1. Jumping on Walls CodeForces - 198B

    Jumping on Walls CodeForces - 198B 应该是一个隐式图的bfs,或者叫dp. 先是一个TLE的O(nklogn) #include<cstdio> #inc ...

  2. oracle中的用户详解 【转】

      oracle中的用户很多,也很令初学者费解.oracle中的帐户分为两类:一类是必需的帐户,一类是存储各种应用的帐户 用户名 密码 描述 ANONYMOUS ANONYMOUS 访问http的匿名 ...

  3. HDU 5778 abs 数学

    http://acm.hdu.edu.cn/showproblem.php?pid=5778 这题的意思就是找离x最近的一个数y,且y是一个完全平方数,还是所有质因子都只能出现两次的完全平方数 一开始 ...

  4. python2和python3的区别(转)

    基本语法差异 核心类差异 Python3对Unicode字符的原生支持 Python2中使用 ASCII 码作为默认编码方式导致string有两种类型str和unicode,Python3只支持uni ...

  5. wkWebView 的一些问题

    导语 WKWebView 是苹果在 WWDC 2014 上推出的新一代 webView 组件,用以替代 UIKit 中笨重难用.内存泄漏的 UIWebView.WKWebView 拥有60fps滚动刷 ...

  6. spark性能优化-JVM虚拟机垃圾回收调优

    1 2 3 4

  7. 如何用Chrome自带的截屏功能截取超过一个屏幕的网页

    提升程序员工作效率的工具/技巧推荐系列 推荐一个功能强大的文件搜索工具SearchMyFiles 介绍一个好用的免费流程图和UML绘制软件-Diagram Designer 介绍Windows任务管理 ...

  8. PHP一句话后门过狗姿势万千之后门构造与隐藏

    第二章节主要带给大家一些后门构造思路,与安全狗文件特征检测的机制. 另外强调一下,这篇文章需要大家对于php有一定的认识. 本章节分为三大部分,第一部分针对初级,分析菜刀php代码的执行过程,较基础: ...

  9. hdu5739Fantasia(多校第二场1006) 割点+逆元

    Fantasia Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Proble ...

  10. DROP CAST - 删除一个用户定义的类型转换

    SYNOPSIS DROP CAST (sourcetype AS targettype) [ CASCADE | RESTRICT ] DESCRIPTION 描述 DROP CAST 删除一个前面 ...