結果
| 問題 |
No.469 区間加算と一致検索の問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-20 12:40:13 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,494 bytes |
| コンパイル時間 | 4,212 ms |
| コンパイル使用メモリ | 86,516 KB |
| 実行使用メモリ | 106,704 KB |
| 最終ジャッジ日時 | 2024-12-14 11:19:27 |
| 合計ジャッジ時間 | 43,077 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 WA * 7 |
ソースコード
package yukicoder;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Random;
import java.util.Scanner;
public class Q469 {
public static void main(String[] args) {
PrintWriter pw = new PrintWriter(System.out);
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int q = sc.nextInt();
Random rand = new Random();
long p1 = 1_000_000_000 + 7;
long m1 = 1_000_000_000 + 9;
long p2 = BigInteger.probablePrime(30, rand).longValue();
long m2 = BigInteger.probablePrime(30, rand).longValue();
long[] pow1 = new long[n];
long[] pow2 = new long[n];
pow1[0] = 1;
pow2[0] = 1;
for (int i = 1; i < n; ++i) {
pow1[i] = pow1[i - 1] * p1 % m1;
pow2[i] = pow2[i - 1] * p2 % m2;
}
long[] accum1 = new long[n];
long[] accum2 = new long[n];
accum1[0] = pow1[0];
accum2[0] = pow2[0];
for (int i = 1; i < n; ++i) {
accum1[i] = (accum1[i - 1] + pow1[i]) % m1;
accum2[i] = accum2[i - 1] + pow2[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 += (accum1[r - 1] - (l > 0 ? accum1[l - 1] : 0)) * k % m1;
while (h1 < 0)
h1 += m1;
h1 %= m1;
if (!map.containsKey(h1)) {
map.put(h1, query + 1);
}
} else {
pw.println(map.get(h1));
}
}
pw.close();
}
}