This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
//#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
#define getchar_unlocked getchar
inline int scan()
{
char c = getchar_unlocked();
int x = 0;
while(c<'0'||c>'9')
{
c=getchar_unlocked();
}
while(c>='0'&&c<='9')
{
x=(x<<1)+(x<<3)+c-'0';
c=getchar_unlocked();
}
return x;
}
void phongbeo();
const int inf=1e9;
const int mod2=1e9+9;
const int mod1=998244353;
struct icd
{
long double a;
int b;
};
struct ib
{
ll a;
ll b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
struct ie
{
int a,b,c,d,e;
};
ll n,m,s1,s2,s4,s3,sf,k,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,s33,dem3,dem4,l,r,mid,l2,r2;
ll i,s10,s12;
ll kk;
ll el=29;
ll a[100001];
vector<ll> v;
struct IT
{
ib t[400001];
ib mer(ib a,ib b)
{
return{a.a+b.a,a.b+b.b};
}
void upd(int node,int l,int r,int l1,ll x)
{
if(l==r)
{
t[node].b+=x;
t[node].a=v[l-1]*t[node].b;
return;
}
int mid=l+r>>1;
if(l1<=mid) upd(node<<1,l,mid,l1,x);
else upd(node<<1|1,mid+1,r,l1,x);
t[node]=mer(t[node<<1],t[node<<1|1]);
}
ll walk(int node,int l,int r,ll x)
{
if(l==r) return l;
int mid=l+r>>1;
if(t[node<<1|1].b>=x) return walk(node<<1|1,mid+1,r,x);
x-=t[node<<1|1].b;
return walk(node<<1,l,mid,x);
}
ib get(int node,int l,int r,int l1,int r1)
{
if(l>r1||r<l1) return {0,0};
if(l>=l1&&r<=r1) return t[node];
int mid=l+r>>1;
return mer(get(node<<1,l,mid,l1,r1),get(node<<1|1,mid+1,r,l1,r1));
}
} st;
void go(int x,int y)
{
while(l2<x)
{
st.upd(1,1,n,a[l2],-1);
l2++;
}
while(l2>x)
{
l2--;
st.upd(1,1,n,a[l2],1);
}
while(r2<y)
{
r2++;
st.upd(1,1,n,a[r2],1);
}
while(r2>y)
{
st.upd(1,1,n,a[r2],-1);
r2--;
}
}
void solve_left(ll l,ll r,ll x,ll y)
{
if(l>r) return;
ll mid=l+r>>1;
ll mx_z=-1;
ll pos=-1;
for(int i=x; i<=y; i++)
{
go(mid,i);
if(i!=k) s4=m-(i-mid+k-mid);
else s4=m-(k-mid);
s5=st.walk(1,1,n,s4);
ib xx=st.get(1,1,n,s5+1,n);
ib xx2=st.get(1,1,n,s5,s5);
s3=xx.a+min(xx2.a,(s4-xx.b)*v[s5-1]);
if(s3>mx_z)
mx_z=s3,pos=i;
}
s9=max(s9,mx_z);
solve_left(l,mid-1,x,pos);
solve_left(mid+1,r,pos,y);
}
void solve_right(ll l,ll r,ll x,ll y)
{
if(l>r) return;
ll mid=l+r>>1;
ll mx_z=-1;
ll pos=-1;
for(int i=x; i<=y; i++)
{
go(i,mid);
if(i!=k) s4=m-(mid-i+mid-k);
else s4=m-(mid-k);
s5=st.walk(1,1,n,s4);
ib xx=st.get(1,1,n,s5+1,n);
ib xx2=st.get(1,1,n,s5,s5);
s3=xx.a+min(xx2.a,(s4-xx.b)*v[s5-1]);
if(s3>mx_z)
mx_z=s3,pos=i;
}
s9=max(s9,mx_z);
solve_right(l,mid-1,x,pos);
solve_right(mid+1,r,pos,y);
}
long long findMaxAttraction(int ff, int g2, int g, int attraction[])
{
n=ff;
for(int i=1; i<=n; i++)
a[i]=attraction[i-1],v.pb(a[i]);
sort(v.begin(),v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for(int i=1; i<=n; i++)
a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin()+1;
l2=0;
r2=0;
m=g;
k=g2;
s7=n;
n=v.size();
l2=1;
k++;
solve_right(k,s7,1,k);
//assert(0);
solve_left(1,k,k,s7);
return s9;
}
Compilation message (stderr)
holiday.cpp: In member function 'void IT::upd(int, int, int, int, long long int)':
holiday.cpp:84:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
84 | int mid=l+r>>1;
| ~^~
holiday.cpp: In member function 'long long int IT::walk(int, int, int, long long int)':
holiday.cpp:92:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
92 | int mid=l+r>>1;
| ~^~
holiday.cpp: In member function 'ib IT::get(int, int, int, int, int)':
holiday.cpp:101:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
101 | int mid=l+r>>1;
| ~^~
holiday.cpp: In function 'void solve_left(long long int, long long int, long long int, long long int)':
holiday.cpp:131:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
131 | ll mid=l+r>>1;
| ~^~
holiday.cpp: In function 'void solve_right(long long int, long long int, long long int, long long int)':
holiday.cpp:153:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
153 | ll mid=l+r>>1;
| ~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |