結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
41,876 KB
testcase_01 AC 161 ms
42,136 KB
testcase_02 AC 160 ms
46,536 KB
testcase_03 AC 316 ms
48,384 KB
testcase_04 AC 324 ms
48,336 KB
testcase_05 AC 340 ms
48,296 KB
testcase_06 AC 373 ms
48,484 KB
testcase_07 AC 372 ms
48,908 KB
testcase_08 AC 368 ms
47,672 KB
testcase_09 AC 297 ms
47,348 KB
testcase_10 AC 400 ms
48,516 KB
testcase_11 AC 277 ms
46,868 KB
testcase_12 WA -
testcase_13 AC 340 ms
48,812 KB
testcase_14 AC 256 ms
46,488 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 388 ms
48,572 KB
testcase_18 AC 376 ms
48,484 KB
testcase_19 AC 264 ms
46,900 KB
testcase_20 WA -
testcase_21 AC 274 ms
47,204 KB
testcase_22 AC 217 ms
43,752 KB
testcase_23 AC 906 ms
56,476 KB
testcase_24 AC 752 ms
57,596 KB
testcase_25 WA -
testcase_26 AC 772 ms
56,992 KB
testcase_27 AC 838 ms
57,108 KB
testcase_28 AC 730 ms
58,760 KB
testcase_29 AC 824 ms
56,948 KB
testcase_30 AC 837 ms
56,920 KB
testcase_31 AC 778 ms
56,636 KB
testcase_32 AC 825 ms
56,660 KB
testcase_33 AC 1,221 ms
98,220 KB
testcase_34 AC 1,311 ms
95,400 KB
testcase_35 WA -
testcase_36 AC 1,225 ms
96,600 KB
testcase_37 AC 1,221 ms
98,216 KB
testcase_38 AC 1,274 ms
94,972 KB
testcase_39 AC 1,257 ms
96,416 KB
testcase_40 AC 1,341 ms
94,908 KB
testcase_41 WA -
testcase_42 AC 1,251 ms
96,172 KB
testcase_43 AC 1,258 ms
94,784 KB
testcase_44 AC 1,209 ms
97,612 KB
testcase_45 AC 1,186 ms
96,384 KB
testcase_46 AC 1,191 ms
98,336 KB
testcase_47 AC 1,264 ms
94,888 KB
testcase_48 AC 174 ms
41,904 KB
testcase_49 AC 133 ms
40,688 KB
testcase_50 AC 1,206 ms
95,132 KB
testcase_51 AC 1,276 ms
96,176 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 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();
	}
}
0