题意

有\(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代码

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef pair<int,int> pi;
  5. #define sz(x) ((int)(x).size())
  6. #define all(x) (x).begin(),(x).end()
  7. #define rall(x) (x).rbegin(),(x).rend()
  8. #define endl '\n'
  9. const double PI=acos(-1.0);
  10. namespace IO{
  11. bool REOF = 1;//为0表示文件结尾
  12. inline char nc() {
  13. static char buf[100000], *p1 = buf, *p2 = buf;
  14. return p1 == p2 && REOF && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? (REOF = 0, EOF) : *p1++;
  15. }
  16. template<class T>
  17. inline bool read(T &x) {
  18. if(!REOF)return false;
  19. char c = nc();bool f = 0; x = 0;
  20. while (c<'0' || c>'9')c == '-' && (f = 1), c = nc();
  21. while (c >= '0'&&c <= '9')x = (x << 3) + (x << 1) + (c ^ 48), c = nc();
  22. if(f)x=-x;
  23. return true;
  24. }
  25. template<typename T, typename... T2>
  26. inline bool read(T &x, T2 &... rest) {
  27. if(!REOF)return false;
  28. read(x);
  29. return read(rest...);
  30. }
  31. inline bool need(char &c) { return ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'Z')); }
  32. // inline bool need(char &c) { return ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'Z')) || c==' '; }
  33. inline bool read_str(char *a) {
  34. if(!REOF)return false;
  35. while ((*a = nc()) && need(*a) && REOF)++a; *a = '\0';
  36. return true;
  37. }
  38. inline bool read_dbl(double &x){
  39. if(!REOF)return false;
  40. bool f = 0; char ch = nc(); x = 0;
  41. while(ch<'0'||ch>'9') {f|=(ch=='-');ch=nc();}
  42. while(ch>='0'&&ch<='9'){x=x*10.0+(ch^48);ch=nc();}
  43. if(ch == '.') {
  44. double tmp = 1; ch = nc();
  45. while(ch>='0'&&ch<='9'){tmp=tmp/10.0;x=x+tmp*(ch^48);ch=nc();}
  46. }
  47. if(f)x=-x;
  48. return true;
  49. }
  50. template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
  51. template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  52. while(*sdbg!=',')cerr<<*sdbg++;
  53. cerr<<'='<<h<<','<<' '; _dbg(sdbg+1, a...);
  54. }
  55. template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  56. os << "["; for (auto vv : V) os << vv << ","; return os << "]";
  57. }
  58. template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  59. return os << "(" << P.st << "," << P.nd << ")";
  60. }
  61. #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
  62. }
  63. using namespace IO;
  64. const int maxn=2e5+5;
  65. const int maxv=1e6+5;
  66. const int mod=998244353; // 998244353 1e9+7
  67. const ll INF=0x3f3f3f3f3f3f3f3f; // 1e9+7 0x3f3f3f3f 0x3f3f3f3f3f3f3f3f
  68. const double eps=1e-12;
  69. int dx[4]={0,1,0,-1};
  70. //int dx[8]={1,0,-1,1,-1,1,0,-1};
  71. int dy[4]={1,0,-1,0};
  72. //int dy[8]={1,1,1,0,0,-1,-1,-1};
  73. #define ls (x<<1)
  74. #define rs (x<<1|1)
  75. #define mid ((l+r)>>1)
  76. #define lson ls,l,mid
  77. #define rson rs,mid+1,r
  78. /**
  79. * ********** Backlight **********
  80. * 仔细读题
  81. * 注意边界条件
  82. * 记得注释输入流重定向
  83. * 没有思路就试试逆向思维
  84. * 加油,奥利给
  85. */
  86. int n,m,p;
  87. struct weapon{
  88. int a,ca;
  89. }a[maxn];
  90. ll A[maxv];
  91. struct armor{
  92. int b,cb;
  93. }b[maxn];
  94. ll B[maxv];
  95. struct monster{
  96. int x,y,z;
  97. bool operator<(const monster& r){
  98. if(x==r.x)return y<r.y;
  99. return x<r.x;
  100. }
  101. }c[maxn];
  102. ll ma[maxv<<2],tag[maxv<<2];
  103. void change(int x,int val){
  104. ma[x]+=val; tag[x]+=val;
  105. }
  106. void push_up(int x){
  107. ma[x]=max(ma[ls],ma[rs]);
  108. }
  109. void push_down(int x){
  110. if(tag[x]){
  111. change(ls,tag[x]); change(rs,tag[x]);
  112. tag[x]=0;
  113. }
  114. }
  115. void build(int x,int l,int r){
  116. if(l==r){
  117. ma[x]=-B[l];
  118. return;
  119. }
  120. build(lson); build(rson);
  121. push_up(x);
  122. }
  123. void update(int x,int l,int r,int L,int R,int val){
  124. if(l==L && r==R){
  125. change(x,val);
  126. return;
  127. }
  128. push_down(x);
  129. if(R<=mid)update(lson,L,R,val);
  130. else if(L>mid)update(rson,L,R,val);
  131. else{
  132. update(lson,L,mid,val);
  133. update(rson,mid+1,R,val);
  134. }
  135. push_up(x);
  136. }
  137. void solve(){
  138. read(n,m,p);
  139. for(int i=1;i<=n;i++)read(a[i].a,a[i].ca);
  140. for(int i=1;i<=m;i++)read(b[i].b,b[i].cb);
  141. for(int i=1;i<=p;i++)read(c[i].x,c[i].y,c[i].z);
  142. sort(c+1,c+1+p);
  143. memset(A,0x3f,sizeof(A));
  144. for(int i=1;i<=n;i++)A[a[i].a]=min(A[a[i].a],(ll)a[i].ca);
  145. memset(B,0x3f,sizeof(B));
  146. for(int i=1;i<=m;i++)B[b[i].b]=min(B[b[i].b],(ll)b[i].cb);
  147. for(int i=maxv-2;i>=1;i--)B[i]=min(B[i],B[i+1]);
  148. build(1,1,maxv-1);
  149. ll ans=-INF;
  150. for(int i=1,j=1;i<=1e6;i++) if(A[i]!=INF){
  151. while(j<=p && c[j].x<i){
  152. update(1,1,maxv-1,c[j].y+1,maxv-1,c[j].z);
  153. j++;
  154. }
  155. ans=max(ans,ma[1]-A[i]);
  156. }
  157. printf("%lld\n",ans);
  158. }
  159. int main()
  160. {
  161. // freopen("in.txt","r",stdin);
  162. // ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  163. // int _T; read(_T); for(int _=1;_<=_T;_++)solve();
  164. // while(read(n))solve();
  165. solve();
  166. return 0;
  167. }

