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放在最上层情况 ...
随机推荐
- CPP-网络/通信:COM
))//打开串口 { ) { CloseCom();//关闭串口 break; } //添加处理代码. } //最后关闭串口 CloseCom();//关闭串口
- Python操作12306抢票脚本
有一段时间没有使用Python了,前几天经朋友提起一篇关于用Python实现抢火车票的文章,百度了实现抢火车票的技术细节,网上却有不少资料,也不是新鲜的东西.在了解了一些技术手段,阅读了一些大神的博文 ...
- Mac OSX: 有线共享WiFi
首先连上有线 系统偏好设置->网络->点击左侧WiFi,再点击右下角[高级] 勾选[创建电脑对电脑网络],然后单击[好] 在顶部菜单栏击WiFi图标,如果WiFi未打开,则单击打开,如果已 ...
- perl学习之:shift/unshift
perl中shift 和unshift 操作 2008-02-02 11:18:04| 分类: Perl语言|举报|字号 订阅 ############################### ...
- perl学习二:简单变量
字符串变量:${}1.单引号:不进行变量替换,不进行转义,字符串可以跨行.2.双引号:变量替换(贪婪匹配原则).支持转义字符(转义字符可以另外看)3.反引号 字符串的特殊表示方法:qq(...) q( ...
- LeetCode(109) Convert Sorted List to Binary Search Tree
题目 Given a singly linked list where elements are sorted in ascending order, convert it to a height b ...
- Java中TreeMap集合讲解
1.TreeSet介绍 TreeSet是一个有序集合,可以以任意顺序将元素插入到集合中,在对集合进行遍历的时候,每个元素将自动按照排序后的顺序呈现.底层使用的是二叉树(更具体点是红黑树)实现,对于元素 ...
- Python paramiko模块 + 堡垒机
paremiko SSHClient 用于连接远程服务器并执行基本命令 基于用户名密码连接: import paramiko # 创建SSH对象 ssh = paramiko.SSHClient ...
- DDL、DML、DCL、DQL的理解
DDL.DML 和 DCL 的理解 DDL(data definition language)数据库定义语言 的主要语句(操作) Create 语句:可以创建数据库和数据库的一些对象. Drop 语句 ...
- 大数据学习——Kafka集群部署
1下载安装包 2解压安装包 -0.9.0.1.tgz -0.9.0.1 kafka 3修改配置文件 cp server.properties server.properties.bak # Lice ...