CF1320C World of Darkraft: Battle for Azathoth
线段树
又是熟悉的感觉,又是E题写完了,没调完,不过还好上了紫
可以发现可以打败怪兽的关系类似二维偏序
那么首先考虑第一维(武器)以攻击值($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的更多相关文章
- Codeforces 1321E World of Darkraft: Battle for Azathoth
题意 有\(n\)个武器,第\(i\)个武器攻击力为\(a_i\),价值\(ca_i\). 有\(m\)个防具,第\(i\)个防具防御力为\(b_i\),价值\(cb_i\). 有\(p\)个怪,第\ ...
- Codeforces Round #625 (1A - 1D)
A - Journey Planning 题意: 有一列共 n 个城市, 每个城市有美丽值 b[i], 要访问一个子序列的城市, 这个子序列相邻项的原项数之差等于美丽值之差, 求最大的美丽值总和. ...
- Solution -「线段树」题目集合
T1 无聊的数列 来自:Link flag 帖先从水题入手. 首先分析题目,它是以等差数列为原型进行的修改.等差数列一大性质就是其差分数列的值除第一项以外均相等. 于是不难想到使用差分数列进行维护. ...
- 【Virt.Contest】CF1321(div.2)
第一次打虚拟赛. CF 传送门 T1:Contest for Robots 统计 \(r[i]=1\) 且 \(b[i]=0\) 的位数 \(t1\) 和 \(r[i]=0\) 且 \(b[i]=1\ ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- Codeforces 738D. Sea Battle 模拟
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- error C2065: “uint8_t”: 未声明的标识符
转载:https://blog.csdn.net/lys07962000/article/details/12052571 参考: http://blog.csdn.net/chenxin_130/a ...
- Java基础系列-RandomAccess
原创文章,转载请标注出处:https://www.cnblogs.com/V1haoge/p/10755424.html Random是随机的意思,Access是访问的意思,合起来就是随机访问的意思. ...
- OracleOggan安装并测试同步数据步骤!
Oracle Golden Gate (ogg)安装使用说明 Golden Gate(简称OGG)提供异构环境下交易数据的实时捕捉.变换.投递等功能. OGG支持的异构环境有: OGG的特性: ①对生 ...
- iOS企业重签名管理软件之风车签名
这是一款在Mac平台下安全可控的iOS签名管理软件,旨在对签名后的APP能够完全控制,包括APP的开启或禁用.设置到期时间锁.注入第三方动态库文件.设置安装限量.修改APP名称和自定义Bundle I ...
- [转载]volitale关键字详解
来看这个代码: int fun(int& a) { int b = a; int c = a; return a+b+c; } int main() { int a=1; //........ ...
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)解决方案
在Win7下使用MySQL5.6.35创建用户时,提示权限不足,具体解决方案如下: 1 停止mysql服务 net stop mysql 2 打开新的cmd窗口,切换到bin目录,运行如下命令,cmd ...
- linux(centos8):配置docker的cgroup driver为systemd
一,为什么要修改docker的cgroup driver? 1,什么是cgroups? cgroups(Control Groups) 是 linux 内核提供的一种机制 它可以限制.记录任务组所使用 ...
- php+nginx 整合
php编译 https://www.cnblogs.com/php-linux/p/12360858.html nginx编译 https://www.cnblogs.com/php-linux/p/ ...
- Java安全之Commons Collections3分析
Java安全之Commons Collections3分析 文章首发:Java安全之Commons Collections3分析 0x00 前言 在学习完成前面的CC1链和CC2链后,其实再来看CC3 ...
- js和vue方法的相互调用(iframe父子页面的方法相互调用)。
项目是前后端不分离的,模板引擎使用的JSP. 但是使用了Vue+ElementUI,这里列举一些常用的调用方式,有时候可能. 在js里调用vue方法 我们需要把方法注册到vue对象之外的页面,所以对与 ...