【Hello 2018 D】Too Easy Problems
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
可以考虑把所有的题目按照ai排序。
然后顺序考虑最后做出来的题目个数和第i道题目的ai一样。
则1..i-1这些题目就没有用了。
值考虑i..n这些题目就可以了。
显然考虑ti最小的若干项。
使得它们的时间和我这个做法太麻烦了。。
另解1
我这种做法其实可以做得更好一点:
即枚举题目个数i从n递减到1
然后在一个集合中维护ai>=i的题目(只要枚举到第i个的时候,把ai==i的加入set里面就好了),然后保证集合的大小为i就可以了。
->如果大于k了,那么就把ti最大的那几个删掉,直到集合的大小为k
维护集合里面的题目的和就好。
另解2
二分最后的分数。
显然如果分数mid可以得到的话。
那么分数mid-1肯定也可以得到。
可以看出来有单调性。
【代码】
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5;
struct BI {
ll a[N + 10],b[N+10];
int lowbit(int x) {
return x&(-x);
}
void add(int x,int y) {
while (x <= N) {
a[x] += y;
x += lowbit(x);
}
}
void add2(int x,int y) {
while (x <= N) {
b[x] += y;
x += lowbit(x);
}
}
ll sum(int x) {
int now = 0;
while (x > 0) {
now += a[x];
x -= lowbit(x);
}
return now;
}
int sum2(int x) {
int now = 0;
while (x > 0) {
now += b[x];
x -= lowbit(x);
}
return now;
}
ll get_sum(int l, int r) {
return sum(r) - sum(l - 1);
}
int get_sum2(int l, int r) {
return sum2(r) - sum2(l - 1);
}
}B;
struct abc{
int a,t,idx;
};
bool cmp(abc a,abc b){
return a.a<b.a;
}
bool cmp2(abc a,abc b){
return a.t<b.t;
}
abc a[N+10],b[N+10];
int should[N+10];
multiset< int > myset;
bool bo[N+10];
int n,t;
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> t;
for (int i = 1;i <= n;i++){
cin >> a[i].a >> a[i].t;
a[i].idx = i;
}
for (int i = 1;i <= n;i++) myset.insert(a[i].t);
sort(a+1,a+1+n,cmp);
for (int i = 1;i <= n;i++) b[i] = a[i];
sort(b+1,b+1+n,cmp2);
for (int i = 1;i <= n;i++){
should[b[i].idx] = i;
B.add(i,b[i].t);
B.add2(i,1);
}
int ans = 0,index = -1;
for (int i = 1;i <= n;i++){
int num = a[i].a;
ll now = 0;
int j = 0;
int l = 1,r = n,temp = -1,temptot;
while (l <= r){
int mid = (l+r)>>1;
int cnt = B.get_sum2(1,mid);
ll tot = B.get_sum(1,mid);
if (cnt<=num && tot<=t){
temptot = cnt;
l = mid+1;
temp = mid;
}else{
r = mid - 1;
}
}
if (temp!=-1){
if (temptot>ans) {
ans = temptot;
index = i;
}
}
j = i;
int tt = should[a[i].idx];
B.add2(tt,-1);
B.add(tt,-a[i].t);
bo[a[i].idx] = true;
while (j+1<=n && a[j+1].a==a[i].a) {
j++;
bo[a[j].idx] = true;
int tt = should[a[j].idx];
B.add2(tt,-1);
B.add(tt,-a[j].t);
}
i = j;
}
cout << ans << endl;
cout << ans << endl;
if (index!=-1){
sort(a+index,a+1+n,cmp2);
for (int i = index;i <= index+ans-1;i++)
cout <<a[i].idx<<' ';
}
return 0;
}
【Hello 2018 D】Too Easy Problems的更多相关文章
- 【AGC 005F】Many Easy Problems
Description One day, Takahashi was given the following problem from Aoki: You are given a tree with ...
- 【AGC005F】Many Easy Problems FFT 容斥原理
题目大意 给你一棵树,有\(n\)个点.还给你了一个整数\(k\). 设\(S\)为树上某些点的集合,定义\(f(S)\)为最小的包含\(S\)的联通子图的大小. \(n\)个点选\(k\)个点一共有 ...
- 【AGC005F】Many Easy Problems (NTT)
Description 给你一棵\(~n~\)个点的树和一个整数\(~k~\).设为\(~S~\)为树上某些点的集合,定义\(~f(S)~\)为最小的包含\(~S~\)的联通子图的大小.\(~n~ ...
- 【AGC005F】Many Easy Problems
Description 题目链接 对于每个\(k\),统计任选\(k\)个点作为关键点的"最小生成树"的大小之和 Solution 正向想法是枚举或者计算大小为\(x\).叶子数目 ...
- 【AGC005 F】Many Easy Problems
神他吗一天考一道码农题两道 FFT(其实还是我推式子一窍不通) 题意 给你一棵 \(n\) 个点的树,再给你一个常数 \(k\). 设 \(S\) 为树上某些点的集合,定义 \(f(S)\) 为最小的 ...
- 【Hello 2018 C】Party Lemonade
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 处理出凑够2^j最少需要花费多少钱. 即试着把第i种物品买2^(j-i)个,看看会不会更便宜 记录在huafei[0..31]中 然 ...
- 【Hello 2018 B】Christmas Spruce
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 写个dfs看看是不是每个节点都有3个叶子节点就可以了. [代码] #include <bits/stdc++.h> us ...
- 【Hello 2018 A】 Modular Exponentiation
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 当a<b的时候 a%b==a 显然2^n增长很快的. 当2^n>=1e8的时候,直接输出m就可以了 [代码] #incl ...
- 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT
[题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...
随机推荐
- ArchLinux 设置时间同步和硬件时间同步错误 No usable clock interface found
笔记本不知道怎么了,总是时间对不上 硬件时间也设置不了,只能时间同步了 手动时间同步 ntpdate即可,ntp服务器在这里用这两个就好了 cn.ntp.org.cn 或 edu.ntp.org.cn ...
- 【IDEA】Error: java: Compliance level '1.6' is incompatible with target level '1.8'. A compliance level '1.8' or better is required解决办法
在运行的时候常常出现如下错误: Error: java: Compliance level '1.6' is incompatible with target level '1.8'. A compl ...
- 紫书 习题 10-10 UVa 1645(递推)
除了根节点以外,有n-1个节点,然后就看n-1的因数有那些,所有因数加起来(递推)就好了. #include<cstdio> #define REP(i, a, b) for(int i ...
- Unity ContextMenu特性
有时候我们需要在编辑器下,频繁的做一些操作,比如说在不同的位置创建物体,一个个的修改坐标显然有点繁琐 这时候ContextMenu就派上用处了 例:利用 LineRenderer 画圆,我们不可能一个 ...
- C++里面关于虚函数的一些注意点
最后,总结一下关于虚函数的一些常见问题: 1) 虚函数是动态绑定的,也就是说,使用虚函数的指针和引用能够正确找到实际类的对应函数,而不是执行定义类的函数.这是虚函数的基本功能,就不再解释了. 2) 构 ...
- vector和list容器之间的复制
#include <iostream> #include <list> #include <string> #include <vector> #inc ...
- JVM-ClassLoader装载class的流程
在JVM中,有三种默认的类加载器,分别为Bootstrap ClassLoader,Extension CLassLoader以及App ClassLoader.其中,Bootstrap Classl ...
- linux添加开机启动项的方法介绍
使用chkconfig命令可以查看在不同启动级别下课自动启动的服务(或是程序),命令格式如下:chkconfig --list可能输出如下:openvpn 0:关闭 1:开启 ...... 6:关闭 ...
- 2.AngularJS-验证
转自:https://www.cnblogs.com/best/p/6225621.html 一.验证 angularJS中提供了许多的验证指令,可以轻松的实现验证,只需要在表单元素上添加相应的ng属 ...
- spring xml配置文件根元素(文件头文件)说明
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...