이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// ~ Be Name Khoda ~ //
#include"holiday.h"
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops,Ofast")
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const int maxn = 1e6 + 10;
const int maxn5 = 1e6 + 10;
const int maxnt = 1.2e6 + 10;
const int maxn3 = 1e3 + 10;
const int mod = 1e9 + 7;
const int lg = 19;
const ll inf = 1e18;
vector <int> ch;
ll sum = 0, ans = 0;
int lim = 0, pt[maxn5];
int dis, st, val[maxn5];
vector <pair<int, int>> num;
struct fen{
ll fen[maxn5];
void add(int id, ll x){
////cout << "ha adding " << id << endl;
for(; id < maxn5; id += id & -id)
fen[id] += x;
}
ll get(int id){
////cout << "get " << id << endl;
ll ret = 0;
for(; id; id -= id & -id)
ret += fen[id];
return ret;
}
int find(int k){
int ret = 0;
for(int i = lg - 1; i >= 0; i--)
if(ret + (1 << i) < maxn5 && fen[ret + (1 << i)] < k){
ret += (1 << i);
k -= fen[ret];
}
return min(maxn5 - 1, ret + 1);
}
} fen1, fen2;
void add(int id){
//cout << "adding " << id << endl;
ch.pb(id);
fen1.add(pt[id], 1);
fen2.add(pt[id], val[id]);
}
void undo(int x){
while(ch.size() > x){
int id = ch.back();
ch.pop_back();
//cout << "poping " << id << endl;
fen1.add(pt[id], -1);
fen2.add(pt[id], -val[id]);
}
}
void solve(int l, int r, int optl, int optr){
//cout << "welcome " << l << ' ' << r << ' ' << optl << ' ' << optr << ' ' << ch.size() << endl;
int mid = (l + r) >> 1;
int opt = optl;
int keep = ch.size();
ll best = -1;
for(int i = mid; i < optl && i < r; i++)
add(i);
for(int i = max(mid, optl); i < optr; i++){
add(i);
int rem = dis - (min(abs(st - mid), abs(st - i)) + i - mid);
if(rem < 0)
break;
int pt;
ll sum;
if(rem == 0)
sum = 0;
else{
pt = fen1.find(rem);
sum = fen2.get(pt);
}
//cout << mid << ' ' << i << ' ' << rem << ' ' << optl << ' ' << optr << ' ' << pt << ' ' << sum << endl;
if(sum >= best){
best = sum;
opt = i;
}
}
//cout << "all here " << l << ' ' << r << endl;
ans = max(ans, best);
undo(keep);
if(r - l > 1){
for(int i = mid; i < min(r, optl); i++)
add(i);
solve(l, mid, optl, opt + 1);
undo(keep);
for(int i = max(optl, r); i < opt; i++)
add(i);
solve(mid + 1, r, opt, optr);
}
////cout << "done with " << l << ' ' << r << endl;
}
long long int findMaxAttraction(int n, int start, int d, int attraction[]){
if(d == 0)
return 0;
dis = d;
st = start;
//ll all = 0;
for(int i = 0; i < n; i++){
val[i] = attraction[i];
//all += val[i];
num.pb({-val[i], i});
}
////cout << all << endl;
sort(all(num));
for(int i = 0; i < n; i++)
pt[i] = lower_bound(all(num), mp(-val[i], i)) - num.begin() + 1;
solve(max(0, start - d), min(n, start + d + 1), max(0, start - d), min(n, start + d + 1));
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
holiday.cpp: In function 'void undo(int)':
holiday.cpp:72:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
72 | while(ch.size() > x){
| ~~~~~~~~~~^~~
# | 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... |