「CF521D」Shop
传送门
Luogu
解题思路
当只有第三类操作时,我们显然先进行val较大的操作,这是显然的。
那么就考虑把所有的操作都转变为第三类操作。
第一类操作,显然很容易变为第二类操作:单点维护最大的最终结果,然后改为加法就好了。
问题在于第二类操作如何转换。
其实也是贪心,我们对于同一个位置的第二类操作,优先进行val值较大的,把较小的分母留给较大的分子使得答案最优。
细节注意事项
- 实现起来有点繁琐。
参考代码
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
s = f ? -s : s;
}
typedef long long LL;
const int _ = 100010;
int n, m, k, n1, n2, n3, x[_];
struct node{ int t, id, x; LL fz, fm; }t1[_], t2[_], t3[_], ans[_];
inline bool cmp1(const node& a, const node& b) { return a.x == b.x ? a.fz < b.fz : a.x < b.x; }
inline bool cmp2(const node& a, const node& b) { return a.x == b.x ? a.fz > b.fz : a.x < b.x; }
inline bool cmp3(const node& a, const node& b) { return a.fz * b.fm > b.fz * a.fm; }
inline bool cmp4(const node& a, const node& b) { return a.t < b.t; }
int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
read(n), read(m), read(k);
for (rg int i = 1; i <= n; ++i) read(x[i]);
for (rg int t, xi, val, i = 1; i <= m; ++i) {
read(t), read(xi), read(val);
if (t == 1 && val > x[xi]) t1[++n1] = (node) { t, i, xi, val, 1 };
if (t == 2) t2[++n2] = (node) { t, i, xi, val, 1 };
if (t == 3) t3[++n3] = (node) { t, i, xi, val, 1 };
}
sort(t1 + 1, t1 + n1 + 1, cmp1);
int qwq = 0;
for (rg int i = 1; i <= n1; ++i)
if (t1[i].x != t1[i + 1].x) t1[++qwq] = t1[i];
n1 = qwq;
for (rg int i = 1; i <= n1; ++i)
t1[i].fz -= x[t1[i].x], t2[++n2] = t1[i];
sort(t2 + 1, t2 + n2 + 1, cmp2);
LL sum = 0;
for (rg int i = 1; i <= n2; ++i) {
if (t2[i].x != t2[i - 1].x) sum = x[t2[i].x];
t2[i].fm = sum, sum += t2[i].fz;
}
for (rg int i = 1; i <= n3; ++i) --t3[i].fz;
for (rg int i = 1; i <= n2; ++i) t3[++n3] = t2[i];
sort(t3 + 1, t3 + n3 + 1, cmp3);
int cnt = min(n3, k);
for (rg int i = 1; i <= cnt; ++i) ans[i] = t3[i];
printf("%d\n", cnt);
sort(ans + 1, ans + cnt + 1, cmp4);
for (rg int i = 1; i <= cnt; ++i)
printf("%d%c", ans[i].id, " \n"[i == cnt]);
return 0;
}
完结撒花 \(qwq\)
「CF521D」Shop的更多相关文章
- 「CF521D」 Shop
「CF521D」 Shop 传送门 题目说是有三种操作,首先可以知道赋值操作是可以转化为加法操作的,即 \((1,b) \rightarrow (2,b-a_i)\) 然后加法对于一个数你肯定优先选择 ...
- 【LOJ】#2985. 「WC2019」I 君的商店
LOJ#2985. 「WC2019」I 君的商店 一道很神仙的题啊QAQ 居然是智商题--不是乱搞或者是大数据 我们可以用2N问出一个最大值是1 然后对于任意两个值\(x + y\)和\(a\)比较 ...
- loj2985「WC2019」I 君的商店(二分,思维)
loj2985「WC2019」I 君的商店(二分,思维) loj Luogu 题解时间 真的有点猛的思维题. 首先有一个十分简单的思路: 花费 $ 2N $ 确定一个为 $ 1 $ 的数. 之后每次随 ...
- 「译」JUnit 5 系列:条件测试
原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...
- 「译」JUnit 5 系列:扩展模型(Extension Model)
原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...
- JavaScript OOP 之「创建对象」
工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程.工厂模式虽然解决了创建多个相似对象的问题,但却没有解决对象识别的问题. function createPers ...
- 「C++」理解智能指针
维基百科上面对于「智能指针」是这样描述的: 智能指针(英语:Smart pointer)是一种抽象的数据类型.在程序设计中,它通常是经由类型模板(class template)来实做,借由模板(tem ...
- 「JavaScript」四种跨域方式详解
超详细并且带 Demo 的 JavaScript 跨域指南来了! 本文基于你了解 JavaScript 的同源策略,并且了解使用跨域跨域的理由. 1. JSONP 首先要介绍的跨域方法必然是 JSON ...
- 「2014-5-31」Z-Stack - Modification of Zigbee Device Object for better network access management
写一份赏心悦目的工程文档,是很困难的事情.若想写得完善,不仅得用对工具(use the right tools),注重文笔,还得投入大把时间,真心是一件难度颇高的事情.但,若是真写好了,也是善莫大焉: ...
随机推荐
- 洛谷P1073最优贸易(跑两遍dij)
题目描述 CC C国有n n n个大城市和m mm 条道路,每条道路连接这 nnn个城市中的某两个城市.任意两个城市之间最多只有一条道路直接相连.这 mmm 条道路中有一部分为单向通行的道路,一部分为 ...
- Educational Codeforces Round 81 (Rated for Div. 2)
A 0~9需要多少笔画,自取7和1,判奇偶 #include<bits/stdc++.h> using namespace std; #define ll long long #defin ...
- C语言-数组与指针 字符与字符串
1 字符与字符串:char c='a'而不能写出char c="a" //字符变量用单引号'',而字符串用双引号. 2 字符数组与字符指针的初始化: char s[10]={0}, ...
- C++11常用特性介绍——array容器
std::array是具有固定大小的数组,支持快速随机访问,不能添加或删除元素,定义于头文件<array>中. 一.概要 array是C++11新引入的容器类型,与内置数组相比,array ...
- Python 爬取 热词并进行分类数据分析-[云图制作+数据导入]
日期:2020.01.28 博客期:136 星期二 [本博客的代码如若要使用,请在下方评论区留言,之后再用(就是跟我说一声)] 所有相关跳转: a.[简单准备] b.[云图制作+数据导入](本期博客) ...
- 苹果应用商店AppStore审核规则指南
http://www.zesmob.com/blog/40161.html 新应用上架苹果AppStore或重大版本更新时,往往会被拒多次,造成审核不通过的原因,主要是因为对苹果应用商店AppStor ...
- python 连接oracle基础环境配置方法
配置基础: 1.python3.7 2.oracle server 11g 64位 3.PLSQL 64位 4.instantclient-basic-windows.x64-11.2.0.4.0这个 ...
- 1012 The Best Rank (25分) vector与结构体排序
1012 The Best Rank (25分) To evaluate the performance of our first year CS majored students, we con ...
- java记录3--异常
异常的分类 1.Error 由java虚拟机生成并抛出,包括动态链接失败,虚拟机错误等等,JAVA程序无法对此错误 try { //可能出现异常的代码块 } catch(exception1 ) { ...
- hdfs dfs ls /列出了本地根目录下文件夹和文件Warning: fs.defaultFS is not set when running "ls" command
[root@node01 customShells]# hdfs dfs -ls /Warning: fs.defaultFS is not set when running "ls&quo ...