結果
問題 |
No.469 区間加算と一致検索の問題
|
ユーザー |
|
提出日時 | 2016-12-20 12:27:31 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 988 bytes |
コンパイル時間 | 3,748 ms |
コンパイル使用メモリ | 78,552 KB |
実行使用メモリ | 143,912 KB |
最終ジャッジ日時 | 2024-12-14 11:15:36 |
合計ジャッジ時間 | 90,356 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 WA * 9 TLE * 4 |
ソースコード
package yukicoder; import java.util.HashMap; import java.util.Scanner; public class Q469 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int q = sc.nextInt(); long p1 = 1_000_000 + 7; long m1 = 1_000_000 + 9; long[] pow = new long[n]; pow[0] = 1; for (int i = 1; i < n; ++i) { pow[i] = pow[i - 1] * p1 % m1; } long[] accum = new long[n]; accum[0] = pow[0]; for (int i = 1; i < n; ++i) { accum[i] = accum[i - 1] + pow[i]; } HashMap<Long, Integer> map = new HashMap<>(); map.put(0L, 0); long h1 = 0; for (int query = 0; query < q; ++query) { String s = sc.next(); if (s.equals("!")) { int l = sc.nextInt(); int r = sc.nextInt(); int k = sc.nextInt(); h1 += (accum[r - 1] - (l > 0 ? accum[l - 1] : 0)) * k; while (h1 < 0) h1 += m1; if (!map.containsKey(h1)) { map.put(h1, query + 1); } } else { System.out.println(map.get(h1)); } } } }