Codeforces 1321E World of Darkraft: Battle for Azathoth的更多相关文章

  1. CF1320C World of Darkraft: Battle for Azathoth

    线段树 又是熟悉的感觉,又是E题写完了,没调完,不过还好上了紫 CF1295E 可以发现可以打败怪兽的关系类似二维偏序 那么首先考虑第一维(武器)以攻击值($a_{i}$)进行排序 把所有的怪兽以防御 ...

  2. 【42.86%】【Codeforces Round #380D】Sea Battle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. Codeforces 138D World of Darkraft(Multi-Nim)

    [题目链接] http://codeforces.com/problemset/problem/138/D [题目大意] H*W的棋盘中每个点都是L.R.X三者之一,两人轮流选一个点, 若为L则向左下 ...

  4. Codeforces 138D World of Darkraft

    有一个n*m 的棋盘,每个点上标记了L,R,X 中的一个每次能选择一个没有被攻击过的点(i,j),从这个点开始发射线,射线形状为:1. 若字符是 L,向左下角和右上角发,遇到被攻击过的点就停下来2. ...

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

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

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

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

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

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

  8. 2018省赛赛第一次训练题解和ac代码

    第一次就去拉了点思维很神奇的CF题目 2018省赛赛第一次训练 # Origin Title     A CodeForces 607A Chain Reaction     B CodeForces ...

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

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

随机推荐

  1. Java web 小测验

    题目要求: 1登录账号:要求由6到12位字母.数字.下划线组成,只有字母可以开头:(1分) 2登录密码:要求显示“• ”或“*”表示输入位数,密码要求八位以上字母.数字组成.(1分) 3性别:要求用单 ...

  2. 简单python爬虫编写,Python采集妹子图!

    疫情期间在家闲来无事,每天打游戏荒废了一段时间.我觉得自己不能在这么颓废下去,就立马起身写了一点python代码(本人只是python新手). 很多人学习python,不知道从何学起.很多人学习pyt ...

  3. CUDA线程、线程块、线程束、流多处理器、流处理器、网格概念的深入理解

    一.与CUDA相关的几个概念:thread,block,grid,warp,sp,sm. sp: 最基本的处理单元,streaming processor  最后具体的指令和任务都是在sp上处理的.G ...

  4. C#LeetCode刷题之#171-Excel表列序号(Excel Sheet Column Number)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3852 访问. 给定一个Excel表格中的列名称,返回其相应的列序 ...

  5. golang 的 string包

    前言 不做文字搬运工,多做思路整理 就是为了能速览标准库,只整理我自己看过的...... 注意!!!!!!!!!! 单词都是连着的,我是为了看着方便.理解方便才分开的 1.string 中文文档 [英 ...

  6. MSF常用命令备忘录

    msf下的命令 set session x:设置要攻击的session #监听端口反弹PHP shell use exploit/multi/handler set payload php/meter ...

  7. python基本数据类型(三)

    字典{} 冒号前面是key(键)冒号后面是values(值)  键:值 ==键值对 1.索引 s={ 'name':'lifei', 'age':'', 'sex':'man' } print(s[' ...

  8. 可以用命令行控制eclipse断点增加删除、远程调试创建与启动的插件

    java # 创建断点(支持条件断点) curl -X PUT -H "Content-Type:application/json" --data '{"language ...

  9. idea Maven项目 包下载不下来或者已经下载了就是飘红

    0.先在settings.xml加上阿里的镜像在刷新试试 <mirror> <id>aliyunmaven</id> <mirrorOf>*</m ...

  10. Java不可重入锁和可重入锁的简单理解

    基础知识 Java多线程的wait()方法和notify()方法 这两个方法是成对出现和使用的,要执行这两个方法,有一个前提就是,当前线程必须获其对象的monitor(俗称“锁”),否则会抛出Ille ...