結果

問題 No.2650 [Cherry 6th Tune *] セイジャク
ユーザー tentententen
提出日時 2024-02-29 17:53:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,060 ms / 2,500 ms
コード長 2,203 bytes
コンパイル時間 3,598 ms
コンパイル使用メモリ 95,240 KB
実行使用メモリ 98,556 KB
最終ジャッジ日時 2024-02-29 17:54:02
合計ジャッジ時間 32,166 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
54,704 KB
testcase_01 AC 65 ms
54,756 KB
testcase_02 AC 582 ms
75,260 KB
testcase_03 AC 240 ms
60,516 KB
testcase_04 AC 569 ms
69,764 KB
testcase_05 AC 536 ms
70,004 KB
testcase_06 AC 419 ms
65,636 KB
testcase_07 AC 539 ms
67,676 KB
testcase_08 AC 386 ms
64,532 KB
testcase_09 AC 928 ms
87,348 KB
testcase_10 AC 883 ms
85,764 KB
testcase_11 AC 916 ms
87,244 KB
testcase_12 AC 917 ms
86,464 KB
testcase_13 AC 1,006 ms
93,952 KB
testcase_14 AC 893 ms
86,056 KB
testcase_15 AC 895 ms
86,864 KB
testcase_16 AC 993 ms
87,940 KB
testcase_17 AC 947 ms
82,940 KB
testcase_18 AC 971 ms
88,720 KB
testcase_19 AC 998 ms
87,476 KB
testcase_20 AC 1,042 ms
88,764 KB
testcase_21 AC 949 ms
87,404 KB
testcase_22 AC 1,024 ms
89,104 KB
testcase_23 AC 950 ms
88,728 KB
testcase_24 AC 1,060 ms
98,556 KB
testcase_25 AC 1,007 ms
94,948 KB
testcase_26 AC 889 ms
87,156 KB
testcase_27 AC 878 ms
86,956 KB
testcase_28 AC 886 ms
88,320 KB
testcase_29 AC 879 ms
87,920 KB
testcase_30 AC 978 ms
87,976 KB
testcase_31 AC 891 ms
85,828 KB
testcase_32 AC 831 ms
82,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int a = sc.nextInt();
        TreeMap<Integer, List<Integer>> places = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            if (!places.containsKey(x)) {
                places.put(x, new ArrayList<>());
            }
            places.get(x).add(i);
        }
        int t = sc.nextInt();
        int[] lefts = new int[t];
        int[] rights = new int[t];
        for (int i = 0; i < t; i++) {
            lefts[i] = sc.nextInt();
            rights[i] = sc.nextInt();
        }
        int[] ans = new int[n];
        Arrays.fill(ans, -1);
        for (int i = t - 1; i >= 0; i--) {
            Integer key = lefts[i] - 1;
            while ((key = places.higherKey(key)) != null) {
                if (key > rights[i]) {
                    break;
                }
                for (int x : places.get(key)) {
                    ans[x] = i + 1;
                }
                places.remove(key);
            }
        }
        System.out.println(Arrays.stream(ans).mapToObj(String::valueOf).collect(Collectors.joining("\n")));
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0