結果

問題 No.151 セグメントフィッシング
ユーザー gigurururugigurururu
提出日時 2015-02-17 18:29:07
言語 Ruby
(3.2.2)
結果
AC  
実行時間 242 ms / 5,000 ms
コード長 437 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 11,244 KB
実行使用メモリ 15,740 KB
最終ジャッジ日時 2023-08-26 23:12:59
合計ジャッジ時間 5,196 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,228 KB
testcase_01 AC 83 ms
15,052 KB
testcase_02 AC 82 ms
15,328 KB
testcase_03 AC 82 ms
15,292 KB
testcase_04 AC 81 ms
15,356 KB
testcase_05 AC 83 ms
15,156 KB
testcase_06 AC 85 ms
15,028 KB
testcase_07 AC 85 ms
15,348 KB
testcase_08 AC 102 ms
15,228 KB
testcase_09 AC 105 ms
15,360 KB
testcase_10 AC 104 ms
15,544 KB
testcase_11 AC 102 ms
15,476 KB
testcase_12 AC 170 ms
15,572 KB
testcase_13 AC 170 ms
15,524 KB
testcase_14 AC 169 ms
15,740 KB
testcase_15 AC 170 ms
15,536 KB
testcase_16 AC 172 ms
15,468 KB
testcase_17 AC 134 ms
15,600 KB
testcase_18 AC 118 ms
15,572 KB
testcase_19 AC 232 ms
15,576 KB
testcase_20 AC 242 ms
15,568 KB
testcase_21 AC 138 ms
15,528 KB
testcase_22 AC 136 ms
15,604 KB
testcase_23 AC 152 ms
15,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
Q.times{|t|
  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