I guess there's not much point in reminding you that Nvodsk winters aren't exactly hot. That increased the popularity of the public transport dramatically. The route of bus 62 has exactly n stops (stop 1 goes first on its way and stop n goes last). The stops are positioned on a straight line and their coordinates are 0 = x1 < x2 < ... < xn.

Each day exactly m people use bus 62. For each person we know the number of the stop where he gets on the bus and the number of the stop where he gets off the bus. A ticket from stop a to stop b (a < b) costs xb - xa rubles. However, the conductor can choose no more than one segment NOT TO SELL a ticket for. We mean that conductor should choose C and D (С <= D) and sell a ticket for the segments [AC] and [DB], or not sell the ticket at all. The conductor and the passenger divide the saved money between themselves equally. The conductor's "untaxed income" is sometimes interrupted by inspections that take place as the bus drives on some segment of the route located between two consecutive stops. The inspector fines the conductor by c rubles for each passenger who doesn't have the ticket for this route's segment.

You know the coordinated of all stops xi; the numbers of stops where the i-th passenger gets on and off, ai and bi (ai < bi); the fine c; and also pi — the probability of inspection on segment between the i-th and the i + 1-th stop. The conductor asked you to help him make a plan of selling tickets that maximizes the mathematical expectation of his profit.

Input

The first line contains three integers nm and c (2 ≤ n ≤ 150 000, 1 ≤ m ≤ 300 000, 1 ≤ c ≤ 10 000).

The next line contains n integers xi (0 ≤ xi ≤ 109x1 = 0, xi < xi + 1) — the coordinates of the stops on the bus's route.

The third line contains n - 1 integer pi (0 ≤ pi ≤ 100) — the probability of inspection in percents on the segment between stop i and stop i + 1.

Then follow m lines that describe the bus's passengers. Each line contains exactly two integers ai and bi (1 ≤ ai < bi ≤ n) — the numbers of stops where the i-th passenger gets on and off.

Output

Print the single real number — the maximum expectation of the conductor's profit. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

Examples

Input
3 3 10
0 10 100
100 0
1 2
2 3
1 3
Output
90.000000000
Input
10 8 187
0 10 30 70 150 310 630 1270 2550 51100
13 87 65 0 100 44 67 3 4
1 10
2 9
3 8
1 5
6 10
2 7
4 10
4 5
Output
76859.990000000

题意:有从左到右1到N个站,每一站到下一战的费用是两站间距离,即X[i+1]-X[i]。现在假设乘客从a站到b站,那么他可以和售票员密谋,不买其中连续一段的票,然后这些钱两人对半分。而每一站到下一站有被发现的几率为Pi,如果被发现就会罚款C元。有M个乘客,问售票员一共最多赚多少钱。

思路:乘客之间没有联系,单独考虑,我们保存每一站到下一站的收益,即X[i+1]-X[i]-Pi*C,那么现在问题转化为区间最大连续区间值。也就是裸的线段树题了。

手动打的丑代码:

