結果

問題 No.919 You Are A Project Manager
ユーザー aajisakaaajisaka
提出日時 2019-11-05 21:32:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 3,000 ms
コード長 6,518 bytes
コンパイル時間 2,179 ms
コンパイル使用メモリ 177,520 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-10 03:50:49
合計ジャッジ時間 6,652 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 17 ms
4,384 KB
testcase_05 AC 18 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 41 ms
4,380 KB
testcase_08 AC 11 ms
4,380 KB
testcase_09 AC 9 ms
4,384 KB
testcase_10 AC 14 ms
4,384 KB
testcase_11 AC 14 ms
4,384 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 18 ms
4,384 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 7 ms
4,384 KB
testcase_16 AC 24 ms
4,380 KB
testcase_17 AC 73 ms
4,380 KB
testcase_18 AC 73 ms
4,380 KB
testcase_19 AC 74 ms
4,380 KB
testcase_20 AC 100 ms
4,388 KB
testcase_21 AC 74 ms
4,384 KB
testcase_22 AC 47 ms
4,380 KB
testcase_23 AC 45 ms
4,384 KB
testcase_24 AC 47 ms
4,380 KB
testcase_25 AC 46 ms
4,380 KB
testcase_26 AC 98 ms
4,380 KB
testcase_27 AC 86 ms
4,384 KB
testcase_28 AC 107 ms
4,380 KB
testcase_29 AC 74 ms
4,384 KB
testcase_30 AC 74 ms
4,384 KB
testcase_31 AC 72 ms
4,384 KB
testcase_32 AC 72 ms
4,384 KB
testcase_33 AC 50 ms
4,380 KB
testcase_34 AC 50 ms
4,380 KB
testcase_35 AC 109 ms
4,380 KB
testcase_36 AC 110 ms
4,384 KB
testcase_37 AC 109 ms
4,380 KB
testcase_38 AC 109 ms
4,384 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 6 ms
4,380 KB
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 3 ms
4,380 KB
testcase_43 AC 4 ms
4,380 KB
testcase_44 AC 8 ms
4,384 KB
testcase_45 AC 3 ms
4,380 KB
testcase_46 AC 7 ms
4,380 KB
testcase_47 AC 46 ms
4,380 KB
testcase_48 AC 46 ms
4,384 KB
testcase_49 AC 49 ms
4,380 KB
testcase_50 AC 45 ms
4,380 KB
testcase_51 AC 41 ms
4,384 KB
testcase_52 AC 33 ms
4,384 KB
testcase_53 AC 42 ms
4,380 KB
testcase_54 AC 7 ms
4,380 KB
testcase_55 AC 2 ms
4,384 KB
testcase_56 AC 1 ms
4,384 KB
testcase_57 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());
// Original: https://github.com/beet-aizu/library

struct FullyIndexableDictionary{
    int len,blk;
    vector<unsigned> bit;
    vector<int> sum;

    FullyIndexableDictionary(){}
    FullyIndexableDictionary(int len)
        :len(len),blk((len+31)>>5),bit(blk,0),sum(blk,0){}

    void set(int k){
      bit[k>>5]|=1u<<(k&31);
    }

    void build(){
      sum[0]=0;
      for(int i=1;i<blk;i++)
        sum[i]=sum[i-1]+__builtin_popcount(bit[i-1]);
    }

    bool operator[](int k) const{
      return bool((bit[k>>5]>>(k&31))&1);
    }

    int rank(int k){
      return sum[k>>5]+__builtin_popcount(bit[k>>5]&((1u<<(k&31))-1));
    }

    int rank(bool v,int k){
      return (v?rank(k):k-rank(k));
    }

    int select(bool v,int k){
      if(k<0||rank(v,len)<=k) return -1;
      int l=0,r=len;
      while(l+1<r){
        int m=(l+r)>>1;
        if(rank(v,m)>=k+1) r=m;
        else l=m;
      }
      return r-1;
    }

    int select(bool v,int i,int l){
      return select(v,i+rank(v,l));
    }
};

template<class T,int MAXLOG>
struct WaveletMatrix{
    int len;
    FullyIndexableDictionary mat[MAXLOG];
    int zs[MAXLOG],buff1[MAXLOG],buff2[MAXLOG];
    static const T npos=-1;

    int freq_dfs(int d,int l,int r,T val,T a,T b){
      if(l==r) return 0;
      if(d==MAXLOG) return (a<=val&&val<b)?r-l:0;
      T nv=T(1)<<(MAXLOG-d-1)|val;
      T nnv=((T(1)<<(MAXLOG-d-1))-1)|nv;
      if(nnv<a||b<=val) return 0;
      if(a<=val&&nnv<b) return r-l;
      int lc=mat[d].rank(1,l),rc=mat[d].rank(1,r);
      return freq_dfs(d+1,l-lc,r-rc,val,a,b)
             +freq_dfs(d+1,lc+zs[d],rc+zs[d],nv,a,b);
    }

