結果

問題 No.318 学学学学学
ユーザー GrenacheGrenache
提出日時 2015-12-11 19:12:18
言語 Java19
(openjdk 21)
結果
AC  
実行時間 849 ms / 2,000 ms
コード長 3,286 bytes
コンパイル時間 5,251 ms
コンパイル使用メモリ 77,776 KB
実行使用メモリ 81,080 KB
最終ジャッジ日時 2023-09-04 17:36:39
合計ジャッジ時間 18,095 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 167 ms
55,176 KB
testcase_01 AC 269 ms
59,568 KB
testcase_02 AC 293 ms
59,648 KB
testcase_03 AC 251 ms
59,572 KB
testcase_04 AC 258 ms
57,784 KB
testcase_05 AC 795 ms
81,080 KB
testcase_06 AC 644 ms
71,912 KB
testcase_07 AC 600 ms
69,120 KB
testcase_08 AC 521 ms
68,476 KB
testcase_09 AC 420 ms
64,636 KB
testcase_10 AC 397 ms
65,856 KB
testcase_11 AC 849 ms
79,556 KB
testcase_12 AC 646 ms
71,152 KB
testcase_13 AC 544 ms
68,960 KB
testcase_14 AC 475 ms
67,856 KB
testcase_15 AC 427 ms
64,356 KB
testcase_16 AC 386 ms
66,004 KB
testcase_17 AC 517 ms
70,984 KB
testcase_18 AC 489 ms
68,660 KB
testcase_19 AC 431 ms
72,392 KB
testcase_20 AC 337 ms
63,140 KB
testcase_21 AC 48 ms
50,080 KB
testcase_22 AC 47 ms
49,872 KB
testcase_23 AC 48 ms
49,916 KB
testcase_24 AC 47 ms
50,224 KB
testcase_25 AC 48 ms
48,000 KB
testcase_26 AC 48 ms
49,820 KB
testcase_27 AC 47 ms
49,752 KB
testcase_28 AC 47 ms
49,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.PriorityQueue;


public class Main_yukicoder318 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Printer pr = new Printer(System.out);

        int n = sc.nextInt();
        Map<Integer, Range> hm = new HashMap<Integer, Range>();
        for (int i = 0; i < n; i++) {
        	int a = sc.nextInt();
        	if (hm.containsKey(a)) {
        		Range r = hm.get(a);
        		if (r.e < i) {
        			r.e = i;
        		}
        	} else {
        		hm.put(a, new Range(a, i, i));
        	}
        }

        LinkedList<Range> list = new LinkedList<Range>(hm.values());
        Collections.sort(list);

        PriorityQueue<Range> pq = new PriorityQueue<Range>(new Comparator<Range>() {
			@Override
			public int compare(Range o1, Range o2) {
				if (o2.t != o1.t) {
					return Integer.compare(o2.t, o1.t);
				}
				return 0;
			}
		});


        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
        	while (!list.isEmpty() && list.peekFirst().s <= i) {
        		pq.add(list.removeFirst());
        	}

        	while (pq.peek().e < i) {
        		pq.remove();
        	}

        	b[i] = pq.peek().t;
        }

        for (int i = 0; i < n; i++) {
        	if (i != 0) {
        		pr.print(" ");
        	}

        	pr.print(b[i]);
        }
        pr.println();

        pr.close();
        sc.close();
    }

    private static class Range implements Comparable<Range> {
    	int t;
    	int s;
    	int e;

    	Range(int t, int s, int e) {
    		this.t = t;
    		this.s = s;
    		this.e = e;
    	}

		@Override
		public int compareTo(Range o) {
			if (this.s != o.s) {
				return Integer.compare(this.s, o.s);
			}
//			if (this.e != o.e) {
//				return Integer.compare(o.e, this.e);
//			}
//			if (this.t != o.t) {
//				return Integer.compare(o.t, this.t);
//			}
			return 0;
		}
    }

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;

		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
					it = Arrays.asList(br.readLine().split(" ")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0