Submission #1299311

#TimeUsernameProblemLanguageResultExecution timeMemory
1299311luvnaHacker (BOI15_hac)C++20
100 / 100
226 ms135552 KiB
#include<bits/stdc++.h>

#define MASK(i) (1 << (i))
#define pub push_back
#define all(v) v.begin(), v.end()
#define compact(v) v.erase(unique(all(v)), end(v))
#define pii pair<int,int>
#define fi first
#define se second
#define endl "\n"
#define sz(v) (int)(v).size()
#define dbg(x) "[" #x " = " << (x) << "]"
#define vi vector<int>

using namespace std;
bool START_ALLOC;

template<class T> bool minimize(T& a, T b){if(a > b) return a = b, true;return false;}
template<class T> bool maximize(T& a, T b){if(a < b) return a = b, true;return false;}

typedef long long ll;
typedef long double ld;

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r){return uniform_int_distribution<ll>(l, r)(rng);}

const int MAX = 1e6 + 15;

int n, k;
int a[MAX];
ll pref[MAX];

ll calc(int l, int r){
    if(r > n) r -= n;
    if(l < 1) l += n;
    if(l <= r) return pref[r] - pref[l-1];
    return pref[n] - (pref[l-1] - pref[r]);
}

ll f(int i){
    ll fh = calc(i, i + k - 1);
    ll sh = calc(i - k + 1, i);
    return min(fh, sh);
}

ll spt[MAX][21];

ll query(int l, int r){
    int k = log2(r - l + 1);
    return min(spt[l][k], spt[r - (1 << k) + 1][k]);
}

void solve(){
    cin >> n;

    for(int i = 1; i <= n; i++){
        cin >> a[i];
        pref[i] = pref[i-1] + a[i];
    }

    for(int i = n+1; i <= 2*n; i++){
        a[i] = a[i-n];
        pref[i] = pref[i-1] + a[i];
    }

    int k = (n + 1) / 2;
    for(int i = k; i <= 2*n; i++){
        spt[i][0] = pref[i] - pref[i - k];
    }

    for(int j = 1; j < 21; j++){
        for(int i = k; i + (1 << j) - 1 <= 2*n; i++){
            spt[i][j] = min(spt[i][j-1], spt[i + (1 << (j-1))][j-1]);
        }
    }

    ll answer = 0;
    for(int i = k; i <= 2*n; i++){
        maximize(answer, query(i - k + 1, i));
    }

    cout << answer << endl;
}

bool END_ALLOC;
signed main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(0); cout.tie(0);

    #define task "task"

    cerr << "[Static Memory : " << fixed << setprecision(2) << (((&END_ALLOC) - (&START_ALLOC)) / (1024.0 * 1024.0)) << "mb]\n";
    if(fopen(task".INP", "r")){
        freopen(task".INP", "r", stdin);
        freopen(task".OUT", "w", stdout);
    }

    int t; t = 1; //cin >> t;
    while(t--) solve();
}

Compilation message (stderr)

hac.cpp: In function 'int main()':
hac.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
hac.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |         freopen(task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...