题意

有\(n\)个武器,第\(i\)个武器攻击力为\(a_i\),价值\(ca_i\)。

有\(m\)个防具,第\(i\)个防具防御力为\(b_i\),价值\(cb_i\)。

有\(p\)个怪,第\(i\)个怪攻击力为\(x_i\),防御力为\(y_i\),价值\(z_i\)。

可以选择\(1\)个武器和\(1\)个防具,假设选择第\(i\)个武器和第\(j\)个防具,那么你需要花费\(a_i+b_j\),且可以杀死所有满足攻击力小于\(a_i\)且防御力小于\(b_j\)的怪,并获得这些怪物的价值。

问怎么选择从而使收益最大。

注意必须选择1个武器和1个防具。

解题思路

用权值线段树维护防具,表示选择防御力为\(i\)的防具的收益,初始值为代价的负数。

枚举攻击力,将所有攻击力小于当前枚举值的怪都加入到权值线段树中,加入是为区间加操作,范围是\(\left[当前怪的防御力+1,防御力的最大值\right]\)。注意这里怪可以按照攻击力升序排序以降低复杂度。

现在,权值线段树中的最大值减去选择当前攻击力的代价就是选择当前攻击力的最大收益。在枚举攻击力的过程中更新最大收益即可。

AC代码

#include <bits/stdc++.h>
using namespace std; typedef long long ll;
typedef pair<int,int> pi; #define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define endl '\n' const double PI=acos(-1.0); namespace IO{
bool REOF = 1;//为0表示文件结尾
inline char nc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && REOF && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? (REOF = 0, EOF) : *p1++;
} template<class T>
inline bool read(T &x) {
if(!REOF)return false;
char c = nc();bool f = 0; x = 0;
while (c<'0' || c>'9')c == '-' && (f = 1), c = nc();
while (c >= '0'&&c <= '9')x = (x << 3) + (x << 1) + (c ^ 48), c = nc();
if(f)x=-x;
return true;
} template<typename T, typename... T2>
inline bool read(T &x, T2 &... rest) {
if(!REOF)return false;
read(x);
return read(rest...);
} inline bool need(char &c) { return ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'Z')); }
// inline bool need(char &c) { return ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'Z')) || c==' '; } inline bool read_str(char *a) {
if(!REOF)return false;
while ((*a = nc()) && need(*a) && REOF)++a; *a = '\0';
return true;
} inline bool read_dbl(double &x){
if(!REOF)return false;
bool f = 0; char ch = nc(); x = 0;
while(ch<'0'||ch>'9') {f|=(ch=='-');ch=nc();}
while(ch>='0'&&ch<='9'){x=x*10.0+(ch^48);ch=nc();}
if(ch == '.') {
double tmp = 1; ch = nc();
while(ch>='0'&&ch<='9'){tmp=tmp/10.0;x=x+tmp*(ch^48);ch=nc();}
}
if(f)x=-x;
return true;
} template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; } template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
while(*sdbg!=',')cerr<<*sdbg++;
cerr<<'='<<h<<','<<' '; _dbg(sdbg+1, a...);
} template<class T> ostream &operator<<(ostream& os, vector<T> V) {
os << "["; for (auto vv : V) os << vv << ","; return os << "]";
} template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
return os << "(" << P.st << "," << P.nd << ")";
} #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
} using namespace IO;
const int maxn=2e5+5;
const int maxv=1e6+5;
const int mod=998244353; // 998244353 1e9+7
const ll INF=0x3f3f3f3f3f3f3f3f; // 1e9+7 0x3f3f3f3f 0x3f3f3f3f3f3f3f3f
const double eps=1e-12; int dx[4]={0,1,0,-1};
//int dx[8]={1,0,-1,1,-1,1,0,-1};
int dy[4]={1,0,-1,0};
//int dy[8]={1,1,1,0,0,-1,-1,-1}; #define ls (x<<1)
#define rs (x<<1|1)
#define mid ((l+r)>>1)
#define lson ls,l,mid
#define rson rs,mid+1,r /**
* ********** Backlight **********
* 仔细读题
* 注意边界条件
* 记得注释输入流重定向
* 没有思路就试试逆向思维
* 加油,奥利给
*/
int n,m,p;
struct weapon{
int a,ca;
}a[maxn];
ll A[maxv]; struct armor{
int b,cb;
}b[maxn];
ll B[maxv]; struct monster{
int x,y,z;
bool operator<(const monster& r){
if(x==r.x)return y<r.y;
return x<r.x;
}
}c[maxn]; ll ma[maxv<<2],tag[maxv<<2];
void change(int x,int val){
ma[x]+=val; tag[x]+=val;
} void push_up(int x){
ma[x]=max(ma[ls],ma[rs]);
} void push_down(int x){
if(tag[x]){
change(ls,tag[x]); change(rs,tag[x]);
tag[x]=0;
}
} void build(int x,int l,int r){
if(l==r){
ma[x]=-B[l];
return;
}
build(lson); build(rson);
push_up(x);
} void update(int x,int l,int r,int L,int R,int val){
if(l==L && r==R){
change(x,val);
return;
}
push_down(x);
if(R<=mid)update(lson,L,R,val);
else if(L>mid)update(rson,L,R,val);
else{
update(lson,L,mid,val);
update(rson,mid+1,R,val);
}
push_up(x);
} void solve(){
read(n,m,p); for(int i=1;i<=n;i++)read(a[i].a,a[i].ca);
for(int i=1;i<=m;i++)read(b[i].b,b[i].cb);
for(int i=1;i<=p;i++)read(c[i].x,c[i].y,c[i].z); sort(c+1,c+1+p); memset(A,0x3f,sizeof(A));
for(int i=1;i<=n;i++)A[a[i].a]=min(A[a[i].a],(ll)a[i].ca); memset(B,0x3f,sizeof(B));
for(int i=1;i<=m;i++)B[b[i].b]=min(B[b[i].b],(ll)b[i].cb);
for(int i=maxv-2;i>=1;i--)B[i]=min(B[i],B[i+1]); build(1,1,maxv-1); ll ans=-INF;
for(int i=1,j=1;i<=1e6;i++) if(A[i]!=INF){
while(j<=p && c[j].x<i){
update(1,1,maxv-1,c[j].y+1,maxv-1,c[j].z);
j++;
}
ans=max(ans,ma[1]-A[i]);
} printf("%lld\n",ans);
} int main()
{
// freopen("in.txt","r",stdin);
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
// int _T; read(_T); for(int _=1;_<=_T;_++)solve();
// while(read(n))solve();
solve();
return 0;
}

最新文章

  1. C#: using JsonReader avoid Deserialize Json to dynamic
  2. Java: some learning note for Java calssloader and Servlet
  3. candence 笔记总结
  4. 构建者模式(Builder)示例代码
  5. jQuery 、js 设置 显示隐藏
  6. Linux试题及答案
  7. Spark源码剖析(一):如何将spark源码导入到IDEA中
  8. printk的用法
  9. 【工具篇】抓包中的王牌工具—Fiddler (2-工具介绍)
  10. python操作redis命令
  11. arcpy加载mxd文件时,无效的MXD路径,提示assert (os.path.isfile(mxd) or (mxd.lower() == &quot;current&quot;)), gp.getIDMessage(89004, &quot;Invalid MXD filename&quot;)
  12. SQL Server 2008 management studio 无法连接到(local)解决方法
  13. hive web界面管理
  14. python之路-网络基础
  15. STM 软件事务内存——本质是为提高并发,通过事务来管理内存的读写访问以避免锁的使用
  16. VS报:&quot;dll标记为系统必备组件,必须对其进行强签名&quot;错误
  17. oracle导入提示IMP-00013: 只有 DBA 才能导入由其他 DBA 导出的文件
  18. 2017年USNews美国大学研究生专业排名
  19. bzoj 1070 [SCOI2007]修车——网络流(拆边)
  20. sigmoid function和softmax function

热门文章

  1. ios 淘宝评论详情、朋友圈布局masony实现
  2. kubernetes 中安装 heapster 问题
  3. python深挖65万人的明星贴吧,探究上万个帖子的秘密
  4. 菊长说丨一文读懂MySQL4种事务隔离级别
  5. CVE-2020-14644 weblogic iiop反序列化漏洞
  6. C#LeetCode刷题之#671-二叉树中第二小的节点(Second Minimum Node In a Binary Tree)
  7. 在K3s上使用Kong网关插件,开启K3s的无限可能!
  8. day5 字符串 函数
  9. 手把手教你在win10下搭建pytorch GPU环境(Anaconda+Pycharm)
  10. Linux C++实现一服务器与多客户端之间的通信