线段树

又是熟悉的感觉,又是E题写完了,没调完,不过还好上了紫

CF1295E


可以发现可以打败怪兽的关系类似二维偏序

那么首先考虑第一维(武器)以攻击值($a_{i}$)进行排序

把所有的怪兽以防御力($x_{i}$)进行排序

然后用双指针维护到目前遍历到的武器,可以打败的怪兽

然后考虑防具和怪兽的攻击力也就是第二维

首先先定义$lb$数组,$lb[i]$表示所选防具至少为$i$的最少花费

可以用差分求出

可以发现如果选到防御力为$i$的防具,那么所有当前可以打败的怪兽中,只要攻击力小于$i$都可以累加到答案中

那么考虑$mx[i]$表示维护防御力最大为$i$的最大获利(包含防具的开支,武器的开支在最后计算)

对于一只新增的怪兽只要$i$大于其防御力,那么$mx[i]$都可以加上这只怪兽的获利

线段树维护即可

还要注意武器和防具里必选,不能不选

 1 #include <bits/stdc++.h>
2 #define inf 1e18
3 #define int long long
4 using namespace std;
5 const int N=2*1e5+100,NUM=1e6+100;
6 int n,m,p,lb[NUM],ans,mb;
7 struct tool
8 {
9 int f,cost;
10 };
11 tool a[N],b[N];
12 struct monsters
13 {
14 int x,y,z;
15 }c[N];
16 struct node
17 {
18 int MAX,lazy;
19 }sh[NUM*4];
20 bool cmp(tool a,tool b)
21 {
22 return a.f<b.f;
23 }
24 bool cmp1(monsters a,monsters b)
25 {
26 return a.x<b.x;
27 }
28 void pushup(int x)
29 {
30 sh[x].MAX=max(sh[x+x].MAX,sh[x+x+1].MAX);
31 }
32 void pushdown(int x)
33 {
34 if (sh[x].lazy!=0)
35 {
36 sh[x+x].lazy+=sh[x].lazy;
37 sh[x+x+1].lazy+=sh[x].lazy;
38 sh[x+x].MAX+=sh[x].lazy;
39 sh[x+x+1].MAX+=sh[x].lazy;
40 sh[x].lazy=0;
41 }
42 }
43 void build(int x,int l,int r)
44 {
45 if (l==r)
46 {
47 sh[x].MAX=-lb[l];//处理当前防具的价格
48 return;
49 }
50 int mid=(l+r)>>1;
51 build(x+x,l,mid);
52 build(x+x+1,mid+1,r);
53 pushup(x);
54 }
55 void change(int x,int l,int r,int ll,int rr,int v)//区间修改
56 {
57 if (ll<=l && r<=rr)
58 {
59 sh[x].MAX+=v;
60 sh[x].lazy+=v;
61 return;
62 }
63 int mid=(l+r)>>1;
64 pushdown(x);
65 if (ll<=mid) change(x+x,l,mid,ll,rr,v);
66 if (rr>mid) change(x+x+1,mid+1,r,ll,rr,v);
67 pushup(x);
68 }
69 signed main()
70 {
71 scanf("%lld%lld%lld",&n,&m,&p);
72 for (int i=1;i<=n;i++) scanf("%lld%lld",&a[i].f,&a[i].cost);
73 for (int i=1;i<=m;i++) scanf("%lld%lld",&b[i].f,&b[i].cost);
74 for (int i=1;i<=p;i++) scanf("%lld%lld%lld",&c[i].x,&c[i].y,&c[i].z);
75 sort(a+1,a+1+n,cmp);
76 sort(c+1,c+1+p,cmp1);
77 for (int i=1;i<=m;i++) mb=max(mb,b[i].f);
78 for (int i=1;i<=mb;i++) lb[i]=inf;
79 for (int i=1;i<=m;i++) lb[b[i].f]=min(lb[b[i].f],b[i].cost);
80 for (int i=mb-1;i>=1;i--) lb[i]=min(lb[i+1],lb[i]);//差分求出lb数组
81 ans=-inf;
82 build(1,1,mb);
83 for (int i=1,j=1;i<=n;i++)
84 {
85 while (c[j].x<a[i].f && j<=p)//双指针维护当前可以击败的怪兽
86 {
87 if (c[j].y+1<=mb)//在防御力最大的防具之内
88 change(1,1,mb,c[j].y+1,mb,c[j].z);//要严格大于
89 j++;
90 }
91 ans=max(ans,-a[i].cost+sh[1].MAX);//最后计算武器的代价
92 }
93 printf("%lld\n",ans);
94 }

