이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"holiday.h"
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#define vec std::vector
#define myc std::pair < int, int >
#define x first
#define y second
#define ll long long
#define MAXN 100000
#define MAXP 265000
struct node {
int cnt;
ll sum;
} aint[MAXP];
ll val;
int poz, cnt;
void update(int p, int st, int dr) {
if (st == dr) {
aint[p].cnt = val > 0;
aint[p].sum = val;
} else {
int m = (st + dr) / 2;
if (poz <= m) update(2 * p, st, m);
else update(2 * p + 1, m + 1, dr);
aint[p].cnt = aint[2 * p].cnt + aint[2 * p + 1].cnt;
aint[p].sum = aint[2 * p].sum + aint[2 * p + 1].sum;
}
}
void query(int p, int st, int dr) {
if (poz != dr + 1)
return ;
if (aint[p].cnt <= cnt) {
cnt -= aint[p].cnt;
val += aint[p].sum;
poz = st;
return ;
}
if (st == dr)
return ;
int m = (st + dr) / 2;
query(2 * p + 1, m + 1, dr);
query(2 * p, st, m);
}
void divide(int cost, vec < myc > &V, vec < ll > &dp, int left, int right, int st, int dr, int &unde) {
if (left > right)
return ;
while (unde < st) {
unde++;
poz = V[unde].y;
val = V[unde].x;
update(1, 0, V.size() - 1);
}
while (unde > st) {
poz = V[unde].y;
val = 0;
update(1, 0, V.size() - 1);
unde--;
}
int sol = st, m = (left + right) / 2;
poz = V.size();
val = 0;
cnt = m - cost * st - cost;
query(1, 0, V.size() - 1);
dp[m] = val;
for (int i = st + 1; i <= dr; i++) {
unde++;
poz = V[unde].y;
val = V[unde].x;
update(1, 0, V.size() - 1);
poz = V.size();
val = 0;
cnt = m - cost * i - cost;
query(1, 0, V.size() - 1);
if (val > dp[m]) {
sol = i;
dp[m] = val;
}
}
divide(cost, V, dp, left, m - 1, st, sol, unde);
divide(cost, V, dp, m + 1, right, sol, dr, unde);
}
inline void solve(int cost, vec < ll > &dp, vec < int > &v) {
if (v.empty())
return ;
memset(aint, 0, sizeof aint);
vec < myc > W(v.size()), V(v.size());
for (int i = 0; i < (int)v.size(); i++)
W[i] = {v[i], i};
std::sort(W.begin(), W.end());
for (int i = 0; i < (int)V.size(); i++)
V[W[i].y] = {W[i].x, i};
int unde = -1;
divide(cost, V, dp, 0, dp.size() - 1, 0, v.size() - 1, unde);
}
long long int findMaxAttraction(int n, int start, int d, int attraction[]) {
vec < ll > left1(d + 1, 0), left2(d + 1, 0), right1(d + 1, 0), right2(d + 1, 0);
vec < int > st, dr;
for (int i = start - 1; i >= 0; i--)
st.push_back(attraction[i]);
for (int i = start + 1; i < n; i++)
dr.push_back(attraction[i]);
solve(1, left1, st);
solve(2, left2, st);
solve(1, right1, dr);
solve(2, right2, dr);
ll ans = 0;
for (int i = 0; i <= d; i++)
ans = std::max(ans, std::max(left2[i] + right1[d - i], right2[i] + left1[d - i]));
for (int i = 0; i < d; i++)
ans = std::max(ans, attraction[start] + std::max(left2[i] + right1[d - i - 1], right2[i] + left1[d - i - 1]));
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
grader.cpp: In function 'int main()':
grader.cpp:7:12: warning: variable 'n_s' set but not used [-Wunused-but-set-variable]
int i, n_s;
^~~
# | 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... |