Place Your Ad Here

把没用的第一类区间去掉之后, 排序, 然后枚举第二类区间, 在上面死命二分就好了。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); bool chkmax(LL& a, LL b) {
return a < b ? a = b, true : false;
}
bool chkmax(int& a, int b) {
return a < b ? a = b, true : false;
} int Log[N];
struct ST {
PII dp[N][];
void build(int n, PII b[]) {
for(int i = ; i <= n; i++) dp[i][] = b[i];
for(int j = ; j <= Log[n]; j++)
for(int i = ; i+(<<j)- <= n; i++)
dp[i][j] = max(dp[i][j-], dp[i+(<<(j-))][j-]);
}
PII query(int x, int y) {
int k = Log[y - x + ];
return max(dp[x][k], dp[y-(<<k)+][k]);
}
}; int n, m;
PII len[N];
PII gg = mk(, ); pair<PII, int> a[N];
pair<PII, int> b[N];
ST rmq; bool cmp(const pair<PII, int>& a, const pair<PII, int>& b) {
if(a.fi.fi == b.fi.fi) return a.fi.se > b.fi.se;
return a.fi.fi < b.fi.fi;
}
int main() {
for(int i = -(Log[]=-); i < N; i++)
Log[i] = Log[i - ] + ((i & (i - )) == );
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) scanf("%d%d", &a[i].fi.fi, &a[i].fi.se), a[i].se = i;
for(int i = ; i <= m; i++) scanf("%d%d%d", &b[i].fi.fi, &b[i].fi.se, &b[i].se);
sort(a + , a + + n, cmp);
int up = n; n = ;
for(int i = ; i <= up; i++)
if(a[i].fi.se > a[n].fi.se) a[++n] = a[i];
// for(int i = 1; i <= n; i++) printf("%d %d %d ^^\n", a[i].se, a[i].fi.fi, a[i].fi.se);
for(int i = ; i <= n; i++) len[i].fi = a[i].fi.se - a[i].fi.fi, len[i].se = a[i].se;
rmq.build(n, len);
LL ans = ;
for(int i = ; i <= m; i++) {
int L = b[i].fi.fi, R = b[i].fi.se, c = b[i].se, len = , who = ;
int low = , high = n, p = -;
while(low <= high) {
int mid = low + high >> ;
if(a[mid].fi.fi <= L) p = mid, low = mid + ;
else high = mid - ;
}
if(~p && a[p].fi.se > L && chkmax(len, min(R, a[p].fi.se) - L)) who = a[p].se;
low = , high = n, p = -;
while(low <= high) {
int mid = low + high >> ;
if(a[mid].fi.se >= R) p = mid, high = mid - ;
else low = mid + ;
}
if(~p && a[p].fi.fi < R && chkmax(len, R - max(L, a[p].fi.fi))) who = a[p].se;
int Lb = -, Rb = -;
low = , high = n;
while(low <= high) {
int mid = low + high >> ;
if(a[mid].fi.fi >= L) Lb = mid, high = mid - ;
else low = mid + ;
}
low = , high = n;
while(low <= high) {
int mid = low + high >> ;
if(a[mid].fi.se <= R) Rb = mid, low = mid + ;
else high = mid - ;
}
if(~Lb && ~Rb && Lb <= Rb) {
PII t = rmq.query(Lb, Rb);
if(chkmax(len, t.fi)) who = t.se;
}
if(chkmax(ans, 1LL * c * len)) {
gg.fi = who;
gg.se = i;
}
}
if(ans) {
printf("%lld\n", ans);
printf("%d %d\n", gg.fi, gg.se);
} else {
puts("");
}
return ;
} /*
*/

Codeforces 542A Place Your Ad Here的更多相关文章

  1. 【codeforces 803D】Magazine Ad

    [题目链接]:http://codeforces.com/contest/803/problem/D [题意] 给你一个字符串; 其中的空格和连字符表示可以折叠的部分 (就是说能在那个位置把字符串分成 ...

  2. Codeforces Global Round 3(A-D)

    我凉了..感觉自己啥都不会做,搞不好起床就绿了啊 代码和反思起床补,今天要反了个大思的 A. Another One Bites The Dust 把所有的ab排在一起然后两边叉a和b #includ ...

  3. Codeforces Edu Round 51 A-D

    A. Vasya And Password 模拟题,将所缺的种类依次填入"出现次数$ >1 $"的位置,替换掉Ta即可. #include <iostream> ...

  4. Codeforces Edu Round 50 A-D

    A. Function Height 由于只能提升\(x\)为奇数的点,每个三角形的底一定为\(2\), 则要求我们求: \(2 * (h_1 + h_2 + - + h_n) / 2 = k\),使 ...

  5. Codeforces Edu Round 48 A-D

    A. Death Note 简单模拟,可用\(\%\)和 \(/\)来减少代码量 #include <iostream> #include <cstdio> using nam ...

  6. Codeforces Edu Round 64 A-D

    A. Inscribed Figures 分类讨论打表即可. PS:这道题翻译有歧义. 这样稍微翻转一下,就可以是\(7\)个交点呀...(大概是我没看英文题干导致的惨案) #include < ...

  7. Codeforces Edu Round 59 A-D

    A. Digits Sequence Dividing 注意特殊情况,在\(n = 2\)时除非\(str[1] >= str[2]\),否则可以把第一个数划分下来,剩下的数直接当成一组,一定满 ...

  8. Codeforces Edu Round 57 A-D

    A. Find Divisible 符合条件的区间一定可以选择\(l, l * 2\). 证明\(l * 2 <= r\) 假设存在一组解,\(x, x * d (l <= x <= ...

  9. Codeforces Edu Round 56 A-D

    A. Dice Rolling 把\(x\)分解为\(a * 6 + b\),其中\(a\)是满6数,\(b\)满足\(1 <= b < 6\),即可... #include <io ...

随机推荐

  1. 使用tomcat发布含有shtml文件的web程序

    平常都是使用html或jsp,当导入含有shtml的一个web项目时,向平常一样使用Jetty运行,访问到shtml文件时,直接在浏览器上显示出了源码. 查询,使用tomcat发布,修改tomcat的 ...

  2. Linux VPS基础命令 - cp复制文件命令

    cp命令在Linux VPS操作和应用过程中还是比较常用的,我们可以用来复制文件或者文件夹,重命名一个新的文件以及复制到其他路径中用于文件的转移. 举例用法: 1.复制root目录下的itbulu.c ...

  3. 随机函数rand()和srand()

    C++中随机函数rand()和srand()的用法 一.rand() 函数名:   rand     功   能:   随机数发生器   用   法:   int rand(void); 所在头文件: ...

  4. 让NotePad++添加到右键快捷方式

    添加后的效果图: 操作方式: 第一步:在桌面上新建一个txt文本文档,然后将写入如下内容 Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT ...

  5. Golang 类型转换,断言和显式强制转换

    1 前言 类型转换,可以用断言(只能使用在interface{}类型转换成其它类型)和显式类型强制转换(常规是用于基本类型) 2 代码 //graphql-go func(params graphql ...

  6. MYSQL修改字段

    当字段为空则插入0,不为空则原来的值  UPDATE t_pm_scheduleSET lesson_room_id1 = IFNULL(lesson_room_id1, 0), lesson_roo ...

  7. C#中lock死锁实例教程

    这篇文章主要介绍了C#中lock死锁的用法,对于共享资源的访问及C#程序设计的安全性而言,有着非常重要的意义!需要的朋友可以参考下 链接:http://www.jb51.net/article/543 ...

  8. sleep()和wait()的区别及wait方法的一点注意事项

    一.查看API sleep是Thread类的方法,导致此线程暂停执行指定时间,给其他线程执行机会,但是依然保持着监控状态,过了指定时间会自动恢复,调用sleep方法不会释放锁对象. 当调用sleep方 ...

  9. Confluence 6 编辑站点欢迎消息

    通过编辑欢迎信息能够为你站点的主页面添加一些个人信息. 站点的欢迎信息显示在站点主面板的右侧,这是你对站点添加声明,连接,有关你项目组美好回忆照片的完美位置. 你需要 Confluence 管理员权限 ...

  10. LeetCode(3):无重复字符的最大子串

    本内容是LeetCode第三道题目:无重复字符的最大子串 # -*- coding: utf-8 -*- """ Created on Sun Mar 10 20:14: ...