結果

問題 No.469 区間加算と一致検索の問題
ユーザー 37zigen37zigen
提出日時 2016-12-20 12:41:10
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,494 bytes
コンパイル時間 3,461 ms
コンパイル使用メモリ 79,408 KB
実行使用メモリ 98,560 KB
最終ジャッジ日時 2024-05-08 08:39:12
合計ジャッジ時間 42,000 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 154 ms
42,048 KB
testcase_01 AC 150 ms
41,984 KB
testcase_02 AC 162 ms
46,328 KB
testcase_03 AC 306 ms
47,972 KB
testcase_04 AC 332 ms
48,300 KB
testcase_05 AC 355 ms
48,588 KB
testcase_06 AC 376 ms
48,928 KB
testcase_07 AC 371 ms
48,580 KB
testcase_08 AC 398 ms
48,988 KB
testcase_09 AC 293 ms
48,160 KB
testcase_10 AC 391 ms
48,496 KB
testcase_11 AC 280 ms
47,192 KB
testcase_12 AC 413 ms
49,172 KB
testcase_13 AC 339 ms
48,652 KB
testcase_14 AC 252 ms
46,400 KB
testcase_15 AC 283 ms
47,632 KB
testcase_16 AC 410 ms
48,536 KB
testcase_17 AC 367 ms
48,464 KB
testcase_18 AC 367 ms
48,584 KB
testcase_19 AC 249 ms
46,256 KB
testcase_20 AC 398 ms
48,904 KB
testcase_21 AC 280 ms
47,196 KB
testcase_22 AC 207 ms
43,220 KB
testcase_23 AC 850 ms
57,036 KB
testcase_24 AC 826 ms
56,616 KB
testcase_25 AC 727 ms
55,156 KB
testcase_26 AC 787 ms
57,056 KB
testcase_27 AC 769 ms
56,940 KB
testcase_28 AC 715 ms
53,460 KB
testcase_29 AC 810 ms
57,060 KB
testcase_30 AC 811 ms
56,864 KB
testcase_31 AC 772 ms
56,436 KB
testcase_32 AC 784 ms
56,756 KB
testcase_33 WA -
testcase_34 AC 1,246 ms
97,440 KB
testcase_35 WA -
testcase_36 AC 1,293 ms
95,280 KB
testcase_37 AC 1,299 ms
95,756 KB
testcase_38 AC 1,261 ms
96,260 KB
testcase_39 AC 1,265 ms
96,188 KB
testcase_40 WA -
testcase_41 AC 1,154 ms
96,036 KB
testcase_42 AC 1,261 ms
96,376 KB
testcase_43 AC 1,283 ms
96,412 KB
testcase_44 AC 1,262 ms
96,236 KB
testcase_45 AC 1,274 ms
96,100 KB
testcase_46 AC 1,266 ms
94,584 KB
testcase_47 AC 1,269 ms
94,872 KB
testcase_48 AC 167 ms
41,992 KB
testcase_49 AC 151 ms
42,008 KB
testcase_50 WA -
testcase_51 AC 1,155 ms
95,984 KB
権限があれば一括ダウンロードができます

ソースコード

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 p2 = 1_000_000_000 + 7;
		long m2 = 1_000_000_000 + 9;
		long p1 = BigInteger.probablePrime(30, rand).longValue();
		long m1 = 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