【bzoj1568】【JSOI2008】【Blue Mary开公司】【线段树】
来源:互联网 发布:javascript模式 下载 编辑:程序博客网 时间:2024/04/28 19:59
Description
Input
第一行 :一个整数N ,表示方案和询问的总数。 接下来N行,每行开头一个单词“Query”或“Project”。 若单词为Query,则后接一个整数T,表示Blue Mary询问第T天的最大收益。 若单词为Project,则后接两个实数S,P,表示该种设计方案第一天的收益S,以及以后每天比上一天多出的收益P。
Output
对于每一个Query,输出一个整数,表示询问的答案,并精确到整百元(以百元为单位,例如:该天最大收益为210或290时,均应该输出2)。
Sample Input
10
Project 5.10200 0.65000
Project 2.76200 1.43000
Query 4
Query 2
Project 3.80200 1.17000
Query 2
Query 3
Query 1
Project 4.58200 0.91000
Project 5.36200 0.39000
Project 5.10200 0.65000
Project 2.76200 1.43000
Query 4
Query 2
Project 3.80200 1.17000
Query 2
Query 3
Query 1
Project 4.58200 0.91000
Project 5.36200 0.39000
Sample Output
0
0
0
0
0
0
0
0
0
HINT
约定: 1 <= N <= 100000 1 <= T <=50000 0 < P < 100,| S | <= 10^6 提示:本题读写数据量可能相当巨大,请选手注意选择高效的文件读写方式。
题解:同bzoj3165
#include<iostream>#include<cstring>#include<cmath>#include<cstdio>#define N 500000#define P 500010#define MOD 1000000000#define eps 1e-10using namespace std;int t[P<<2],ansa,n,xx,kind,top,a[P],lastans;double b[P],ansb,x,y,x2,y2,p,q;char ch[10];struct use{ double k,b; int l,r; double f(int x){return k*x+b;}}line[N];int cross(use a,use b){ return floor((b.b-a.b)/(a.k-b.k));}use cal(double x,double y,double x2,double y2){ use ans; ans.r=max(x,x2);ans.l=min(x,x2); if (x2!=x) ans.k=(y2-y)/(x2-x),ans.b=y-ans.k*x; else ans.k=0.0,ans.b=max(y,y2); return ans;}int check(double x){ return (x>-eps)-(x<eps); }void up(int k,int x){ double t=line[k].f(x); int ff=check(t-b[x]); if (!a[x]||(ff>0||(ff==0&&k<a[x]))){ a[x]=k;b[x]=t; } }void insert(int k,int l,int r,int x){ if (line[x].l<=l&&r<=line[x].r){ if (!t[k]){t[k]=x;return;} else{ int fl=check(line[x].f(l)-line[t[k]].f(l))>0; int fr=check(line[x].f(r)-line[t[k]].f(r))>0; if (fl&&fr) t[k]=x; else if(fl||fr){ int mid=(l+r)>>1; int p=cross(line[x],line[t[k]]); if (p<=mid&&fl) insert(k<<1,l,mid,x); if (p<=mid&&fr) insert(k<<1,l,mid,t[k]),t[k]=x; if (p>mid&&fl) insert(k<<1|1,mid+1,r,t[k]),t[k]=x; if (p>mid&&fr) insert(k<<1|1,mid+1,r,x); } else up(x,l),up(x,r); } return; } int mid=(l+r)>>1; if (line[x].l<=mid) insert(k<<1,l,mid,x); if (line[x].r>mid) insert(k<<1|1,mid+1,r,x);}void query(int k,int l,int r,int x){ if (t[k]){ double tt=line[t[k]].f(x); int ff=check(tt-ansb); if ((ff>0||(ff==0&&ansa<t[k]))){ ansa=t[k];ansb=tt; } } if (l==r) return; int mid=(l+r)>>1; if (x<=mid) query(k<<1,l,mid,x); else query(k<<1|1,mid+1,r,x); }int main(){ scanf("%d",&n); for (int i=1;i<=n;i++){ scanf("%s",ch); if (ch[0]=='P'){ scanf("%lf%lf",&p,&q); x=1;y=p;x2=P;y2=y+(P-1)*q; line[++top]=cal(x,y,x2,y2); insert(1,1,P,top); } else{ scanf("%d",&xx);ansa=0;ansb=-1.0; query(1,1,P,xx); int ff=check(b[xx]-ansb); if ((ff>0||(ff==0&&a[xx]<ansa))){ ansa=a[xx]; } p=line[ansa].f(xx);p=p/100.0; printf("%d\n",(int)p); } }}
0 0
- 【bzoj1568】【JSOI2008】【Blue Mary开公司】【线段树】
- 【bzoj1568】[JSOI2008]Blue Mary开公司 超哥线段树
- bzoj1568: [JSOI2008]Blue Mary开公司
- BZOJ1568: [JSOI2008]Blue Mary开公司
- 【bzoj1568】[JSOI2008]Blue Mary开公司
- [BZOJ1568][JSOI2008]Blue Mary开公司(超哥线段树)
- 【BZOJ1568】【Tyvj3490】Blue Mary开公司 李超线段树
- 【BZOJ】【P1568】【JSOI2008】【Blue Mary开公司】【题解】【线段树】
- 【JSOI2008】Blue Mary开公司 李超线段树
- [JSOI2008]Blue Mary开公司
- [JSOI2008]Blue Mary开公司
- bzoj 1568: [JSOI2008]Blue Mary开公司(超哥线段树)
- 【bzoj 1568】[JSOI2008]Blue Mary开公司(超哥线段树)
- [李超线段树 模板题] BZOJ 1568 [JSOI2008]Blue Mary开公司
- BZOJ 1568 [JSOI2008]Blue Mary开公司 标记永久化线段树
- 1568: [JSOI2008]Blue Mary开公司
- BZOJ 1568 [JSOI2008]Blue Mary开公司
- 1568: [JSOI2008]Blue Mary开公司
- c语言①
- C++作业-3
- 【CodeForces】[546A]Soldier and Bananas
- 深入理解PHP Opcode缓存原理
- 深入理解PHP Opcode缓存原理
- 【bzoj1568】【JSOI2008】【Blue Mary开公司】【线段树】
- ThinkPHP之__construct()和__initialize()
- LeetCode 221. Maximal Square
- 如何修改CSDN个人头像
- 写ArrayList随手出现No enclosing instance of type <program name> is accessible
- serv-u通过防火墙配置
- nginx配置成服务
- LeetCode 2. Add Two Numbers
- CCF 201512-1数位之和