    WaveletMatrix(vector<T> data){
      len=data.size();
      vector<T> ls(len),rs(len);
      for(int dep=0;dep<MAXLOG;dep++){
        mat[dep]=FullyIndexableDictionary(len+1);
        int p=0,q=0;
        for(int i=0;i<len;i++){
          bool k=(data[i]>>(MAXLOG-(dep+1)))&1;
          if(k) rs[q++]=data[i],mat[dep].set(i);
          else  ls[p++]=data[i];
        }
        zs[dep]=p;
        mat[dep].build();
        swap(ls,data);
        for(int i=0;i<q;i++) data[p+i]=rs[i];
      }
    }

    T access(int k){
      T res=0;
      for(int dep=0;dep<MAXLOG;dep++){
        bool bit=mat[dep][k];
        res=(res<<1)|bit;
        k=mat[dep].rank(bit,k)+zs[dep]*dep;
      }
      return res;
    }

    // return the number of v in [0,k)
    int rank(T v,int k){
      int l=0,r=k;
      for(int dep=0;dep<MAXLOG;dep++){
        buff1[dep]=l;buff2[dep]=r;
        bool bit=(v>>(MAXLOG-(dep+1)))&1;
        l=mat[dep].rank(bit,l)+zs[dep]*bit;
        r=mat[dep].rank(bit,r)+zs[dep]*bit;
      }
      return r-l;
    }

    // return the position of k-th v
    int select(T v,int k){
      rank(v,len);
      for(int dep=MAXLOG-1;dep>=0;dep--){
        bool bit=(v>>(MAXLOG-(dep+1)))&1;
        k=mat[dep].select(bit,k,buff1[dep]);
        if(k>=buff2[dep]||k<0) return -1;
        k-=buff1[dep];
      }
      return k;
    }

    int select(T v,int k,int l){
      return select(v,k+rank(v,l));
    }

    // return k-th largest value in [l,r)
    T quantile(int l,int r,int k){
      if(r-l<=k||k<0) return -1;
      T res=0;
      for(int dep=0;dep<MAXLOG;dep++){
        int p=mat[dep].rank(1,l);
        int q=mat[dep].rank(1,r);
        if(q-p>k){
          l=p+zs[dep];
          r=q+zs[dep];
          res|=T(1)<<(MAXLOG-(dep+1));
        }else{
          k-=(q-p);
          l-=p;
          r-=q;
        }
      }
      return res;
    }

    T rquantile(int l,int r,int k){
      return quantile(l,r,r-l-k-1);
    }

    // return number of points in [left, right) * [lower, upper)
    int rangefreq(int left,int right,T lower,T upper){
      return freq_dfs(0,left,right,0,lower,upper);
    }

    pair<int, int> ll(int l,int r,T v){
      int res=0;
      for(int dep=0;dep<MAXLOG;dep++){
        buff1[dep]=l;buff2[dep]=r;
        bool bit=(v>>(MAXLOG-(dep+1)))&1;
        if(bit) res+=r-l+mat[dep].rank(bit,l)-mat[dep].rank(bit,r);
        l=mat[dep].rank(bit,l)+zs[dep]*bit;
        r=mat[dep].rank(bit,r)+zs[dep]*bit;
      }
      return make_pair(res,r-l);
    }

    int lt(int l,int r,T v){
      auto p=ll(l,r,v);
      return p.first;
    }

    int le(int l,int r,T v){
      auto p=ll(l,r,v);
      return p.first+p.second;
    }

    T succ(int l,int r,T v){
      int k=le(l,r,v);
      return k==r-l?npos:rquantile(l,r,k);
    }

    T pred(int l,int r,T v){
      int k=lt(l,r,v);
      return k?rquantile(l,r,k-1):npos;
    }
};

class project_manager {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<ll> a(n);
      const int C = 1e+9;
      rep(i, n) {
        cin >> a[i];
        a[i] += C;
      }
      WaveletMatrix<ll, 32> wm(a);
      ll ans = 0;

      for(int k=1; k<=n; k++) {
        vector<ll> left, right;
        left.push_back(0);
        right.push_back(0);
        ll now = 0;
        for(int l=0; l+k<=n; l+=k) {
          now += wm.rquantile(l, l+k, (k-1)/2)-C;
          debug(now);
          left.push_back(max(now, left.back()));
        }
        now = 0;
        for(int r=n; r-k>=0; r-=k) {
          now += wm.rquantile(r-k, r, (k-1)/2)-C;
          right.push_back(max(now, right.back()));
        }
        int s = left.size();
        rep(i, s) {
          chmax(ans, (left[i] + right[s-1-i])*k);
        }
      }
      cout << ans << endl;
    }
};

signed main() {
  project_manager solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
0