이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"holiday.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 100064;
ll mxl[N*2], mxl2[N*2], mxr[N*2], mxr2[N*2];
ll mxc[N];
int bin(int len, ll x)
{
int l=1, r=len;
while (l < r) {
int mid = (l+r)/2;
if (mxc[mid] - mxc[mid-1] >= x)
l = mid+1;
else
r = mid;
}
return l;
}
__attribute__((optimize("O3,unroll-loops"),target("avx2")))
void insert(int len, ll x)
{
typedef ll ymm __attribute__((vector_size(32),aligned(8)));
int i = bin(len, x);
int r = len;
while ((r-i)%4) {
mxc[r] = mxc[r-1] + x;
--r;
}
for (; r > i; r -= 4)
*(ymm *)(mxc+r-3) = *(ymm *)(mxc+r-4) + x;
mxc[i] = mxc[i-1] + x;
}
template<ll a[2*N]>
__attribute__((optimize("O3,unroll-loops"),target("avx2")))
void up(int len, int off)
{
#define MAX(x, y) ((x)>(y)?(x):(y))
Loop (i,0,len)
a[i+off] = MAX(a[i+off], mxc[i]);
#undef MAX
}
long long int findMaxAttraction(int n, int s, int d, int attr[])
{
int k = min(s, n-1-s);
Loop (i,s+1,n) {
insert(i - s, attr[i]);
up<mxr>(i - s + 1, i - s);
if (i-s <= k)
up<mxr2>(i - s + 1, 2*(i - s));
}
LoopR (i,0,s) {
insert(s - i, attr[i]);
up<mxl>(s - i + 1, s - i);
if (s-i <= k)
up<mxl2>(s - i + 1, 2*(s - i));
}
Loop (i,0,2*N-1) {
mxl [i+1] = max(mxl [i+1], mxl [i]);
mxl2[i+1] = max(mxl2[i+1], mxl2[i]);
mxr [i+1] = max(mxr [i+1], mxr [i]);
mxr2[i+1] = max(mxr2[i+1], mxr2[i]);
}
ll ans = 0;
Loop (i,0,d+1) {
if (i < 2*N && (d-i) < 2*N) {
ans = max(ans, mxl[i] + mxr2[d-i]);
ans = max(ans, mxl2[i] + mxr[d-i]);
}
}
Loop (i,0,d) {
if (i < 2*N && (d-1-i) < 2*N) {
ans = max(ans, mxl[i] + mxr2[d-1-i] + attr[s]);
ans = max(ans, mxl2[i] + mxr[d-1-i] + attr[s]);
}
}
return ans;
}
# | 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... |