이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Power Of Ninja Go
#include <bits/stdc++.h>
#ifdef atom
#include "grader.cpp"
#else
#include "holiday.h"
#endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii;
#define X first
#define Y second
#define vi vector<int>
#define vii vector< ii >
#define pb push_back
int *arr, N, st, D;
struct node
{
ll v, v2;
node *left, *right;
node(ll a, ll a2, node *b, node *c)
{
v = a; v2 = a2;
left = b; right = c;
}
node* update(int L, int R, int x, int dx)
{
//printf("%d %d %d\n", L, R, x);
if(L> x || R< x) return this;
if(L == x && x == R)
{
return new node(this->v+dx, this->v2+1, NULL, NULL);
}
int M = (L+R)/2;
return new node(this->v+dx, this->v2+1, this->left->update(L, M, x, dx), this->right->update(M+1, R, x, dx));
}
};
node *zero;
const int maxn = 1e5+5;
node *val[maxn];
ll pong(node *va, node *vb, int k)
{
//printf("ei (%lld-%lld) with (%lld-%lld)\n", a->v, b->v, (va->v), (vb->v));
if(va->v2 - vb->v2 <= k) return va->v - vb->v;
int x = va->right->v2 - vb->right->v2;
//printf("yoyo %d\n", x);
if(k<= x) return pong(va->right, vb->right, k);
return (va->right->v - vb->right->v) + pong(va->left, vb->left, k-x);
}
ll sumK(int k, int a, int b)
{
return pong(val[b], a?val[a-1]:zero, k);
}
ll solve(int L = 0, int R = st, int i = st, int j = N-1)
{
if(L> R) return 0;
int M = (L+R)/2;
int opt = i;
ll res = -4e18;
for(int p = i; p<= j; p++)
{
int a = st-M, b = p-st;
int del = min(a, b)*2+max(a, b);
if(del>= D) break;
ll here = sumK(D-del, M, p);
//printf("sumK(%d %d %d) = %lld\n", D-del, M, p, here);
if(here> res)
{
res = here;
opt = p;
}
}
return max(max(solve(L, M-1, i, opt), solve(M+1, R, opt, j)), res);
}
int rev[maxn];
long long findMaxAttraction(int n, int start, int d, int attraction[])
{
arr = attraction; N = n; st = start; D = d;
zero = new node(0, 0, NULL, NULL);
zero->left = zero->right = zero;
vii foo;
for(int i = 0; i< n; i++) foo.pb(ii(arr[i], i));
sort(foo.begin(), foo.end());
for(int i = 0; i< n; i++) rev[foo[i].Y] = i;
for(int i = 0; i< n; i++)
{
//printf("(%d)\n", rev[i]);
val[i] = (i?val[i-1]:zero)->update(0, n-1, rev[i], arr[i]);
}
//printf("kuy %lld\n", val[n-1]->v);
return solve();
}
컴파일 시 표준 에러 (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... |