結果

問題 No.469 区間加算と一致検索の問題
ユーザー kuuso1kuuso1
提出日時 2016-12-19 01:25:57
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 236 ms / 5,000 ms
コード長 2,004 bytes
コンパイル時間 2,322 ms
コンパイル使用メモリ 106,744 KB
実行使用メモリ 58,232 KB
最終ジャッジ日時 2023-08-23 13:21:18
合計ジャッジ時間 11,475 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
22,820 KB
testcase_01 AC 63 ms
20,744 KB
testcase_02 AC 66 ms
22,124 KB
testcase_03 AC 70 ms
20,680 KB
testcase_04 AC 70 ms
20,724 KB
testcase_05 AC 71 ms
20,732 KB
testcase_06 AC 73 ms
20,776 KB
testcase_07 AC 72 ms
20,708 KB
testcase_08 AC 74 ms
22,768 KB
testcase_09 AC 68 ms
20,676 KB
testcase_10 AC 73 ms
20,732 KB
testcase_11 AC 66 ms
20,644 KB
testcase_12 AC 76 ms
23,232 KB
testcase_13 AC 70 ms
20,864 KB
testcase_14 AC 65 ms
20,864 KB
testcase_15 AC 67 ms
22,768 KB
testcase_16 AC 73 ms
20,784 KB
testcase_17 AC 71 ms
20,768 KB
testcase_18 AC 73 ms
20,652 KB
testcase_19 AC 65 ms
18,800 KB
testcase_20 AC 76 ms
20,936 KB
testcase_21 AC 65 ms
20,784 KB
testcase_22 AC 63 ms
22,736 KB
testcase_23 AC 130 ms
31,628 KB
testcase_24 AC 129 ms
31,380 KB
testcase_25 AC 131 ms
33,540 KB
testcase_26 AC 130 ms
29,432 KB
testcase_27 AC 131 ms
31,452 KB
testcase_28 AC 133 ms
31,480 KB
testcase_29 AC 131 ms
31,648 KB
testcase_30 AC 128 ms
33,444 KB
testcase_31 AC 128 ms
29,444 KB
testcase_32 AC 129 ms
31,448 KB
testcase_33 AC 234 ms
57,164 KB
testcase_34 AC 234 ms
58,232 KB
testcase_35 AC 231 ms
56,176 KB
testcase_36 AC 230 ms
56,272 KB
testcase_37 AC 236 ms
56,140 KB
testcase_38 AC 226 ms
51,692 KB
testcase_39 AC 226 ms
51,788 KB
testcase_40 AC 229 ms
51,816 KB
testcase_41 AC 227 ms
51,640 KB
testcase_42 AC 226 ms
51,684 KB
testcase_43 AC 228 ms
51,760 KB
testcase_44 AC 229 ms
53,700 KB
testcase_45 AC 226 ms
53,788 KB
testcase_46 AC 226 ms
53,744 KB
testcase_47 AC 229 ms
53,720 KB
testcase_48 AC 64 ms
20,860 KB
testcase_49 AC 60 ms
18,672 KB
testcase_50 AC 230 ms
51,788 KB
testcase_51 AC 226 ms
53,760 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(){
		
		ulong mod = (ulong) 1e9+7;
		ulong[] ms = new ulong[N+1];
		ms[0] = mod;
		for(int i=1;i<N+1;i++) ms[i] = ms[i-1] * mod;
		
		ulong ofs = (ulong) 2e8;
		ulong[] A = new ulong[N+1];
		for(int i=0;i<N+1;i++) A[i] = ofs;
		int[] AA = new int[N+1];
		
		ulong[] res = new ulong[Q+1];
		
		ulong tot = 0;
		for(int i=0;i<N+1;i++) tot += A[i] * ms[i];
		res[0] = tot;
		Dictionary<ulong,int> his = new Dictionary<ulong,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]);
			
			if(k>0){
				tot += ((ulong) k) * ms[a];
				tot -= ((ulong) k) * ms[b];
			}else if(k<0){
				tot -= ((ulong)(-k)) * ms[a];
				tot += ((ulong)(-k)) * ms[b];
			}
			
			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