제출 #1299303

#제출 시각아이디문제언어결과실행 시간메모리
1299303daveleHacker (BOI15_hac)C++20
100 / 100
148 ms94364 KiB
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define vi vector <int>
#define pq priority_queue
#define MASK(i) (1ll<<(i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define x0 ___x0
#define y0 ___y0
#define div   ___div
#define next   ___next
#define prev   ___prev
#define left   ___left
#define right   ___right
#define pos pisosi
#define pb push_back
#define pf push_front
using namespace std;

//const int mod = ;
//void add (int &a, const int&b){
//    a+=b;
//    if (a>=mod) a-=mod;
//}
//
//void sub (int&a, const int&b){
//    a-=b;
//    if (a<0) a+=mod;
//}
//
//void mul (int&a, const int&b){
//    a*=b;
//    a%=mod;
//}

template<class X, class Y>
    bool minimize(X &x, const Y&y){
        if (x<=y) return false;
        else{
            x = y;
            return true;
        }
    }
template<class X, class Y>
    bool maximize (X &x, const Y&y){
        if (x>=y) return false;
        else{
            x = y;
            return true;
        }
    }

/////////////////////////////////////////////////////////////////////////////////

//// dang nhap ham
//#ifndef davele
//
//#endif // davele
//
//// chay thu ham main:
//
//#ifdef davele
//
//#endif // davele

////////////////////////////////////////////////////////////////////////////
//const int lim = , limit = , inf = ;
const string name = "chonso";
const int lim = 5e5, limit = lim+5;

int n, k;
int rmq[limit][21];
int sum[limit], A[limit], sr[limit];

int next (int id, int step){
    return (id+step)%n;
}

int prev (int id, int step){
    return (id-step+n)%n;
}

int getmax (int l, int r){
    int tm = 31-__builtin_clz (r-l+1);
    return max (rmq[l][tm], rmq[r-MASK(tm)+1][tm]);
}

int get (int st, int en){
    int furthest = prev (en, k-1);
    if (furthest<=en){
        if (st<=furthest) return getmax (st,furthest);
        else return max(getmax(st, n-1), getmax(0, furthest));
    }
    else{
        if (st<=furthest) return getmax (st, furthest);
    }
}

namespace sub3{
    void process(){
        sum[0] = A[0];
        for (int i=1; i<n; i++) sum[i] = sum[i-1] + A[i];
        //
        k = n/2;
        for (int i=0; i<n; i++){
            // sr[i] = i -> next (i, k-1)
            if (next(i, k-1)>=i){
                sr[i] = sum[next(i, k-1)] - (i==0 ? 0 : sum[i-1]);
            }
            else{
                sr[i] = sum[n-1] - sum[i-1] + sum[next(i, k-1)];
            }
        }
        //
        for (int i=0; i<n; i++) rmq[i][0] = sr[i];
        //
        for (int i=1; i<=20; i++) for (int j=0; j+MASK(i)-1<n; j++){
            rmq[j][i] = max (rmq[j][i-1], rmq[j+MASK(i-1)][i-1]);
        }
        //
        int ret = 0;
        for (int i = 0; i<n; i++){
            int st = next(i, 1);
            int en = prev (i, 1);
            // lay trong doan [st; en]
            int comp = get (st, en);
            maximize (ret, sum[n-1]-comp);
        }
        cout<<ret;
    }
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //
    if (fopen((name+".inp").c_str(), "r")){
        freopen ((name+".inp").c_str(), "r", stdin);
        freopen ((name+".out").c_str(), "w", stdout);
    }
    //
    cin>>n;
    for (int i=0; i<n; i++) cin>>A[i];
    //
    sub3::process();
}

컴파일 시 표준 에러 (stderr) 메시지

hac.cpp: In function 'long long int get(long long int, long long int)':
hac.cpp:99:1: warning: control reaches end of non-void function [-Wreturn-type]
   99 | }
      | ^
hac.cpp: In function 'int main()':
hac.cpp:141:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  141 |         freopen ((name+".inp").c_str(), "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hac.cpp:142:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  142 |         freopen ((name+".out").c_str(), "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...