因为题目中要求使连续死亡的机器人最多,令人联想到二分答案。

考虑如何检验这之中是否存在一段连续的长度为md的区间,其中花最多k步使得它们都死亡。

这个条件等价于区间中m个最大值的和不超过k。

枚举起点,可以用 $ O(mlogn) $ 的时间确定这段区间是否合法,最终check的复杂度是 $ O(nmlogn) $。

总复杂度是 $ O(nmlog^{2}n) $。

$ \bigodot $ 技巧&套路:

  • 最大(小)值的问题,可以考虑二分答案。
  • check时用线段树优化区间平移,来枚举每一个长度固定的区间。
 #include <cstdio>
#include <iostream>
#include <algorithm> const int N = ; int n, m, k, re;
int a[N][], ans[], tmp[]; namespace SE {
int ma[][N << ];
inline void Up(int t) {
for (int i = ; i <= m; ++i) {
ma[i][t] = std::max(ma[i][t << ], ma[i][t << | ]);
}
}
void Build(int t, int l, int r) {
if (l == r) {
for (int i = ; i <= m; ++i) ma[i][t] = a[l][i];
return;
}
int md = (l + r) >> ;
Build(t << , l, md);
Build(t << | , md + , r);
Up(t);
}
int Query(int t, int l, int r, int L, int R, int ty) {
if (L <= l && r <= R) return ma[ty][t];
int md = (l + r) >> , re = ;
if (L <= md) re = std::max(re, Query(t << , l, md, L, R, ty));
if (md < R) re = std::max(re, Query(t << | , md + , r, L, R, ty));
return re;
}
} inline int Check(int md) {
for (int i = ; i + md - <= n; ++i) {
int sum = ;
for (int j = ; j <= m; ++j) {
tmp[j] = SE::Query(, , n, i, i + md - , j);
sum += tmp[j];
if (sum > k) break;
}
if (sum <= k) {
for (int j = ; j <= m; ++j) ans[j] = tmp[j];
return ;
}
}
return ;
} int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = ; i <= n; ++i) {
for (int j = ; j <= m; ++j) {
scanf("%d", &a[i][j]);
}
}
SE::Build(, , n);
for (int nl = , nr = n, md; nl <= nr; ) {
md = (nl + nr) >> ;
if (Check(md)) {
re = md; nl = md + ;
} else {
nr = md - ;
}
}
if (re) Check(re);
for (int i = ; i <= m; ++i) {
printf("%d ", (re)? ans[i] : );
} return ;
}

【Cf #291 B】R2D2 and Droid Army(二分,线段树)的更多相关文章

  1. (困难) CF 484E Sign on Fence,整体二分+线段树

    Bizon the Champion has recently finished painting his wood fence. The fence consists of a sequence o ...

  2. Codeforces 514 D R2D2 and Droid Army(Trie树)

    题目链接 大意是判断所给字符串组中是否存在与查询串仅一字符之差的字符串. 关于字符串查询的题,可以用字典树(Trie树)来解,第一次接触,做个小记.在查询时按题目要求进行查询. 代码: #define ...

  3. Codeforces Round #291 (Div. 2) D. R2D2 and Droid Army [线段树+线性扫一遍]

    传送门 D. R2D2 and Droid Army time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  4. R2D2 and Droid Army(多棵线段树)

    R2D2 and Droid Army time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. HDU4614 Vases and Flowers 二分+线段树

    分析:感觉一看就是二分+线段树,没啥好想的,唯一注意,当开始摆花时,注意和最多能放的比大小 #include<iostream> #include<cmath> #includ ...

  6. J - Joseph and Tests Gym - 102020J (二分+线段树)

    题目链接:https://cn.vjudge.net/contest/283920#problem/J 题目大意:首先给你n个门的高度,然后q次询问,每一次询问包括两种操作,第一种操作是将当前的门的高 ...

  7. Educational Codeforces Round 61 D 二分 + 线段树

    https://codeforces.com/contest/1132/problem/D 二分 + 线段树(弃用结构体型线段树) 题意 有n台电脑,只有一个充电器,每台电脑一开始有a[i]电量,每秒 ...

  8. 【BZOJ-3110】K大数查询 整体二分 + 线段树

    3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 6265  Solved: 2060[Submit][Sta ...

  9. hdu6070 Dirt Ratio 二分+线段树

    /** 题目:hdu6070 Dirt Ratio 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6070 题意:给定n个数,求1.0*x/y最小是多少.x ...

  10. K-th occurrence HDU - 6704 (后缀数组+二分线段树+主席树)

    大意: 给定串s, q个询问(l,r,k), 求子串s[l,r]的第kk次出现位置. 这是一篇很好的题解: https://blog.csdn.net/sdauguanweihong/article/ ...

随机推荐

  1. 2.深入解析数据类型与变量——《Excel VBA 程序开发自学宝典》

    2.1 数据类型 数据类型 所占字节 Byte 1 Boolean 2 Integer 2 Long 4 Single 4 Double 8 Currency 8 Decimal 14 Date 8 ...

  2. CF 675E Trains and Statistic

    草稿和一些题解而已 因为指针太恶心了 所以query决定还是要试试自己yy一下 #include<cstdio> #include<cstring> #include<i ...

  3. v-if、v-show 指令

    HTML部分: <div id="app"> <button type="button" @click="flag=!flag&qu ...

  4. CocoStuff—基于Deeplab训练数据的标定工具【五、训练成果分析】

    一.说明 本文为系列博客第五篇,主要展示训练的结果,以及对训练进行分析. *注:暂未进行大量的数据训练以及IoU测算,目前只做到使用Matlab将训练结果的mat文件可视化. 二. *占坑

  5. flex布局时,内容区域自适应高度

    页面元素高度固定,中间的元素需要撑满屏幕,或者内容多时显示滚动条时,我们要把父元素设置为height:100vh <div class="parent"> <di ...

  6. C++ 类 构造函数 constructor

    构造函数 当定义了一个整型变量: int a; 这会申请了一块内存空间来存储a,但是这块内存中原本有数据的,可能是任何值,这不是你所希望的,若你就希望a表示1,所以要把a的值赋值为1. ; 例: #i ...

  7. 关于如何使用Microsoft Word发博客

    关于如何使用Microsoft Word发博客   PS:以Microsoft Word 2010为例作具体操作,实际上Microsoft Word 2007也可以完成该功能,略有差异,但是只能是20 ...

  8. 使用switchPage.js插件jQuery全屏滚动翻页

    1. 先引入jquery.js,再引入switchPage.js 文件地址:点击打开链接 <script src="jquery.min.js"></script ...

  9. Sprint4

    进展:今天一天满课,晚上也没有做什么,所以今天一天没什么进展. 燃尽图:

  10. Servlet 3.0 对异步处理的支持

    Servlet 3.0 实现了对异步处理的支持 通过利用注解@WebServlet(urlPatterns="/AServlet" AysnsSupported=true) 让后n ...