結果
問題 | No.919 You Are A Project Manager |
ユーザー | 37zigen |
提出日時 | 2020-03-13 17:50:36 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 929 ms / 3,000 ms |
コード長 | 5,425 bytes |
コンパイル時間 | 2,402 ms |
コンパイル使用メモリ | 79,948 KB |
実行使用メモリ | 44,932 KB |
最終ジャッジ日時 | 2024-05-02 01:46:02 |
合計ジャッジ時間 | 28,443 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 633 ms
43,600 KB |
testcase_01 | AC | 54 ms
36,408 KB |
testcase_02 | AC | 53 ms
36,860 KB |
testcase_03 | AC | 53 ms
36,992 KB |
testcase_04 | AC | 324 ms
41,172 KB |
testcase_05 | AC | 328 ms
41,828 KB |
testcase_06 | AC | 106 ms
39,268 KB |
testcase_07 | AC | 418 ms
42,304 KB |
testcase_08 | AC | 263 ms
41,004 KB |
testcase_09 | AC | 183 ms
41,468 KB |
testcase_10 | AC | 243 ms
41,076 KB |
testcase_11 | AC | 235 ms
41,044 KB |
testcase_12 | AC | 73 ms
37,880 KB |
testcase_13 | AC | 268 ms
40,928 KB |
testcase_14 | AC | 91 ms
38,680 KB |
testcase_15 | AC | 201 ms
41,504 KB |
testcase_16 | AC | 349 ms
41,832 KB |
testcase_17 | AC | 646 ms
43,704 KB |
testcase_18 | AC | 597 ms
43,320 KB |
testcase_19 | AC | 603 ms
43,568 KB |
testcase_20 | AC | 849 ms
44,824 KB |
testcase_21 | AC | 619 ms
43,444 KB |
testcase_22 | AC | 502 ms
42,268 KB |
testcase_23 | AC | 454 ms
42,576 KB |
testcase_24 | AC | 508 ms
42,496 KB |
testcase_25 | AC | 467 ms
42,240 KB |
testcase_26 | AC | 776 ms
44,740 KB |
testcase_27 | AC | 645 ms
42,616 KB |
testcase_28 | AC | 873 ms
44,840 KB |
testcase_29 | AC | 595 ms
43,596 KB |
testcase_30 | AC | 597 ms
43,748 KB |
testcase_31 | AC | 608 ms
43,288 KB |
testcase_32 | AC | 629 ms
43,804 KB |
testcase_33 | AC | 484 ms
42,364 KB |
testcase_34 | AC | 476 ms
42,620 KB |
testcase_35 | AC | 889 ms
44,856 KB |
testcase_36 | AC | 870 ms
44,792 KB |
testcase_37 | AC | 929 ms
44,932 KB |
testcase_38 | AC | 901 ms
44,576 KB |
testcase_39 | AC | 74 ms
37,724 KB |
testcase_40 | AC | 170 ms
41,164 KB |
testcase_41 | AC | 99 ms
39,224 KB |
testcase_42 | AC | 111 ms
39,368 KB |
testcase_43 | AC | 124 ms
39,956 KB |
testcase_44 | AC | 201 ms
41,164 KB |
testcase_45 | AC | 106 ms
39,460 KB |
testcase_46 | AC | 183 ms
40,984 KB |
testcase_47 | AC | 464 ms
42,428 KB |
testcase_48 | AC | 468 ms
42,336 KB |
testcase_49 | AC | 491 ms
42,428 KB |
testcase_50 | AC | 455 ms
42,244 KB |
testcase_51 | AC | 488 ms
42,444 KB |
testcase_52 | AC | 405 ms
41,944 KB |
testcase_53 | AC | 464 ms
42,276 KB |
testcase_54 | AC | 178 ms
41,064 KB |
testcase_55 | AC | 55 ms
37,096 KB |
testcase_56 | AC | 58 ms
37,144 KB |
testcase_57 | AC | 66 ms
37,100 KB |
ソースコード
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.NoSuchElementException; class BitVector{ long[] small; int[] big; int n; public BitVector(int n) { this.n=n; small=new long[n/64+1]; big=new int[n/64+1]; } void set(int k) { small[k/64]|=1L<<(k%64); } void build() { for(int i=0;i<big.length;++i) { big[i]=(i>0?Long.bitCount(small[i-1]):0)+(i>0?big[i-1]:0); } } int access(int k) { return (int) ((small[k/64]>>>(k%64))&1); } //[l,r) int rank(int l,int r,long m) { if(l>=r)return 0; int ret=bitCount(r)-bitCount(l); return m==1?ret:(r-l-ret); } //[0,n) int bitCount(int n) { n=Math.min(n, this.n); if(n<=0)return 0; --n; return big[n/64]+Long.bitCount((small[n/64]<<(63-n%64))>>>(63-n%64)); } } class WaveletMatrix{ int w=64; BitVector[] b=new BitVector[w];//b[i]:=&2^{i+1}で安定ソートしたときの第&2^{i} int[] nz=new int[w]; int n; final long base=Long.MAX_VALUE/2; public WaveletMatrix(long[] a) { n=a.length; for(int i=0;i<b.length;++i)b[i]=new BitVector(n); long[][] sorted=new long[n][]; for(int i=0;i<a.length;++i) { sorted[i]= new long[]{a[i]+base,0}; } Comparator<long[]> comp=new Comparator<long[]>() { @Override public int compare(long[] o1, long[] o2) { return Long.compare((o1[0]>>>o1[1])&1, (o2[0]>>>o2[1])&1); } }; for(int bit=w-1;bit>=0;--bit) { for(int i=0;i<n;++i)sorted[i][1]=bit+1; if(bit<w-1)Arrays.sort(sorted, comp);//安定ソート for(int i=0;i<n;++i)if(((sorted[i][0]>>>bit)&1)==1) { b[bit].set(i); } } for(int i=0;i<b.length;++i)b[i].build(); for(int i=0;i<b.length;++i)nz[i]=b[i].rank(0, n, 0); } long access(int k) { long ret=0; int pos=k; for(int bit=w-1;bit>=0;--bit) { int v=b[bit].access(pos); ret|=(1L<<bit)*v; pos=b[bit].rank(0, pos, v)+(v==0?0:nz[bit]); } return ret-base; } long quantile(int l,int r,int k) { if(k+1>r-l)throw new AssertionError(); long ret=0; for(int bit=w-1;bit>=0;--bit) { int nl=-1,nr=-1; if(b[bit].rank(l, r, 0)>=k+1) { nl=b[bit].rank(0, l, 0); nr=nl+b[bit].rank(l, r, 0); }else { nl=nz[bit]+b[bit].rank(0, l, 1); nr=nl+b[bit].rank(l, r, 1); k-=b[bit].rank(l, r, 0); ret|=1L<<bit; } l=nl;r=nr; } return ret-base; } } class Main { public static void main(String[] args) { new Main().run(); } void run() { FastScanner sc=new FastScanner(); int N=sc.nextInt(); long[] a=new long[N]; for(int i=0;i<N;++i)a[i]=sc.nextLong(); WaveletMatrix wm=new WaveletMatrix(a); PrintWriter pw=new PrintWriter(System.out); long ans=0; for(int K=1;K<=N;++K) { long[] right=new long[N/K]; long[] left=new long[N/K]; for(int i=0;i<N/K;++i)right[i]=wm.quantile(N-(i+1)*K, N-i*K, (K+1)/2-1)+(i>0?right[i-1]:0); for(int i=0;i<N/K;++i)left[i]=wm.quantile(i*K, (i+1)*K, (K+1)/2-1)+(i>0?left[i-1]:0); for(int i=1;i<N/K;++i)right[i]=Math.max(right[i], right[i-1]); for(int i=1;i<N/K;++i)left[i]=Math.max(left[i], left[i-1]); for(int i=-1;i<N/K;++i)ans=Math.max(ans, K*((i==-1?0:left[i])+(N/K-i-2==-1?0:right[N/K-i-2]))); } pw.println(ans); pw.close(); } void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));} } class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} }