結果
| 問題 | No.1496 不思議な数え上げ |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-07-30 08:37:39 |
| 言語 | Java (openjdk 26.0.2.1 + ACL) |
| 結果 |
RE
不安定
|
| 実行時間 | - |
| コード長 | 1,863 bytes |
| 記録 | |
| コンパイル時間 | 1,812 ms |
| コンパイル使用メモリ | 87,984 KB |
| 実行使用メモリ | 95,576 KB |
| 最終ジャッジ日時 | 2026-08-27 17:45:08 |
| 合計ジャッジ時間 | 24,994 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 WA * 5 RE * 33 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int[] sums = new int[n + 1];
HashMap<Integer, Integer> positions = new HashMap<>();
for (int i = 1; i <= n; i++) {
int x = sc.nextInt();
sums[i] = x + sums[i - 1];
positions.put(x, i);
}
int[] limits = new int[n + 1];
for (int i = 1; i <= n; i++) {
limits[i] = sc.nextInt();
}
TreeSet<Integer> used = new TreeSet<>();
used.add(0);
used.add(n + 1);
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= n; i++) {
long ans = 0;
int base = positions.get(i);
int left = used.lower(base);
int right = used.higher(base);
int current = left;
for (int j = base; j < right; j++) {
while (current < base && sums[j] - sums[current] > limits[i]) {
current++;
}
ans += base - current;
}
sb.append(ans).append("\n");
used.add(base);
}
System.out.print(sb);
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten