結果

問題 No.151 セグメントフィッシング
ユーザー gigurururugigurururu
提出日時 2015-02-15 16:47:58
言語 Ruby
(3.3.0)
結果
AC  
実行時間 236 ms / 5,000 ms
コード長 446 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 11,540 KB
実行使用メモリ 16,056 KB
最終ジャッジ日時 2023-08-27 05:29:12
合計ジャッジ時間 5,212 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,320 KB
testcase_01 AC 83 ms
15,220 KB
testcase_02 AC 82 ms
15,300 KB
testcase_03 AC 82 ms
15,080 KB
testcase_04 AC 83 ms
15,104 KB
testcase_05 AC 83 ms
15,244 KB
testcase_06 AC 84 ms
15,032 KB
testcase_07 AC 83 ms
14,980 KB
testcase_08 AC 103 ms
15,340 KB
testcase_09 AC 104 ms
15,548 KB
testcase_10 AC 104 ms
15,404 KB
testcase_11 AC 103 ms
15,304 KB
testcase_12 AC 169 ms
15,848 KB
testcase_13 AC 170 ms
15,804 KB
testcase_14 AC 169 ms
16,012 KB
testcase_15 AC 171 ms
15,988 KB
testcase_16 AC 169 ms
15,784 KB
testcase_17 AC 135 ms
15,888 KB
testcase_18 AC 146 ms
15,864 KB
testcase_19 AC 232 ms
15,840 KB
testcase_20 AC 236 ms
16,056 KB
testcase_21 AC 139 ms
15,900 KB
testcase_22 AC 136 ms
15,880 KB
testcase_23 AC 151 ms
15,412 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:6: warning: assigned but unused variable - m
Syntax OK

ソースコード

diff #

N,Q=gets.split.map(&:to_i)
NN=N*2
BIT=[0]*(NN+1)
def add x,v;(BIT[x]+=v;x+=x&-x)while BIT[x];end
def sum x;s=0;(s+=BIT[x];x&=x-1)while x>0;s;end
m=[0]*NN
Q.times{|t|
  t+=1
  x,*v=gets.split
  y,z=v.map(&:to_i)
  case x
  when ?L
    add (y+t)%NN+1,z
  when ?R
    add (-y-1+t)%NN+1,z
  when ?C
    ty,tz=(y+t)%NN,(z-1+t)%NN
    uz,uy=(-z+t)%NN,(-y-1+t)%NN
    p sum(tz+1)-sum(ty)+(ty<=tz ?0:sum(NN))+sum(uy+1)-sum(uz)+(uz<=uy ?0:sum(NN))
  end
}
0