이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <string>
#include <utility>
#include <algorithm>
#include <stdio.h>
#include "holiday.h"
#define mp make_pair
#define ff first
#define ss second
#define ll long long
using namespace std;
const int max_N = 1 << 17;
int N, bas, g;
int d[max_N];
ll sonuc = 0;
pair<ll, int> st[max_N << 1];
int id[max_N], sira[max_N];
void ekle (int k) {
st[k + max_N] = mp(d[sira[k]], 1);
k += max_N;
while(k > 1){
k >>= 1;
st[k] = mp(st[k+k].ff + st[k+k+1].ff, st[k+k].ss + st[k+k+1].ss);
}
}
void sil (int k) {
st[k + max_N] = mp(0, 0);
k += max_N;
while (k > 1) {
k >>= 1;
st[k] = mp(st[k+k].ff + st[k+k+1].ff, st[k+k].ss + st[k+k+1].ss);
}
}
ll get (int k) {
int x = 1;
ll sonuc = 0;
// printf("N: %d\n", N);
while (x < max_N) {
// printf("x: %d\n", x);
if (st[x+x+1].ss >= k)
x = x+x+1;
else {
k -= st[x+x+1].ss;
sonuc += st[x+x+1].ff;
x = x+x;
}
}
sonuc += (k > 0) * st[x].ff;
return sonuc;
}
int bsol, bsag;
void fix (int sol, int sag) {
while (bsag < sag) ekle (id[++bsag]);
while (bsol > sol) ekle (id[--bsol]);
while (bsag > sag) sil (id[bsag--]);
while (bsol < sol) sil (id[bsol++]);
}
void coz (int sol, int sag, int oSol, int oSag) {
//printf("Sol: %d, sag: %d, oSol: %d, oSag: %d\n", sol, sag, oSol, oSag);
if (sol > sag) return;
int o = (sol + sag) >> 1;
ll eb = 0;
ll opt = -1;
for (int i = oSol; i <= o && i <= oSag; i++) {
fix(i, o);
ll s = get(g - (o - i) - (o - bas));
// printf("i: %d, o: %d, s: %d\n", i, o, s);
if (opt == -1 || s >= eb) {
sonuc = max(sonuc, s);
eb = s;
opt = i;
}
}
coz (sol, o-1, oSol, opt);
coz (o+1, sag, opt, oSag);
}
bool cmp(int x, int y) {return d[x] < d[y];}
void cozBas() {
for (int i = 1; i <= N; i++)
sira[i] = i;
sort (sira +1, sira + N +1, cmp);
for (int i = 1; i <= N; i++)
id[sira[i]] = i;
bsol = 1;
bsag = 0;
memset(st, 0, sizeof st);
for (int i = bas; i <= N; i++) {
ekle(id[i]);
sonuc = max(sonuc, get(g- (i - bas)) );
}
memset(st, 0, sizeof st);
coz(bas, N, 1, bas);
}
long long int findMaxAttraction(int n, int start, int D, int attraction[]) {
N = n;
bas = start + 1;
g = D;
for (int i = 0; i < n; i++)
d[i+1] = attraction[i];
cozBas();
reverse(d +1, d + n +1);
bas = n - bas +1;
cozBas();
return sonuc;
}
컴파일 시 표준 에러 (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... |