結果

問題 No.469 区間加算と一致検索の問題
ユーザー 37zigen37zigen
提出日時 2016-12-20 12:36:59
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,486 bytes
コンパイル時間 3,980 ms
コンパイル使用メモリ 79,240 KB
実行使用メモリ 96,364 KB
最終ジャッジ日時 2024-05-08 08:37:22
合計ジャッジ時間 40,053 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
41,776 KB
testcase_01 AC 155 ms
41,800 KB
testcase_02 AC 162 ms
47,176 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 348 ms
48,628 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 385 ms
48,436 KB
testcase_11 AC 255 ms
47,124 KB
testcase_12 WA -
testcase_13 AC 318 ms
48,828 KB
testcase_14 AC 240 ms
46,552 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 234 ms
46,776 KB
testcase_20 WA -
testcase_21 AC 249 ms
46,548 KB
testcase_22 AC 197 ms
42,676 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 181 ms
42,796 KB
testcase_49 AC 140 ms
41,900 KB
testcase_50 WA -
testcase_51 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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 + 7;
		long m1 = 1_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();
	}
}
0