結果
問題 |
No.469 区間加算と一致検索の問題
|
ユーザー |
![]() |
提出日時 | 2016-12-19 22:50:24 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,859 bytes |
コンパイル時間 | 1,726 ms |
コンパイル使用メモリ | 116,032 KB |
実行使用メモリ | 50,004 KB |
最終ジャッジ日時 | 2024-12-14 09:02:13 |
合計ジャッジ時間 | 9,072 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 3 WA * 46 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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) 1e9+7; 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));} }