1 solutions
-
0
/* * __----~~~~~~~~~~~------___ * . . ~~//====...... __--~ ~~ * -. \_|// |||\\ ~~~~~~::::... /~ * ___-==_ _-~o~ \/ ||| \\ _/~~- * __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ * _-~~ .=~ | \\-_ '-~7 /- / || \ / * .~ .~ | \\ -_ / /- / || \ / * / ____ / | \\ ~-_/ /|- _/ .|| \ / * |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ * ' ~-| /| |-~\~~ __--~~ * |-~~-_/ | | ~\_ _-~ /\ * / \ \__ \/~ \__ * _--~ _/ | .-~~____--~-/ ~~==. * ((->/~ '.|||' -_| ~~-/ , . _|| * -_ ~\ ~~---l__i__i__i--~~_/ * _-~-__ ~) \--______________--~~ * //.-~~~-~_--~- |-------~~~~~~~~ * //.-~~~--\ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * 神兽保佑 永无BUG */ /* * @Description: I want to be the weakest vegetable in the world! * @Author: I.Z. */ #include<bits/stdc++.h> using namespace std; #define MOD 998244353 #define int long long #define pii pair<int,int> #define all(v) v.begin(),v.end() #define pb push_back #define REP(i,b,e) for(int i=(b);i<(int)(e);++i) #define over(x) {cout<<(x)<<endl;return;} #define lowbit(x) ((x)&(-(x))) #define cntbit(x) __builtin_popcount(x) #define deal(v) sort(all(v));v.erase(unique(v.begin(),v.end()),v.end()) #define lbound(v,x) lower_bound(all(v),x)-v.begin() mt19937 sd(random_device{}()); int qpow(int a,int b,int m=MOD,int res=1){ a%=m; while(b>0)res=(b&1)?(res*a%m):(res),a=a*a%m,b>>=1; return res; } int exgcd(int x,int y,int &a,int &b){ if(y==0){ a=1;b=0; return x; } int d=exgcd(y,x%y,a,b); int z=b; b=a-b*(x/y); a=z; return d; } int _x_,_y_; inline int inverse(int x,int y=MOD){ exgcd(x,y,_x_,_y_); return (_x_+y)%y; } int fac[2000005],inv[2000005]; void init(int n){ fac[0]=inv[0]=1; REP(i,1,n+1)fac[i]=fac[i-1]*i%MOD; inv[n]=qpow(fac[n],MOD-2); for(int i=n-1;i>=1;--i)inv[i]=inv[i+1]*(i+1)%MOD; } int binom(int x,int y){ return x<y||y<0? 0:fac[x]*inv[y]%MOD*inv[x-y]%MOD; } #define ld long double struct linear{ ld k,b; inline ld calc(ld x){return k*x+b;} }seg[1200005]; void build(int l,int r,int p){ seg[p]={-1e18,-1e18}; if(l==r)return; int m=(l+r)>>1; build(l,m,p*2+1);build(m+1,r,p*2+2); } vector<ld>v; void pushdown(int l,int r,int p,linear a){ if(seg[p].k==-1e18)return seg[p]=a,void(); if(seg[p].calc(v[l])<a.calc(v[l]))swap(seg[p],a); if(l==r)return; if(seg[p].calc(v[r])>=a.calc(v[r]))return; int m=(l+r)>>1; if(seg[p].calc(v[m])>=a.calc(v[m]))pushdown(m+1,r,p*2+2,a); else swap(a,seg[p]),pushdown(l,m,p*2+1,a); } void update(int l,int r,int s,int t,int p,linear a){ if(l<=s&&t<=r)return pushdown(s,t,p,a),void(); int m=(s+t)>>1; if(m>=l)update(l,r,s,m,p*2+1,a); if(m<r)update(l,r,m+1,t,p*2+2,a); } void ask(int pos,int l,int r,int p,ld &res){ if(seg[p].k!=-1e18)res=max(res,seg[p].calc(v[pos])); if(l==r)return; int m=(l+r)>>1; if(m>=pos)ask(pos,l,m,p*2+1,res); else ask(pos,m+1,r,p*2+2,res); } struct node{ int x;ld p; }d[30005]; ld c,s1,s2,t; int n; void update(node a){ //s1*tar*a.x<=s2 int L=0,R=v.size()-1,res=-1; while(L<=R){ int mid=(L+R)>>1; if(v[mid]*a.x*s1<=s2)res=mid,L=mid+1; else R=mid-1; } if(res>=0)update(0,res,0,v.size()-1,0,{(1-t)*a.x,a.p-s2});//(1-t)*tar*a.x-s2+a.p if(res+1<v.size())update(res+1,v.size()-1,0,v.size()-1,0,{(1-t-s1)*a.x,a.p}); //(1-t-s1)*tar*a.x+a.p } ld a[30005],f[30005]; inline ld calc(ld x){return x*(1-t)-max(s2,s1*x);} inline ld calc2(ld x){return x*(1+t)+max(s2,s1*x);} int nxt[30005]; void Main() { cin>>c>>s1>>s2>>t>>n; REP(i,0,n)cin>>a[i]; f[0]=c; REP(i,0,n)a[i]*=100,v.pb(a[i]); deal(v); build(0,v.size()-1,0); update({0,c}); REP(i,0,n){ if(i<n-1&&a[i]<=a[i+1]){ f[i+1]=f[i]; //全卖能卖多少 int l=0,r=1e9,res=0;ld rres=0; while(l<=r){ int mid=(l+r)>>1; ld c=calc2(a[i]*mid); if(c<=f[i])res=mid,rres=c,l=mid+1; else r=mid-1; } d[i]={res,f[i]-rres}; update(d[i]); }else{ f[i+1]=f[i]; ask(lbound(v,a[i]),0,v.size()-1,0,f[i+1]); } } cout<<fixed<<setprecision(3); over(f[n]) } void TC() { int tc=1; while(tc--){ Main(); cout.flush(); } } signed main() { freopen("stock.in","r",stdin); freopen("stock.out","w",stdout); return cin.tie(0),cout.tie(0),ios::sync_with_stdio(0),TC(),0; } /* 1. CLEAR the arrays (ESPECIALLY multitests) 2. DELETE useless output */
- 1
Information
- ID
- 3085
- Time
- 2000ms
- Memory
- 128MiB
- Difficulty
- 10
- Tags
- (None)
- # Submissions
- 1
- Accepted
- 1
- Uploaded By