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

考虑如何检验这之中是否存在一段连续的长度为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. Python浮点算术:争议和限制

    浮点数在计算机硬件中表示为以 2 为基数(二进制)的小数.举例而言,十进制的小数 0.125 等于 1/10 + 2/100 + 5/1000 ,同理,二进制的小数 0.001 等于0/2 + 0/4 ...

  2. oracle数据库之rownum和rowid用法

    Rownum 和 Rowid是Oracle数据库所特有的,通过他们可以查询到指定行数范围内的数据记录.   以下通过例子讲解: -- 为了方便,首先,查找dept表中的所有. select deptn ...

  3. thymeleaf 使用javascript定义数组报错

    js中免不了的要用的数组,一维的二维的三维的 但是当用到thymeleaf作为模版时候会有一些坑,导致数组不能用 org.thymeleaf.exceptions.TemplateProcessing ...

  4. Codeforces1151E,F | 553Div2 | 瞎讲报告

    传送链接 E. Number of Components 当时思博了..一直在想对于\([1,r]\)的联通块和\([1,l-1]\)的联通块推到\([l,r]\)的联通块...我真的是傻了..这题明 ...

  5. 笨办法学Python - 习题3: Numbers and Math

    目录 习题 3: 数字和数学计算 算术运算符 加分习题: 我的答案: 总结: 扩展: Python比较运算符 Python赋值运算符 Python位运算符 Python逻辑运算符 Python成员运算 ...

  6. SQL中读取Excel 以及 bpc语言

    --开启导入功能 reconfigure reconfigure --允许在进程中使用ACE.OLEDB.12 --允许动态参数 EXEC master.dbo.sp_MSset_oledb_prop ...

  7. 第十周psp作业

    本周psp 本周进度条 代码累积折线图 博文字数累积折线图 饼状图

  8. “私人助手”Beta版使用说明

    私人助手(Beta)版使用说明 私人助手这款软件是通过添加事件提醒功能,让用户能在正确的时间做正确的事情,使得工作变得更有效率,而这款软件的特色在于提醒模式的添加,用户可以通过震动.铃声提醒,我们的特 ...

  9. 冲刺One之站立会议6 /2015-5-19

    2015-5-19 今天把服务器端的界面完善了一下,然后大家查了好多资料,实现了登陆界面实际连接的功能,开始加了一个它和服务器的的跳转,但是分析过后发现这是个没有必要的跳转.登录应该直接转到聊天室的主 ...

  10. 文件名命工具类(将指定目录下的文件的type类型的文件,进行重命名,命名后的文件将去掉type)

    import java.io.File; /** * <b>function:</b> 文件命名工具类 * @author hoojo * @createDate 2012-5 ...