結果
問題 |
No.1441 MErGe
|
ユーザー |
![]() |
提出日時 | 2022-09-02 11:57:40 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,704 bytes |
コンパイル時間 | 3,129 ms |
コンパイル使用メモリ | 78,856 KB |
実行使用メモリ | 155,936 KB |
最終ジャッジ日時 | 2024-11-15 17:24:16 |
合計ジャッジ時間 | 38,527 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 13 TLE * 15 |
ソースコード
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 q = sc.nextInt(); long[] sums = new long[n + 1]; ArrayList<Integer> idxes = new ArrayList<>(); idxes.add(0); for (int i = 1; i <= n; i++) { sums[i] = sums[i - 1] + sc.nextInt(); idxes.add(i); } StringBuilder sb = new StringBuilder(); while (q-- > 0) { int type = sc.nextInt(); int left = sc.nextInt(); int right = sc.nextInt(); if (type == 1) { for (int i = 0; i < right - left; i++) { idxes.remove(left); } } else { sb.append(sums[idxes.get(right)] - sums[idxes.get(left - 1)]).append("\n"); } } System.out.print(sb); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }