「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),注重文笔,还得投入大把时间,真心是一件难度颇高的事情.但,若是真写好了,也是善莫大焉: ...
 
随机推荐
- Android系统架构(图解)
			
下图是 Android 操作系统的架构,架构包括 4 层,由上到下依次是应用程序层.应用程序框架层.核心类库和 Linux 内核.其中,核心类库中包含系统库及 Android 运行环境. 图1 An ...
 - 【代码审计】VAuditDemo 重装漏洞
			
一.源码安装漏洞介绍 一般在PHP源码程序都有一个初始安装的功能,如果相关代码没有对参数进行严格过滤,可能会导致攻击者访问安装页面(install.php)或构造数据包,对网站进行重新安装,从而危害网 ...
 - 吴裕雄 python 神经网络——TensorFlow 滑动平均类的保存
			
import tensorflow as tf v = tf.Variable(0, dtype=tf.float32, name="v") for variables in tf ...
 - SpringBoot学习笔记(二)——Springboot项目目录介绍
			
官网生成SpringBoot项目 使用官网(https://start.spring.io/)生成一个Maven构建的的SpringBoot项目,下载下来的文件是这个样子的. 导入到IDEA中 为了查 ...
 - 通过UA实现手机端电脑端的分离!(重点)
			
实现Nginx区分PC和手机访问不同的网站是物理上完全隔离的两套网站(一套手机端.一套pc端) 这样带来的好处pc端和移动端的内容可以不一样,移动版网站不需要包含特别多内容.只要包含必要的文字和较小的 ...
 - win10+anaconda安装tensorflow和keras遇到的坑小结
			
win10下利用anaconda安装tensorflow和keras的教程都大同小异(针对CPU版本,我的gpu是1050TI的MAX-Q,不知为啥一直没安装成功),下面简单说下步骤. 一 Anaco ...
 - Servlet部署项目和项目起别名
			
一.部署项目: ① 单机MyEclipse导航栏下方Deploy MyEclipse J2EE Project to Server... ②单机Add,选择Service,点击Ok 二.给项目起别名: ...
 - 爬虫模拟cookie自动登录(人人网自动登录)
			
什么是cookie? 在网站中,HTTP请求时无状态的,也就是说即使第一次和服务器连接后并且登录成功后,第二次请求服务器依然不能知道当前请求是谁,cookie的出现就是为了解决这个问题,第一次登陆后服 ...
 - git pull解决冲突
			
git报错:Please commit your changes or stash them before you merge. 解决:1.不需要保留本地修改的话,直接将有冲突的文件还原再pull:g ...
 - 02-10Android学习进度报告十
			
今天我学习了有关ListView的基础知识,主要是学习了其中界面展示的基本方法. 首先看一个简单的列表实现代码: public class Animal { private String aName; ...