結果
| 問題 |
No.2650 [Cherry 6th Tune *] セイジャク
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2024-02-29 17:53:25 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,175 ms / 2,500 ms |
| コード長 | 2,203 bytes |
| コンパイル時間 | 2,961 ms |
| コンパイル使用メモリ | 91,852 KB |
| 実行使用メモリ | 91,972 KB |
| 最終ジャッジ日時 | 2024-09-29 12:48:04 |
| 合計ジャッジ時間 | 28,532 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 31 |
ソースコード
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();
}
}
}
tenten