結果
| 問題 |
No.1496 不思議な数え上げ
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-07-30 08:39:38 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,868 bytes |
| コンパイル時間 | 2,474 ms |
| コンパイル使用メモリ | 79,364 KB |
| 実行使用メモリ | 90,752 KB |
| 最終ジャッジ日時 | 2024-09-15 04:28:01 |
| 合計ジャッジ時間 | 11,656 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 3 TLE * 1 -- * 35 |
ソースコード
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();
long[] sums = new long[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);
}
long[] limits = new long[n + 1];
for (int i = 1; i <= n; i++) {
limits[i] = sc.nextLong();
}
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