Codeforces Round #291 (Div. 2) D. R2D2 and Droid Army [线段树+线性扫一遍]
2 seconds
256 megabytes
standard input
standard output
An army of n droids is lined up in one row. Each droid is described by m integers a1, a2, ..., am, where ai is the number of details of the i-th type in this droid's mechanism. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He has m weapons, the i-th weapon can affect all the droids in the army by destroying one detail of the i-th type (if the droid doesn't have details of this type, nothing happens to it).
A droid is considered to be destroyed when all of its details are destroyed. R2-D2 can make at most k shots. How many shots from the weapon of what type should R2-D2 make to destroy the sequence of consecutive droids of maximum length?
The first line contains three integers n, m, k (1 ≤ n ≤ 105, 1 ≤ m ≤ 5, 0 ≤ k ≤ 109) — the number of droids, the number of detail types and the number of available shots, respectively.
Next n lines follow describing the droids. Each line contains m integers a1, a2, ..., am (0 ≤ ai ≤ 108), where ai is the number of details of the i-th type for the respective robot.
Print m space-separated integers, where the i-th number is the number of shots from the weapon of the i-th type that the robot should make to destroy the subsequence of consecutive droids of the maximum length.
If there are multiple optimal solutions, print any of them.
It is not necessary to make exactly k shots, the number of shots can be less.
5 2 4
4 0
1 2
2 1
0 2
1 3
2 2
3 2 4
1 2
1 3
2 2
1 3
In the first test the second, third and fourth droids will be destroyed.
In the second test the first and second droids will be destroyed.
题解如标题,线段树+线性扫一遍即可~~~
9855946 | 2015-02-15 10:16:13 | njczy2010 | D - R2D2 and Droid Army | GNU C++ | Accepted | 186 ms | 27412 KB |
9855894 | 2015-02-15 10:10:30 | njczy2010 | D - R2D2 and Droid Army | GNU C++ | Wrong answer on test 6 | 15 ms | 27400 KB |
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<string> #define N 100005
#define M 1505
//#define mod 10000007
//#define p 10000007
#define mod2 1000000000
#define ll long long
#define LL long long
#define eps 1e-6
//#define inf 2147483647
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; ll n,m,k;
ll ma;
ll ans[]; typedef struct
{
ll t[];
}PP;
PP a[N];
PP tree[*N]; PP build(ll i,ll l,ll r)
{
//printf(" i=%I64d l=%I64d r=%I64d\n",i,l,r);
if(l==r){
tree[i]=a[l];
return tree[i];
}
PP le,ri;
ll mid=(l+r)/;
le=build(*i,l,mid);
ri=build(*i+,mid+,r);
ll j;
for(j=;j<=m;j++){
tree[i].t[j]=max(le.t[j],ri.t[j]);
}
return tree[i];
} PP query(ll i,ll l,ll r,ll L,ll R)
{
//printf(" i=%I64d l=%I64d r=%I64d L=%I64d R=%I64d\n",i,l,r,L,R);
if(l>=L && r<=R) return tree[i];
ll mid;
mid=(l+r)/;
PP le,ri,re;
ll j;
for(j=;j<=m;j++){
le.t[j]=ri.t[j]=;
}
if(mid>=L){
le=query(i*,l,mid,L,R);
}
if(mid<R){
ri=query(i*+,mid+,r,L,R);
}
for(j=;j<=m;j++){
re.t[j]=max(le.t[j],ri.t[j]);
}
return re;
} void ini()
{
memset(ans,,sizeof(ans));
ma=;
ll i,j;
for(i=;i<=n;i++){
for(j=;j<=m;j++){
scanf("%I64d",&a[i].t[j]);
}
}
//printf(" bb\n");
build(,,n);
} void solve()
{
ll st,en;
st=;
en=;
ll now=;
PP re;
ll j;
for(j=;j<=m;j++){
re.t[j]=;
}
while(en<n)
{
en++;
now=;
for(j=;j<=m;j++){
re.t[j]=max(re.t[j],a[en].t[j]);
now+=re.t[j];
}
while(now>k){
st++;
if(st>en){
for(j=;j<=m;j++){
re.t[j]=;
}
break;
}
re=query(,,n,st,en);
now=;
for(j=;j<=m;j++){
now+=re.t[j];
}
//printf(" st=%I64d en=%I64d now=%I64d\n",st,en,now);
}
if(now>k) continue;
// printf(" st=%I64d en=%I64d now=%I64d ma=%I64d\n",st,en,now,ma);
if(en-st+>ma){
ma=en-st+;
for(j=;j<=m;j++){
ans[j]=re.t[j];
}
}
}
} void out()
{
printf("%I64d",ans[]);
ll i;
for(i=;i<=m;i++){
printf(" %I64d",ans[i]);
}
printf("\n");
} int main()
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
//scanf("%d",&T);
//for(int ccnt=1;ccnt<=T;ccnt++)
//while(T--)
//scanf("%d%d",&n,&m);
while(scanf("%I64d%I64d%I64d",&n,&m,&k)!=EOF)
{
ini();
solve();
out();
}
return ;
}
Codeforces Round #291 (Div. 2) D. R2D2 and Droid Army [线段树+线性扫一遍]的更多相关文章
- Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)
题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...
- Codeforces Round #332 (Div. 2) C. Day at the Beach 线段树
C. Day at the Beach Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599/p ...
- Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸
D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)
题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...
- Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake 线段树维护dp
D. Babaei and Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/D Description As you ...
- Codeforces Round #250 (Div. 1) D. The Child and Sequence (线段树)
题目链接:http://codeforces.com/problemset/problem/438/D 给你n个数,m个操作,1操作是查询l到r之间的和,2操作是将l到r之间大于等于x的数xor于x, ...
- Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B. "Or" Game 线段树贪心
B. "Or" Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/578 ...
- Codeforces Round #530 (Div. 2)F Cookies (树形dp+线段树)
题:https://codeforces.com/contest/1099/problem/F 题意:给定一个树,每个节点有俩个信息x和t,分别表示这个节点上的饼干个数和先手吃掉这个节点上一个饼干的的 ...
- Codeforces Round #343 (Div. 2) D - Babaei and Birthday Cake 线段树+DP
题意:做蛋糕,给出N个半径,和高的圆柱,要求后面的体积比前面大的可以堆在前一个的上面,求最大的体积和. 思路:首先离散化蛋糕体积,以蛋糕数量建树建树,每个节点维护最大值,也就是假如节点i放在最上层情况 ...
随机推荐
- LeetCode || 双指针 / 单调栈
11. Container With Most Water 题意:取两根求最大体积 思路:使用两个指针分别指向头和尾,然后考虑左右两根: 对于小的那根,如果选择了它,那么能够产生的最大体积一定是当前的 ...
- 第2节 azkaban调度:17、azkaban的两个服务模式的安装
2.3.3.azkaban两个服务模式安装 1.确认所需软件: Azkaban Web服务安装包 azkaban-web-server-0.1.0-SNAPSHOT.tar.gz Azkaban执行服 ...
- ios 团购信息客户端demo(二)
接上一篇,这篇我们对我们的客户端加入KissXML,MBProgressHUD,AQridView这几个库,首先我们先加入KissXML,这是XML解析库,支持Xpath,可以方便添加更改任何节点.先 ...
- swift中使用sqlite3
import Foundation /** 1. 打开数据库 2. 如果没有数据表,需要首先创表 3. 数据操作 */ class SQLite { var db: COpaquePointer = ...
- Ubuntu创建应用快捷方式
Ubuntu创建应用快捷方式 新建一个.desktop文件 vi eclipse.desktop 然后又进行编辑 [Desktop Entry] Encoding=UTF-8 Name=eclipse ...
- bzoj5286 [Hnoi2018]转盘
题目描述: bz luogu 题解: 看了半个晚上终于明白了. 首先最优决策一定有:在起始点停留一段时间然后一直前进. 解释网上有很多,在这里不赘述了. (由于是环,先把$T$数组倍长.) 首先基于决 ...
- 【数论】贝壳找房计数比赛&&祭facinv
震惊!阶乘逆元处理背后竟有如此玄机…… 题目描述 贝壳找房举办了一场计数比赛,比赛题目如下. 给一个字符串 s 和字符串 t,求出 s 的所有去重全排列中 t 出现的次数.比如aab的去重全排列为aa ...
- linux-MySQL基本指令-增删改查
常用指令 指令作用 指令 查看/查询 show,select,desc 创建 create 删除 drop,delete,truncate 切换/进入 use 添加记录 insert 查询类 查看数据 ...
- 文件的软硬链接& 文件编辑vi和vim
目录 文件的软硬链接 1.软链接 2.硬链接 文件编辑vi和vim 须先安装vim命令的软件包yum install -y vim 三种模式: 1.普通模式 2.编辑模式 3.末行模式 文件的软硬链接 ...
- 杭电 1051 Wooden Sticks
Description There is a pile of n wooden sticks. The length and weight of each stick are known in adv ...