Submission #856373

#TimeUsernameProblemLanguageResultExecution timeMemory
856373onepunchac168Holiday (IOI14_holiday)C++14
100 / 100
428 ms10228 KiB
#include"holiday.h" #include <bits/stdc++.h> using namespace std; #define task "" #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } #define ldb long double #define pb push_back #define eb emplace_back #define fi first #define se second #define all(x) begin(x),end(x) #define uniquev(v) v.resize(unique(all(v))-v.begin()) #define rep(i,a,b) for (int i=a;i<=b;i++) #define cntbit(v) __builtin_popcountll(v) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) ((1LL*a*b)/__gcd(a,b)) #define mask(x) (1LL<<(x)) #define readbit(x,i) ((x>>i)&1) #define Yes cout << "Yes" #define YES cout << "YES" #define No cout << "No" #define NO cout << "NO" typedef long long ll; typedef pair <ll,ll> ii; const char nl='\n'; /* void onepunchac168(); signed main() { ios_base::sync_with_stdio(false); cin.tie(0); if (fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } onepunchac168(); }*/ ll n,s,d; const int N=1e5+5; ll a[N]; ll b[N]; int l1,r1; ii T[4*N]; vector <ll> vt; void update(int node,int l,int r,int u,ii val) { if (l>u||r<u) { return; } if (l==r) { T[node].fi+=val.fi; T[node].se+=val.se; return; } update(node*2,l,(l+r)/2,u,val); update(node*2+1,(l+r)/2+1,r,u,val); T[node].fi=T[node*2].fi+T[node*2+1].fi; T[node].se=T[node*2].se+T[node*2+1].se; } void updatea(int u,int v) { while (u<l1) { update(1,1,vt.size(),b[l1-1],{1,a[l1-1]}); l1--; } while (u>l1) { update(1,1,vt.size(),b[l1],{-1,-a[l1]}); l1++; } while (v<r1) { update(1,1,vt.size(),b[r1],{-1,-a[r1]}); r1--; } while (v>r1) { update(1,1,vt.size(),b[r1+1],{1,a[r1+1]}); r1++; } } ll query(int node,int l,int r,int sl) { if (l==r) { ll cost=0; cost=T[node].se; if (T[node].fi>sl) { ll pp=T[node].fi-sl; cost-=vt[l-1]*pp; } return cost; } if (T[node*2+1].fi>=sl) { return query(node*2+1,(l+r)/2+1,r,sl); } return T[node*2+1].se+query(node*2,l,(l+r)/2,sl-T[node*2+1].fi); } ll res=0; void solve(int left,int right,int pos1,int pos2) { if (left>right) { return; } int mid=(left+right)/2; int id=-1; ll ans=-1; for (int i=pos2;i>=pos1;i--) { updatea(mid,i); ll dd=i-mid+min(i-s,s-mid); if (dd>d) { continue; } ll cost=query(1,1,vt.size(),d-dd); if (cost>ans) { ans=cost; id=i; } } res=max(res,ans); if (id==-1) { solve(mid+1,right,pos1,pos2); return; } solve(left,mid-1,pos1,id); solve(mid+1,right,id,pos2); } long long int findMaxAttraction(int na, int start, int da, int attraction[]) { n=na; s=start+1; d=da; for (int i=0;i<n;i++) { a[i+1]=attraction[i]; } for (int i=1;i<=n;i++) { vt.pb(a[i]); } sort (vt.begin(),vt.end()); uniquev(vt); l1=1; r1=n; for (int i=1;i<=n;i++) { b[i]=lower_bound(vt.begin(),vt.end(),a[i])-vt.begin()+1; update(1,1,vt.size(),b[i],{1,a[i]}); } solve(1,s,s,n); return res; } /* void onepunchac168() { cin>>n>>s>>d; s++; for (int i=1;i<=n;i++) { cin>>a[i]; } if (s==1) { sub1(); } else sub2(); } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...