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. Oracle查询结果列的加减、求和、连接、列值相乘

    select prod.amount,prod.plansum,(prod.plansum-prod.amount) as borrow,d.enum_value from ----结果集相减(sel ...

  2. eclipse连接SqlServer2008(被它搞得惨兮兮)

    建民大叔告诉我要考试做一个系统要求连接SqlServer2008,于是我便开始了“炼狱”,人家连接起来一路绿灯,我却一路红灯所以决定把它记录下来,给后来人提供方便. 第一个红灯: 启动服务后利用cmd ...

  3. MySQL密码的恢复方法

    MySQL密码的恢复方法之一 1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的 状态 ...

  4. 【HackerRank】Insertion Sort Advanced Analysis(归并排序求数列逆序数对)

    Insertion Sort is a simple sorting technique which was covered in previous challenges. Sometimes, ar ...

  5. Luogu-4022 [CTSC2012]熟悉的文章

    广义后缀自动机+DP 对于作文库建出广义后缀自动机,广义自动机就是在每次添加一个字符串之前把\(last=0\),然后正常添加就好了 对于每个询问串,预处理出每个位置\(i\)能向前匹配的最长长度\( ...

  6. waitpid使用的一点问题

    使用waipid的时候遇到了一个奇怪的问题,将情况简化后描述一下. 有关waitpid的基本介绍参见这里一下:http://www.cnblogs.com/mickole/p/3187770.html ...

  7. 实例说明Java中的null(转)

    让我们先来看下面的语句: String x = null; 1. 这个语句到底做了些什么?  让我们回顾一下什么是变量,什么是变量值.一个常见的比喻是 变量相当于一个盒子.如同可以使用盒子来储存物品一 ...

  8. ubuntu环境下安装Redis

    1.命令行安装 sudo apt-get update sudo apt-get install redis-server 2.启动redis $redis-server :C Aug ::42.26 ...

  9. compile to 32-bit elf file

    nasm -f elf -o a.o a.asm gcc -c -m32 -o b.o b.c ld -s -m elf_i386 -Ttext 0x30400 -o b.bin b.o a.o

  10. Enum Binding ItemsSource In WPF

    Enum Binding ItemsSource In WPF   在WPF中枚举绑定到ItemsSource. 一.通过ObjectDataProvider 获取Enum数据源 首先我们定义一个En ...