結果

問題 No.1496 不思議な数え上げ
ユーザー tentententen
提出日時 2021-07-30 08:37:39
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,863 bytes
コンパイル時間 3,116 ms
コンパイル使用メモリ 75,972 KB
実行使用メモリ 101,844 KB
最終ジャッジ日時 2023-10-13 07:10:15
合計ジャッジ時間 28,992 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,544 KB
testcase_01 AC 42 ms
49,588 KB
testcase_02 AC 42 ms
49,696 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 117 ms
52,744 KB
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
}
0