結果
| 問題 |
No.469 区間加算と一致検索の問題
|
| コンテスト | |
| ユーザー |
kuuso1
|
| 提出日時 | 2016-12-19 01:25:57 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 225 ms / 5,000 ms |
| コード長 | 2,004 bytes |
| コンパイル時間 | 1,112 ms |
| コンパイル使用メモリ | 108,928 KB |
| 実行使用メモリ | 51,840 KB |
| 最終ジャッジ日時 | 2024-12-21 16:43:27 |
| 合計ジャッジ時間 | 8,616 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
コンパイルメッセージ
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(){
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));}
}
kuuso1