//上图绿色扫描线右侧少画了一条扫描线。

很多区间把数轴分成了很多段,看哪个点的(区间覆盖数*该点权值)最大。

显然在某个区间的右端点的答案是最优的。

排序后 用扫描线从左到右扫描,维护每个点的覆盖数,就是遇到左端点时cnt++,右端点时更新ans、cnt--。

若某个点既有左端点,又有右端点,就把左端点放在前面。

 #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define N 100001
ll ans;
int t1,t2,m,cnt,n;
struct Node{int v;bool dir;Node(const int &a,const bool &b){v=a;dir=b;}Node(){}}a[N<<];
bool operator < (const Node &a,const Node &b){return a.v!=b.v?a.v<b.v:a.dir<b.dir;}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d%d",&t1,&t2);
a[++m]=Node(t1,); a[++m]=Node(t2,);
}
sort(a+,a+m+);
for(int i=;i<=m;i++)
{
if(!a[i].dir) cnt++;
else
{
ans=max(ans,(ll)cnt*(ll)a[i].v);
cnt--;
}
}
cout<<ans<<endl;
return ;
}

【离散化】【扫描线】CH Round #59 - OrzCC杯NOIP模拟赛day1 队爷的新书的更多相关文章

  1. 【强联通分量缩点】【最长路】【spfa】CH Round #59 - OrzCC杯NOIP模拟赛day1 队爷的讲学计划

    10分算法:对于城市网络为一条单向链的数据, 20分算法:对于n<=20的数据,暴力搜出所有的可能路径. 结合以上可以得到30分. 60分算法:分析题意可得使者会带着去的城市也就是这个城市所在强 ...

  2. 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...

  3. 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...

  4. 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...

  5. CH Round #59 - OrzCC杯NOIP模拟赛day1

    第一题:队爷的新书 题意简述:给定n个闭区间,求出一个数p使它与包含它的区间数的积最大,输出这个积. 分析:使用一个差分数组g,每个区间[l,r],l位置加1,r+1的位置减1,从前往后统计,得到对于 ...

  6. CH Round #58 - OrzCC杯noip模拟赛day2

    A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...

  7. CH Round #48 - Streaming #3 (NOIP模拟赛Day1)

    A.数三角形 题目:http://www.contesthunter.org/contest/CH%20Round%20%2348%20-%20Streaming%20%233%20(NOIP模拟赛D ...

  8. CH Round #54 - Streaming #5 (NOIP模拟赛Day1)

    A.珠 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2354%20-%20Streaming%20%235%20(NOIP模拟赛Day1)/珠 题解:sb题, ...

  9. CH Round #54 - Streaming #5 (NOIP模拟赛Day1)解题报告

    最近参加了很多CH上的比赛呢~Rating--了..题目各种跪烂.各种膜拜大神OTZZZ T1珠 描述 萌蛋有n颗珠子,每一颗珠子都写有一个数字.萌蛋把它们用线串成了环.我们称一个数字串是有趣的,当且 ...

随机推荐

  1. Supermarket [堆]

    Supermarket 题目描述 有一个商店有许多批货,每一批货又有N(0<=N<=\(10^4\))个商品,同时每一样商品都有收益Pi​ ,和过期时间Di​ (1<=Pi,Di&l ...

  2. POJ3020:Antenna Placement(二分图匹配)

    Antnna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11093   Accepted: 5459 ...

  3. POJ2236:Wireless Network(并查集)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 39772   Accepted: 164 ...

  4. org.apache.http.conn.HttpHostConnectException: Connection to xxx refused.

    if you are using emulator to run your app for local server. mention the local ip as 10.0.2.2 and hav ...

  5. js如何弹出新窗口

    js如何弹出新窗口 时间:2012-4-22 弹出新窗口也是在网页设计中会经常用到的,其用法也很简单,是通过调用javascript的内置函数windows.open来产生的.  window.ope ...

  6. bzoj 3223 裸splay

    裸的splay 今儿写的splay,由于自己刚开始学,发现几个容易漏掉的地方 1:开始给所有的儿子赋值为-1 2:给max[-1]赋值为-maxlongint 3:开始father[root]:=sr ...

  7. ajax获取django的csrf_token

    ''' 方法一: data: { 'teamid': teamid, csrfmiddlewaretoken: '{{ csrf_token }}' //data: {name: 'john', cs ...

  8. Swift, Playgrounds, and XCPlayground

    http://www.codeschool.com/blog/2014/12/12/swift-playgrounds-xcplayground/ Swift, Playgrounds, and XC ...

  9. 【反演复习计划】【bzoj2820】YY的GCD

    这题跟2818一样的,只不过数据水一点,可以用多一个log的办法水过去…… 原题意思是求以下式子:$Ans=\sum\limits_{isprime(p)}\sum\limits_{i=1}^{a}\ ...

  10. Long类型的坑,第一次遇见

    注意下面标红的code,如果不加这段代码会有问题,原因是一个比较的是地址,一个比较的是value,会导致不同,程序逻辑出错!加上后比较的就是值!!! allViewMap.put("proj ...