#include<bits/stdc++.h>
#define piii pair<pair<double,double>,double>
#define F first
#define S second
using namespace std;
const int maxn=;
double x[maxn],a[maxn];
double sum[maxn]; piii Mx[maxn];//0左,1右,2最大
void build(int Now,int L,int R)
{
if(L==R){
sum[Now]=a[L]; Mx[Now].F.F=Mx[Now].F.S=a[L];
Mx[Now].S=max(a[L],0.0);
return ;
}
int Mid=(L+R)>>;
build(Now<<,L,Mid); build(Now<<|,Mid+,R);
sum[Now]=sum[Now<<]+sum[Now<<|];
Mx[Now].F.F=max(Mx[Now<<].F.F,sum[Now<<]+Mx[Now<<|].F.F);
Mx[Now].F.S=max(Mx[Now<<|].F.S,sum[Now<<|]+Mx[Now<<].F.S);
Mx[Now].S=max(max(Mx[Now<<].S,Mx[Now<<|].S),Mx[Now<<].F.S+Mx[Now<<|].F.F);
}
piii query(int Now,int L,int R,int l,int r)
{
if(l<=L&&r>=R) return Mx[Now];
int Mid=(L+R)/;
if(r<=Mid) return query(Now<<,L,Mid,l,r);
if(l>Mid) return query(Now<<|,Mid+,R,l,r);
else {
piii res,tmp;
res=query(Now<<,L,Mid,l,r);
tmp=query(Now<<|,Mid+,R,l,r);
res.S=max(max(res.S,tmp.S),res.F.S+tmp.F.F);
res.F.F=max(res.F.F,sum[Now<<]+tmp.F.F);
res.F.S=max(tmp.F.S,sum[Now<<|]+res.F.S);
return res;
}
}
int main()
{
int N,M,i; double C,P,ans=;
scanf("%d%d%lf",&N,&M,&C);
for(i=;i<=N;i++) scanf("%lf",&x[i]);
for(i=;i<N;i++){
scanf("%lf",&P);
a[i]=(x[i+]-x[i])/-C*P/100.0;
}
build(,,N-);
for(i=;i<=M;i++){
int L,R; scanf("%d%d",&L,&R);
ans+=query(,,N-,L,R-).S;
}
printf("%.8lf\n",ans);
return ;
}

以及别人的重载加法的令人赏心悦目的代码:

#include <stdio.h>
#define db double
const int N=;
const int M=*N;
db max(db a, db b){ return a>b?a:b;}
struct Node
{
db l,r,sum,best;
Node(){}
Node(db x){ l=r=best=max(x,);sum=x;}
} node[M];
Node operator + (Node a, Node b)
{
Node ans;
ans.best=max(a.best,b.best);
ans.best=max(ans.best,a.r+b.l);
ans.sum=a.sum+b.sum;
ans.l=max(a.l,a.sum+b.l);
ans.r=max(b.r,b.sum+a.r);
return ans;
}
db sub[N];
int ls[M],rs[M],tsz,root;
void Build(int &c, int ss, int se)
{
c=++tsz;
if(ss==se){ node[c]=Node(sub[ss]);return;}
int mid=ss+se>>;
Build(ls[c],ss,mid);
Build(rs[c],mid+,se);
node[c]=node[ls[c]]+node[rs[c]];
}
Node Get(int c, int ss, int se, int qs, int qe)
{
if(qs<=ss && qe>=se) return node[c];
int mid=ss+se>>;
if(qe<=mid) return Get(ls[c],ss,mid,qs,qe);
if(qs>mid) return Get(rs[c],mid+,se,qs,qe);
return Get(ls[c],ss,mid,qs,qe)+Get(rs[c],mid+,se,qs,qe);
}
int x[N],p[N];
int main()
{
int n,m,c,i,l,r;
scanf("%i %i %i",&n,&m,&c);
for(i=;i<=n;i++) scanf("%i",&x[i]);
for(i=;i<=n;i++) scanf("%i",&p[i]),sub[i]=(db)(x[i]-x[i-])/-(db)c*p[i]/;
Build(root,,n);
db sol=;
while(m--)
{
scanf("%i %i",&l,&r);
sol+=Get(root,,n,l+,r).best;
Node tmp=Get(root,,n,l+,r);
}
printf("%.12llf\n",sol);
return ;
}

CodeForces - 150C :Smart Cheater (线段树,求最大连续区间)的更多相关文章

  1. Buses and People CodeForces 160E 三维偏序+线段树

    Buses and People CodeForces 160E 三维偏序+线段树 题意 给定 N 个三元组 (a,b,c),现有 M 个询问,每个询问给定一个三元组 (a',b',c'),求满足 a ...

  2. [Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路)

    [Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路) 题面 有n个空心物品,每个物品有外部体积\(out_i\)和内部体积\(in_i\),如果\(in_i& ...

  3. [Codeforces 316E3]Summer Homework(线段树+斐波那契数列)

    [Codeforces 316E3]Summer Homework(线段树+斐波那契数列) 顺便安利一下这个博客,给了我很大启发(https://gaisaiyuno.github.io/) 题面 有 ...

  4. 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)

    原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...

  5. UVA 11983 Weird Advertisement --线段树求矩形问题

    题意:给出n个矩形,求矩形中被覆盖K次以上的面积的和. 解法:整体与求矩形面积并差不多,不过在更新pushup改变len的时候,要有一层循环,来更新tree[rt].len[i],其中tree[rt] ...

  6. BNU 2418 Ultra-QuickSort (线段树求逆序对)

    题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=2418 解题报告:就是给你n个数,然后让你求这个数列的逆序对是多少?题目中n的范围是n & ...

  7. hdu 1394 (线段树求逆序数)

    <题目链接> 题意描述: 给你一个有0--n-1数字组成的序列,然后进行这样的操作,每次将最前面一个元素放到最后面去会得到一个序列,那么这样就形成了n个序列,那么每个序列都有一个逆序数,找 ...

  8. xdoj-1324 (区间离散化-线段树求区间最值)

    思想 : 1 优化:题意是覆盖点,将区间看成 (l,r)转化为( l-1,r) 覆盖区间 2 核心:dp[i]  覆盖从1到i区间的最小花费 dp[a[i].r]=min (dp[k])+a[i]s; ...

  9. 4163 hzwer与逆序对 (codevs + 权值线段树 + 求逆序对)

    题目链接:http://codevs.cn/problem/4163/ 题目:

  10. poj2299 Ultra-QuickSort(线段树求逆序对)

    Description In this problem, you have to analyze a particular sorting algorithm. The algorithm proce ...

随机推荐

  1. LeetCode:对角线遍历【498】

    LeetCode:对角线遍历[498] 题目描述 给定一个含有 M x N 个元素的矩阵(M 行,N 列),请以对角线遍历的顺序返回这个矩阵中的所有元素,对角线遍历如下图所示. 示例: 输入: [ [ ...

  2. freeMarker入门示例

    1.创建Web项目freeMarkerDemo. 2.添加jar包---freemarker-2.3.9.jar. 3.在WebContent目录下新建templates文件夹,用于放置模板文件ftl ...

  3. EGLImage与纹理

    http://blog.csdn.net/sunnytina/article/details/51895406 Android使用Direct Textures提高glReadPixels.glTex ...

  4. requestAnimationFrame 的实验性实践

    记得当 requestAnimationFrame 出现时我立马就石更了,就跟初次玩耍 transition 时一样,欣喜若狂... 然后,然后特么的就懵逼了,这明明就是口挖不通的深井呀(如果是我傻, ...

  5. python:列表的方法

    注意:在列表的类方法一般是没有返回值的,如果将处理过的列表给新变量,新变量是空类型.如:>>>a=[1,2]>>>b=a.append(3)>>> ...

  6. transition失效问题

    关于transition,css教程中有一个很简单的例子: <!DOCTYPE html> <html> <head> <meta charset=" ...

  7. Docker 容器监控平台-Weave Scope

    官网地址:https://www.weave.works/oss/scope/ 安装 执行如下脚本安装运行 Weave Scope. curl -L git.io/scope -o /usr/loca ...

  8. eclipse中web项目部署到本地tomcat中,但是在本地的tomcat的webapp下找不到发布的项目

    eclipse不像MyEclipse默认将项目部署到tomcat安装目录下的webapps中,而默认部署到工作目录下 为了使项目默认部署到tomcat安装目录下的webapps中,show view- ...

  9. HMM简单理解(来自quora&其他网上资料)

    转载自quora: 连接:https://www.quora.com/What-is-a-simple-explanation-of-the-Hidden-Markov-Model-algorithm ...

  10. 2.mysql高级查询

    01.SQL高级查询_排序     1.排序语句:order by 排序字段名  asc(默认的-升序) / desc(降序);     2.例如:查询所有服装类商品,将查询结果以价格升序排序:   ...