Submission #796327

#TimeUsernameProblemLanguageResultExecution timeMemory
796327HannibalBarcaHacker (BOI15_hac)C++17
100 / 100
111 ms10748 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

template<class A, class B>
ostream& operator<<(ostream& o, const pair<A, B>& p) {
    return o << '(' << p.first << ", " << p.second << ')';
}
template<class T>
auto operator<<(ostream& o, const T& x) -> decltype(x.end(), o) {
    o << '{';
    int i = 0;
    for (const auto& e : x) {
        o << (", ") + 2 * !i++ << e;
    }
    return o << '}';
}
//#define DEBUG
#ifdef DEBUG
#define fastio()
#define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n'
#define check(x) if (!(x)) { cerr << "Check failed: " << #x << " in line " << __LINE__ << endl; exit(1); }
#else
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0);
#define debug(...)
#define check(x)
#endif
#define pii pair<int,int>
#define inf 2'000'000'000
#define mod 998'244'353
#define mod2 1'000'000'009
#define maxn 500'000
typedef long long ll;

int arr[2 * maxn + 3];

const int base = 1 << 19;
class Tree {
    int T[base << 1];
    public:
    void update(int x, int val) {
        x += base;
        T[x] = val;
        while (x > 0) {
            x >>= 1;
            T[x] = max(T[2 * x], T[2 * x + 1]);
        }
    }
    int query(int a, int b) {
        int scr = 0;
        a += base;
        b += base;
        while (a <= b) {
            scr = max({scr, T[a], T[b]});
            a = (a + 1) / 2;
            b = (b - 1) / 2;
        }
        return scr;
    }
};

Tree T;

signed main() {
    int n;
    scanf("%d", &n);
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &arr[i]);
        arr[n + i] = arr[i];
        sum += arr[i];
    }
    //gen prefix sums
    for (int i = 1; i <= 2*n; i++)
     arr[i] += arr[i - 1];
    for (int i = 2 * n; i > n/2; i--)
     arr[i] -= arr[i - n/2];
    for (int i = 1; i <= n; i++)
     arr[i] = arr[n + i];
    for (int i = 1; i <= 2*n; i++)
     T.update(i, arr[i]);
    int mn = inf;
    for (int i = 1; i <= n; i++)
     mn = min(mn, T.query(i + n/2, i + n - 1));
    printf("%d\n", sum - mn);
    return 0;
}

Compilation message (stderr)

hac.cpp: In function 'int main()':
hac.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
hac.cpp:72:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         scanf("%d", &arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...