結果

問題 No.1496 不思議な数え上げ
ユーザー tentententen
提出日時 2021-07-30 08:39:38
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,868 bytes
コンパイル時間 2,207 ms
コンパイル使用メモリ 76,648 KB
実行使用メモリ 101,564 KB
最終ジャッジ日時 2023-10-13 07:12:05
合計ジャッジ時間 12,214 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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