結果

問題 No.919 You Are A Project Manager
ユーザー 37zigen37zigen
提出日時 2020-03-13 17:53:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 988 ms / 3,000 ms
コード長 5,419 bytes
コンパイル時間 2,608 ms
コンパイル使用メモリ 76,748 KB
実行使用メモリ 44,576 KB
最終ジャッジ日時 2023-08-14 13:40:03
合計ジャッジ時間 30,729 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 622 ms
41,964 KB
testcase_01 AC 37 ms
33,636 KB
testcase_02 AC 40 ms
33,636 KB
testcase_03 AC 40 ms
34,024 KB
testcase_04 AC 368 ms
41,220 KB
testcase_05 AC 365 ms
44,576 KB
testcase_06 AC 89 ms
36,220 KB
testcase_07 AC 412 ms
42,320 KB
testcase_08 AC 244 ms
37,860 KB
testcase_09 AC 243 ms
41,308 KB
testcase_10 AC 256 ms
41,340 KB
testcase_11 AC 238 ms
37,472 KB
testcase_12 AC 58 ms
34,644 KB
testcase_13 AC 240 ms
38,988 KB
testcase_14 AC 75 ms
35,520 KB
testcase_15 AC 166 ms
39,324 KB
testcase_16 AC 344 ms
42,048 KB
testcase_17 AC 649 ms
42,220 KB
testcase_18 AC 620 ms
41,876 KB
testcase_19 AC 560 ms
37,916 KB
testcase_20 AC 862 ms
40,840 KB
testcase_21 AC 699 ms
42,056 KB
testcase_22 AC 439 ms
37,896 KB
testcase_23 AC 571 ms
42,060 KB
testcase_24 AC 550 ms
42,200 KB
testcase_25 AC 471 ms
38,380 KB
testcase_26 AC 952 ms
43,108 KB
testcase_27 AC 682 ms
38,784 KB
testcase_28 AC 942 ms
43,068 KB
testcase_29 AC 623 ms
38,100 KB
testcase_30 AC 641 ms
42,412 KB
testcase_31 AC 669 ms
42,112 KB
testcase_32 AC 657 ms
42,148 KB
testcase_33 AC 536 ms
42,044 KB
testcase_34 AC 588 ms
42,196 KB
testcase_35 AC 931 ms
40,236 KB
testcase_36 AC 988 ms
42,968 KB
testcase_37 AC 865 ms
43,208 KB
testcase_38 AC 916 ms
43,068 KB
testcase_39 AC 58 ms
35,128 KB
testcase_40 AC 191 ms
40,844 KB
testcase_41 AC 84 ms
36,528 KB
testcase_42 AC 94 ms
36,088 KB
testcase_43 AC 109 ms
37,392 KB
testcase_44 AC 193 ms
37,500 KB
testcase_45 AC 91 ms
36,852 KB
testcase_46 AC 205 ms
40,844 KB
testcase_47 AC 500 ms
38,404 KB
testcase_48 AC 571 ms
42,228 KB
testcase_49 AC 484 ms
38,340 KB
testcase_50 AC 482 ms
37,880 KB
testcase_51 AC 429 ms
37,828 KB
testcase_52 AC 377 ms
42,088 KB
testcase_53 AC 485 ms
38,380 KB
testcase_54 AC 161 ms
41,580 KB
testcase_55 AC 41 ms
33,640 KB
testcase_56 AC 47 ms
33,760 KB
testcase_57 AC 55 ms
34,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
		long[] right=new long[N];
		long[] left=new long[N];
		for(int K=1;K<=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());}
}
0