2019 Multi-University Training Contest 3 T7 Find the answer
Find the answer
Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
Given a sequence of n integers called W and an integer m. For each i (1 <= i <= n), you can choose some elements W**k (1 <= k < i), and change them to zero to make ∑i**j=1W**j<=m. So what's the minimum number of chosen elements to meet the requirements above?.
Input
The first line contains an integer Q --- the number of test cases.
For each test case:
The first line contains two integers n and m --- n represents the number of elemens in sequence W and m is as described above.
The second line contains n integers, which means the sequence W.
1 <= Q <= 15
1 <= n <= 2*105
1 <= m <= 109
For each i, 1 <= W**i <= m
Output
For each test case, you should output n integers in one line: i-th integer means the minimum number of chosen elements W**k (1 <= k < i), and change them to zero to make ∑i**j=1W**j<=m.
Sample Input
2
7 15
1 2 3 4 5 6 7
5 100
80 40 40 40 60
Sample Output
0 0 0 0 0 2 3
0 1 1 2 3
题意
自己读题,几句话很难说清楚
转化一下就是将最少的数变成0,并且自己不能选,使\(\sum_{j=1}^{i} \leq m\),输出最小的次数。
题解
贪心一下,取最大的几个。
离散+权值线段树就成。
代码
#include<bits/stdc++.h>
#define int long long
#define DEBUG cerr << "Call out: " << __func__ << "\t" << "Line: " << __LINE__ << "\t :"
using namespace std;
#define MAXN 200010
struct sgt
{
int val,p;
int l,r;
} f[MAXN<<2];
int wh[MAXN];
int a[MAXN];
pair <int,int> pt[MAXN];
int n;
int m;
void build(int x,int l,int r)
{
f[x].l = l;
f[x].r = r;
f[x].val = f[x].p = 0;
if (l == r) return;
build(x<<1,l,(l+r)>>1);
build(x<<1|1,((l+r)>>1)+1,r);
}
void add(int x,int pos,int val)
{
f[x].val += val;
f[x].p ++;
if (f[x].l == pos && f[x].r == pos) return;
if (pos > f[x<<1].r) add(x<<1|1,pos,val);
else add(x<<1,pos,val);
}
int query(int x,int val)
{
if (f[x].l == f[x].r)
if (f[x].val == val) return f[x].p;
else return 0;
if (f[x<<1].val >= val) return query(x<<1,val);
return f[x<<1].p + query(x<<1|1,val - f[x<<1].val);
}
signed main()
{
int T;
cin >> T;
while (T--)
{
cin >> n >> m;
memset(f,0,sizeof(f));
build(1,1,n);
for (int i=1; i<=n; i++)
scanf("%d",a+i),pt[i].first = a[i], pt[i].second = i;
sort(pt+1,pt+n+1);
for (int i=1; i<=n; i++)
wh[pt[i].second] = i;
int tot = 0;
for (int i=1; i<=n; i++)
{
tot += a[i];
if (tot <= m) printf("0 ");
if (tot > m) printf("%d ",i-query(1,m-a[i])-1);
add(1,wh[i],a[i]);
}
puts("");
}
}
2019 Multi-University Training Contest 3 T7 Find the answer的更多相关文章
- 2019 Nowcoder Multi-University Training Contest 4 E Explorer
线段树分治. 把size看成时间,相当于时间 $l$ 加入这条边,时间 $r+1$ 删除这条边. 注意把左右端点的关系. #include <bits/stdc++.h> ; int X[ ...
- 2019 Nowcoder Multi-University Training Contest 1 H-XOR
由于每个元素贡献是线性的,那么等价于求每个元素出现在多少个异或和为$0$的子集内.因为是任意元素可以去异或,那么自然想到线性基.先对整个集合A求一遍线性基,设为$R$,假设$R$中元素个数为$r$,那 ...
- 2019 Multi-University Training Contest 8
2019 Multi-University Training Contest 8 C. Acesrc and Good Numbers 题意 \(f(d,n)\) 表示 1 到 n 中,d 出现的次数 ...
- 2019 Multi-University Training Contest 7
2019 Multi-University Training Contest 7 A. A + B = C 题意 给出 \(a,b,c\) 解方程 \(a10^x+b10^y=c10^z\). tri ...
- 2019 Multi-University Training Contest 1
2019 Multi-University Training Contest 1 A. Blank upsolved by F0_0H 题意 给序列染色,使得 \([l_i,r_i]\) 区间内恰出现 ...
- 2019 Multi-University Training Contest 2
2019 Multi-University Training Contest 2 A. Another Chess Problem B. Beauty Of Unimodal Sequence 题意 ...
- 2019 Multi-University Training Contest 5
2019 Multi-University Training Contest 5 A. fraction upsolved 题意 输入 \(x,p\),输出最小的 \(b\) 使得 \(bx\%p&l ...
- HDU校赛 | 2019 Multi-University Training Contest 6
2019 Multi-University Training Contest 6 http://acm.hdu.edu.cn/contests/contest_show.php?cid=853 100 ...
- HDU校赛 | 2019 Multi-University Training Contest 5
2019 Multi-University Training Contest 5 http://acm.hdu.edu.cn/contests/contest_show.php?cid=852 100 ...
随机推荐
- MSF魔鬼训练营-3.1.1信息收集-通过DNS和IP地址挖掘目标网络信息
情报搜集环境站渗透测试全过程的80%~90% 一.外围信息搜集(公开渠道信息搜集OSINT open source intelligence) 3.1.1信息收集-通过DNS和IP地址挖掘目标网 ...
- C# 流与文件(Stream & File & byte[])
原文:https://www.cnblogs.com/long-gengyun/archive/2010/03/28/1698681.html 文件概述 文件在操作时表现为流,即流是从一些输入中读取 ...
- x系统清理/tmp/文件夹的原理
转自:http://www.opsers.org/base/clean-up-on-the-linux-system-tmp-folder-you-may-want-to-know.html§ 我们知 ...
- redis 有序集合
添加 zadd keyword 0 'eric' 0 'zhang' 0 'yun' 查看列表 zrevrange 降序排列 zrevrange keyword 0 -1 增加分数 zincr ...
- Python字符串和正则表达式中的反斜杠('\')问题
在Python普通字符串中 在Python中,我们用'\'来转义某些普通字符,使其成为特殊字符,比如 In [1]: print('abc\ndef') # '\n'具有换行的作用 abc defg ...
- python操作redis用法详解
python操作redis用法详解 转载地址 1.redis连接 redis提供两个类Redis和StrictRedis用于实现Redis的命令,StrictRedis用于实现大部分官方的命令,并使用 ...
- RabbitMQ从安装到使用
一.在Linux中安装RabbitMQ 通过Docker安装: 获取镜像(选用management是带有管理界面的) docker pull rabbitmq:-management 查看下载好的镜像 ...
- linux格式化磁盘命令
linux格式化磁盘命令 linux mkfs 指令:mkfs 使用权限 : 超级使用者 使用方式 : mkfs [-V] [-t fstype] [fs-opti ...
- hostid - 显示当前主机的数字化标识
SYNOPSIS(总览) hostid [-v] DESCRIPTION(描述) 显示当前主机的数字化标识(以十六进制的形式表示). --help 显示帮助信息后退出 --version 输出版本信息 ...
- XML 总结
XML 可用于交换.共享和存储数据. XML 文档形成 树状结构,在"根"和"叶子"的分支机构开始的. XML 有非常简单的 语法规则.带有正确语法的 XML ...