結果

問題 No.318 学学学学学
ユーザー 37zigen37zigen
提出日時 2020-03-27 04:50:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,485 ms / 2,000 ms
コード長 3,780 bytes
コンパイル時間 5,107 ms
コンパイル使用メモリ 86,156 KB
実行使用メモリ 70,456 KB
最終ジャッジ日時 2023-08-30 16:04:52
合計ジャッジ時間 36,945 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 487 ms
61,896 KB
testcase_01 AC 621 ms
61,348 KB
testcase_02 AC 671 ms
61,160 KB
testcase_03 AC 579 ms
61,528 KB
testcase_04 AC 628 ms
61,192 KB
testcase_05 AC 1,485 ms
70,220 KB
testcase_06 AC 1,444 ms
68,192 KB
testcase_07 AC 1,439 ms
69,596 KB
testcase_08 AC 1,476 ms
70,200 KB
testcase_09 AC 1,443 ms
70,456 KB
testcase_10 AC 1,448 ms
54,316 KB
testcase_11 AC 1,448 ms
54,568 KB
testcase_12 AC 1,440 ms
55,232 KB
testcase_13 AC 1,398 ms
54,840 KB
testcase_14 AC 1,399 ms
56,448 KB
testcase_15 AC 1,431 ms
69,980 KB
testcase_16 AC 1,408 ms
55,204 KB
testcase_17 AC 1,277 ms
55,016 KB
testcase_18 AC 1,398 ms
54,604 KB
testcase_19 AC 1,365 ms
54,984 KB
testcase_20 AC 1,334 ms
54,332 KB
testcase_21 AC 170 ms
40,848 KB
testcase_22 AC 159 ms
40,572 KB
testcase_23 AC 163 ms
41,060 KB
testcase_24 AC 161 ms
41,256 KB
testcase_25 AC 160 ms
40,480 KB
testcase_26 AC 162 ms
40,792 KB
testcase_27 AC 160 ms
40,760 KB
testcase_28 AC 160 ms
40,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
	class SegTree{
		int n=1;
		int[] v;
		int nil=-1;
		
		public SegTree(int n_) {
			while(n<n_)n*=2;
			v=new int[2*n-1];
			Arrays.fill(v, nil);
		}
		
		void push(int k) {
			if(2*k+2<v.length&&v[k]!=nil) {
				v[2*k+1]=v[k];
				v[2*k+2]=v[k];
			}
		}
		
		int query(int a,int b,int val) {
			return query(0,n,a,b,0,val);
		}
		
		int query(int a,int b) {
			return query(0,n,a,b,0,nil);
		}
		
		int query(int l,int r,int a,int b,int k,int val) {
			push(k);
			if(r<=a||b<=l)return nil;
			else if(a<=l&&r<=b&&(val!=nil||r-l==1)) {
				if(val!=nil) {
					v[k]=val;
					push(k);
				}
				return v[k];
			}else {
				int vl=query(l,(l+r)/2,a,b,2*k+1,val);
				int vr=query((l+r)/2,r,a,b,2*k+2,val);
				v[k]=nil;
				return Math.max(vl, vr);
			}
		}
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		long[] a=new long[n];
		for(int i=0;i<n;++i) {
			a[i]=sc.nextLong()<<32|i;
		}
		Arrays.sort(a);
		SegTree seg=new SegTree(n);
		for(int i=0;i<n;) {
			int j=i;
			int left=n,right=-1;
			while(j<n&&a[i]>>32==a[j]>>32) {
				left=Math.min(left, (int)a[j]);
				right=Math.max(right, (int)a[j]);
				++j;
			}
			seg.query(left, right+1,(int)(a[i]>>32));
			i=j;
		}
		for(int i=0;i<n;++i) {
			System.out.print(seg.query(i, i+1)+(i==n-1?"\n":" "));
		}
	}
	
	public static void main(String[] args) throws FileNotFoundException {
		long t = System.currentTimeMillis();
		new Main().run();
		System.err.println(System.currentTimeMillis() - t);
	}
}
	
	
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;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); 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() {
    	return (int)nextLong();
    }
}
0