結果

問題 No.469 区間加算と一致検索の問題
ユーザー kuuso1kuuso1
提出日時 2016-12-19 22:55:04
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 259 ms / 5,000 ms
コード長 1,860 bytes
コンパイル時間 2,973 ms
コンパイル使用メモリ 108,948 KB
実行使用メモリ 52,392 KB
最終ジャッジ日時 2023-08-23 13:30:47
合計ジャッジ時間 12,630 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
22,740 KB
testcase_01 AC 66 ms
22,864 KB
testcase_02 AC 71 ms
25,848 KB
testcase_03 AC 73 ms
22,820 KB
testcase_04 AC 73 ms
22,720 KB
testcase_05 AC 74 ms
22,916 KB
testcase_06 AC 75 ms
22,808 KB
testcase_07 AC 76 ms
22,752 KB
testcase_08 AC 78 ms
24,824 KB
testcase_09 AC 72 ms
22,704 KB
testcase_10 AC 76 ms
22,736 KB
testcase_11 AC 72 ms
22,792 KB
testcase_12 AC 79 ms
27,352 KB
testcase_13 AC 73 ms
22,964 KB
testcase_14 AC 68 ms
20,756 KB
testcase_15 AC 70 ms
20,752 KB
testcase_16 AC 77 ms
24,892 KB
testcase_17 AC 75 ms
22,692 KB
testcase_18 AC 75 ms
22,844 KB
testcase_19 AC 68 ms
22,808 KB
testcase_20 AC 78 ms
22,944 KB
testcase_21 AC 69 ms
22,920 KB
testcase_22 AC 67 ms
24,712 KB
testcase_23 AC 133 ms
31,324 KB
testcase_24 AC 133 ms
35,480 KB
testcase_25 AC 134 ms
33,712 KB
testcase_26 AC 136 ms
35,480 KB
testcase_27 AC 134 ms
33,500 KB
testcase_28 AC 134 ms
35,496 KB
testcase_29 AC 134 ms
35,516 KB
testcase_30 AC 135 ms
35,524 KB
testcase_31 AC 133 ms
33,528 KB
testcase_32 AC 135 ms
31,536 KB
testcase_33 AC 255 ms
51,592 KB
testcase_34 AC 254 ms
51,480 KB
testcase_35 AC 256 ms
49,240 KB
testcase_36 AC 259 ms
52,392 KB
testcase_37 AC 253 ms
49,420 KB
testcase_38 AC 250 ms
46,128 KB
testcase_39 AC 251 ms
47,988 KB
testcase_40 AC 252 ms
45,900 KB
testcase_41 AC 250 ms
48,044 KB
testcase_42 AC 251 ms
47,896 KB
testcase_43 AC 251 ms
45,984 KB
testcase_44 AC 253 ms
47,932 KB
testcase_45 AC 252 ms
45,928 KB
testcase_46 AC 252 ms
45,916 KB
testcase_47 AC 255 ms
45,944 KB
testcase_48 AC 67 ms
22,992 KB
testcase_49 AC 64 ms
22,840 KB
testcase_50 AC 252 ms
48,012 KB
testcase_51 AC 253 ms
47,992 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long mod = (long) 1e13+9;
		long[] ms = new long[N+1];
		var rnd = new Random();
		for(int i=0;i<N+1;i++){
			ms[i] = rnd.Next()%mod;
			if(ms[i] < 0) ms[i] += mod;
		}
		
		long[] res = new long[Q+1];
		long[] A = new long[N+1];
		long tot = 0;
		for(int i=0;i<N+1;i++) tot += A[i] * ms[i];
		res[0] = tot;
		Dictionary<long,int> his = new Dictionary<long,int>();
		his.Add(tot,0);
		List<int> L = new List<int>();
		for(int i=0;i<Q;i++){
			if(S[i][0] == '?'){
				res[i+1] = res[i];
				L.Add(his[res[i+1]]);
				continue;
			}
			
			var ss = S[i].Split();
			int a = int.Parse(ss[1]);
			int b = int.Parse(ss[2]);
			int k = int.Parse(ss[3]);
			
			tot += k * ms[a];
			tot -= k * ms[b];
			tot %= mod; if(tot<0) tot += mod;
			
			res[i+1] = tot;
			if(!his.ContainsKey(tot)){
				his.Add(tot,i+1);
			}
		}
		
		Console.WriteLine(String.Join("\n",L));
		
	}
	int N,Q;
	String[] S;
	public Sol(){
		var d = ria();
		N = d[0];
		Q = d[1];
		S = new String[Q];
		for(int i=0;i<Q;i++) S[i] = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0