传送门

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的更多相关文章

  1. 「CF521D」 Shop

    「CF521D」 Shop 传送门 题目说是有三种操作,首先可以知道赋值操作是可以转化为加法操作的,即 \((1,b) \rightarrow (2,b-a_i)\) 然后加法对于一个数你肯定优先选择 ...

  2. 【LOJ】#2985. 「WC2019」I 君的商店

    LOJ#2985. 「WC2019」I 君的商店 一道很神仙的题啊QAQ 居然是智商题--不是乱搞或者是大数据 我们可以用2N问出一个最大值是1 然后对于任意两个值\(x + y\)和\(a\)比较 ...

  3. loj2985「WC2019」I 君的商店(二分,思维)

    loj2985「WC2019」I 君的商店(二分,思维) loj Luogu 题解时间 真的有点猛的思维题. 首先有一个十分简单的思路: 花费 $ 2N $ 确定一个为 $ 1 $ 的数. 之后每次随 ...

  4. 「译」JUnit 5 系列:条件测试

    原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...

  5. 「译」JUnit 5 系列:扩展模型(Extension Model)

    原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...

  6. JavaScript OOP 之「创建对象」

    工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程.工厂模式虽然解决了创建多个相似对象的问题,但却没有解决对象识别的问题. function createPers ...

  7. 「C++」理解智能指针

    维基百科上面对于「智能指针」是这样描述的: 智能指针(英语:Smart pointer)是一种抽象的数据类型.在程序设计中,它通常是经由类型模板(class template)来实做,借由模板(tem ...

  8. 「JavaScript」四种跨域方式详解

    超详细并且带 Demo 的 JavaScript 跨域指南来了! 本文基于你了解 JavaScript 的同源策略,并且了解使用跨域跨域的理由. 1. JSONP 首先要介绍的跨域方法必然是 JSON ...

  9. 「2014-5-31」Z-Stack - Modification of Zigbee Device Object for better network access management

    写一份赏心悦目的工程文档,是很困难的事情.若想写得完善,不仅得用对工具(use the right tools),注重文笔,还得投入大把时间,真心是一件难度颇高的事情.但,若是真写好了,也是善莫大焉: ...

随机推荐

  1. 创业学习---今日头条创业过程分析---HHR计划

    本文搜集和整理了今日头条创业的一些关键点的资料------by 春跃(本文的主要观点都是搜集整理,所以不得本人同意不得转载) 一,18年之前的今日头条创业时间表: 1,张一鸣参与创业的履历:酷讯,饭否 ...

  2. scala基础API

    1.对象和json转换 1.1 json取值 val json:JSONObject = JSON.parseObject(jsonMsg:String)val message:String = js ...

  3. Spring Boot RestApi 测试教程 Mock 的使用

    测试 Spring Boot Web 的时候,我们需要用到 MockMvc,即系统伪造一个 mvc 环境.本章主要编写一个基于 RESTful API 正删改查操作的测试用例.本章最终测试用例运行结果 ...

  4. vscode vue js 开发插件配置

    安装 vetur { // 自动补全触发范围---双引号内的字符串也可以触发补全 "editor.quickSuggestions": { "other": t ...

  5. 【原】简单shell练习(五)

    1.查询一个文件中某个单词出现的次数 # grep -o 'ts' ./test/txt |wc -l 2.统计当前文件夹下文件的个数 ls -l |grep "^-"|wc -l ...

  6. Python与线性代数——Numpy中的matrix()和array()的区别

    Numpy中matrix必须是2维的,但是 numpy中array可以是多维的(1D,2D,3D····ND).matrix是array的一个小的分支,包含于array.所以matrix 拥有arra ...

  7. POJ 1064 Cable master(二分答案)

    嗯... 题目链接:http://poj.org/problem?id=1064 其实这是一道很好想的二分答案的一道题... 二分的区间就是1~max_l,从1开始是因为所有小于1的都需要按0计算,没 ...

  8. 一个IP与多个域名绑定

    方法一:通过端口区分 方法二:通过serverName区分(推荐) 1.httpd.conf打开 virtual host虚拟主机配置 2.httpd-vhost.conf 添加配置 <Virt ...

  9. Linux 命令中 which、whereis、locate 命令的用法

    which 命令 which 命令的作用是,在 PATH 变量指定的路径中搜索可执行文件的所在位置.它一般用来确认系统中是否安装了指定的软件. (1)命令格式 which 可执行文件名称 wherei ...

  10. Vulnhub_DC1 记录

    目录 Vulnhub_DC1 记录 经验 & 总结 步骤流水 1. 建立立足点 2. 提权 3. 主机信息搜集 4. 继续提权 5. 消失的flag Vulnhub_DC1 记录 参考walk ...