您的位置:首页 > 产品设计 > UI/UE

[李超线段树 模板题] BZOJ 1568 [JSOI2008]Blue Mary开公司

2017-02-01 22:42 537 查看
模板题 复习下 顺便骗骗访问量

奇怪的是这个题上网找标程

自己和标程对拍拍出错 标程之间对拍也拍出错

但就是都A了

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;

inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
return *p1++;
}
inline void read(int &x){
char c=nc(),b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
inline void read(char &x){
for (x=nc();!(x>='A' && x<='Z');x=nc());
}
#define C (c=nc())
inline void read(double &x){
char c;int p=1;
double t=10; x=0;
while (C!='-'&&'0'>c||c>'9'); if (c=='-') p=-1,C;
while ('0'<=c&&c<='9') x=x*10+c-'0',C;
if (c=='.') while ('0'<=C&&c<='9') x+=(c-'0')/t,t*=10; x*=p;
}

inline int dcmp(double a,double b){
if (fabs(a-b)<1e-5) return 0;
if (a<b) return -1; return 1;
}

const int N=100005;

int T[N<<2],F[N<<2]; double A[N<<2],B[N<<2];

inline void Flag(int x,int l,int r,double a,double b){
if (!F[x]) { F[x]=1,A[x]=a,B[x]=b; return; }
int mid=(l+r)>>1,len=mid-l;
if (dcmp(A[x],a)==0 || l==r) { B[x]=min(B[x],b); return; }
if (a>A[x] && b>B[x])
A[x]=a,B[x]=b;
else if (a>A[x] && b<=B[x]){
if (A[x]*len+B[x]>a*len+b)
Flag(x<<1|1,mid+1,r,a,b+a*(len+1));
else
swap(A[x],a),swap(B[x],b),Flag(x<<1,l,mid,a,b);
}else if (a<A[x] && b>=B[x]){
if (A[x]*len+B[x]>a*len+b)
Flag(x<<1,l,mid,a,b);
else
swap(A[x],a),swap(B[x],b),Flag(x<<1|1,mid+1,r,a,b+a*(len+1));
}
}

double ans;
inline void Query(int x,int l,int r,int t){
if (F[x]) ans=max(ans,A[x]*(t-l)+B[x]);
if (l==r) return; int mid=(l+r)>>1;
if (t<=mid) Query(x<<1,l,mid,t);
else Query(x<<1|1,mid+1,r,t);
}

int n=50000;

int main(){
int Q,x; double a,b; char order;
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
read(Q);
while (Q--){
read(order);
if (order=='Q'){
ans=0; read(x);
Query(1,1,n,x);
printf("%lld\n",(long long)(ans/100+1e-8));
}else{
read(b); read(a);
Flag(1,1,n,a,b);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: