이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//In the name of God
#include <bits/stdc++.h>
#include"holiday.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
#define lc (id << 1)
#define rc (id << 1 | 1)
ll a[maxn];
ll seg[maxn << 2], cnt[maxn << 2];
pll b[maxn];
void upd(ll id, ll s, ll e, ll i, ll x){
if(i < s || e <= i) return;
if(e - s == 1){
cnt[id] += x;
seg[id] += x * a[s];
return;
}
ll mid = (s + e) >> 1;
upd(lc, s, mid, i, x);
upd(rc, mid, e, i, x);
cnt[id] = cnt[lc] + cnt[rc];
seg[id] = seg[lc] + seg[rc];
return;
}
ll get(ll id, ll s, ll e, ll x){
if(x <= 0) return 0;
if(x >= cnt[id]) return seg[id];
ll mid = (s + e) >> 1;
return get(rc, mid, e, x) + get(lc, s, mid, x - cnt[rc]);
}
ll cal(ll s, ll l, ll r){
return r - l + min(r - s, s - l);
}
long long int findMaxAttraction(int n, int start, int d, int at[]){
for(ll i = 0; i < n; i++){
b[i] = Mp(at[i], i);
}
sort(b, b + n);
for(ll i = 0; i < n; i++){
a[i] = b[i].F;
at[b[i].S] = i;
}
ll ans = 0;
for(ll i = 0; i <= start; i++){
upd(1, 0, n, at[start - i], 1);
ans = max(ans, get(1, 0, n, d - cal(start, start - i, start)));
for(ll j = start + 1; j < n; j++){
upd(1, 0, n, at[j], 1);
ans = max(ans, get(1, 0, n, d - cal(start, start - i, j)));
}
for(ll j = start + 1; j < n; j++){
upd(1, 0, n, at[j], -1);
}
}
return ans;
}
/*int main(){
fast_io;
return 0;
}*/
# | 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... |