CF1320C World of Darkraft: Battle for Azathoth的更多相关文章

  1. Codeforces 1321E World of Darkraft: Battle for Azathoth

    题意 有\(n\)个武器,第\(i\)个武器攻击力为\(a_i\),价值\(ca_i\). 有\(m\)个防具,第\(i\)个防具防御力为\(b_i\),价值\(cb_i\). 有\(p\)个怪,第\ ...

  2. Codeforces Round #625 (1A - 1D)

      A - Journey Planning 题意: 有一列共 n 个城市, 每个城市有美丽值 b[i], 要访问一个子序列的城市, 这个子序列相邻项的原项数之差等于美丽值之差, 求最大的美丽值总和. ...

  3. Solution -「线段树」题目集合

    T1 无聊的数列 来自:Link flag 帖先从水题入手. 首先分析题目,它是以等差数列为原型进行的修改.等差数列一大性质就是其差分数列的值除第一项以外均相等. 于是不难想到使用差分数列进行维护. ...

  4. 【Virt.Contest】CF1321(div.2)

    第一次打虚拟赛. CF 传送门 T1:Contest for Robots 统计 \(r[i]=1\) 且 \(b[i]=0\) 的位数 \(t1\) 和 \(r[i]=0\) 且 \(b[i]=1\ ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. Codeforces 738D. Sea Battle 模拟

    D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...

  7. Codeforces #380 div2 D(729D) Sea Battle

    D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. The 2015 China Collegiate Programming Contest C. The Battle of Chibi hdu 5542

    The Battle of Chibi Time Limit: 6000/4000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Othe ...

  9. get a new level 25 battle pet in about an hour

    If you have 2 level 25 pets and any level 1 pet, obviously start with him in your lineup. Defeat all ...

随机推荐

  1. 题目:写出一条SQL语句,查询工资高于10000,且与他所在部门的经理年龄相同的职工姓名。

    create table Emp( eid char(20) primary key, ename char(20), age integer check (age > 0), did char ...

  2. Arduino - 串口操作函数与示例代码大全

    来源:https://blog.csdn.net/iracer/article/details/50334041 Arduino - 串口操作函数与示例代码大全 本文总结了Arduino常用串口操作函 ...

  3. Java 实现截屏

    操作系统:Windows 10 x64 参考:https://blog.csdn.net/weixin_40657079/article/details/83961708 1 import java. ...

  4. P3469 BLO-Blockade (缩点)

    又可以水紫题了,好开心 前置芝士 无向图割点,然后脑子... 不会的童鞋,出门右转,百度百科...QAQ 首先,对于这道题,我们要求的是,割去每个点及他所连的边后,无向图中,有多少有序点对(\(x\) ...

  5. 从远程库github.com克隆代码时遇到了如下的问题:

    Warning: Permanently added the RSA host key for IP address '13.250.177.223' to the list of known hos ...

  6. RHSA-2018:0007-重要: 内核 安全更新(需要重启、存在EXP)

    [root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) 修复命令: 使用root账号登陆She ...

  7. Oracle - ascii为0的陷阱

    一.概述 ascii0是个空字符,如果将这个字符插入到oracle数据库中会是什么现象,是null吗? 二.正式实验 创建一张测试表 create table test(id int, name va ...

  8. Springboot+Redis(发布订阅模式)跨多服务器实战

    一:redis中发布订阅功能(http://www.redis.cn/commands.html#pubsub) PSUBSCRIBE pattern [pattern -]:订阅一个或者多个符合pa ...

  9. centos8平台使用blkid查看分区信息

    一,blkid的用途 blkid 命令是一个命令行工具,它可以显示关于可用块设备的信息 说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/archite ...

  10. navicate premium黄色版本破解下载

    百度网盘下载 提取码: tsua 按照电脑安装32位或者64位 安装完成后点击最后一个进行破解汉化