Submission #1064509

#TimeUsernameProblemLanguageResultExecution timeMemory
1064509YassirSalamaHoliday (IOI14_holiday)C++17
24 / 100
1137 ms13264 KiB
#include"holiday.h" #include<bits/stdc++.h> using namespace std; #define ll long long #define all(v) v.begin(),v.end() #define pb push_back #define F first #define S second template<typename T> void dbg(const T& t){ cout<<t<<endl; } template<typename T,typename... Args> void dbg(const T& t,const Args&... args){ cout<<t<<" , "; dbg(args...); } #define dbg(...) cout<<"("<<#__VA_ARGS__<<") : ";dbg(__VA_ARGS__); int n,d; const int maxn=3001; ll tree[4*maxn][2]; vector<pair<int,int>> v; map<int,int> mp;//key = position in initial array, val = position in sorted array void update(int node,int l,int r,int ql,int x){ if(l==r){ if(!x){ tree[node][0]=0; tree[node][1]=0; }else{ tree[node][0]=1; tree[node][1]=v[l].F; } return; } int mid=(l+r)/2; if(ql<=mid) update(node<<1,l,mid,ql,x); else{ update(node<<1|1,mid+1,r,ql,x); } tree[node][0]=tree[node<<1][0]+tree[node<<1|1][0]; tree[node][1]=tree[node<<1][1]+tree[node<<1|1][1]; } ll query(int node,int l,int r,int k){ if(l==r) { return (k?tree[node][1]:0); } int mid=(l+r)/2; ll ans=0; if(tree[node<<1][0]<=k){ k-=tree[node<<1][0]; ans+=tree[node<<1][1]; return ans+query(node<<1|1,mid+1,r,k); }else{ return query(node<<1,l,mid,k); } } ll findMaxAttraction(int _n, int start, int _d, int arr[]) { auto calc = [&](int a,int b){ int cost=0; if(a<=start&&start<=b){ int x=b-a+start-a; int y=b-start+b-a; cost=min(x,y); } if(start<=a&&a<=b){ cost=b-start; } if(a<=b&&b<=start){ cost=start-a; } return cost; }; ll ans=0; n=_n; d=_d; for(int i=0;i<n;i++){ v.pb({arr[i],i}); } sort(all(v),greater<pair<int,int>>()); for(int i=0;i<n;i++){ mp[v[i].S]=i; } for(int i=0;i<n;i++){ for(int j=i;j<n;j++){ int cost=calc(i,j); int k=d-cost; update(1,0,n-1,mp[j],1); if(k<0) continue; ans=max(ans,query(1,0,n-1,k)); } for(int j=i;j<n;j++){ update(1,0,n-1,mp[j],0); } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...