Skip to content

Instantly share code, notes, and snippets.

@Eric-Bro
Created April 16, 2012 16:08
Show Gist options
  • Save Eric-Bro/2399691 to your computer and use it in GitHub Desktop.
Save Eric-Bro/2399691 to your computer and use it in GitHub Desktop.
Problem PA-1
input = $stdin.readline.split
n, m = input[0].to_i, input[1].to_i
$cmpts = Array.new(n){0}
def QprintEnergy(var)
var = $cmpts.inject(0){|sum, n| sum += n }
print var.to_s + "\n"
end
def Qparse_string()
parsed = $stdin.readline.split
3.downto(1){|idx| parsed[idx] = Integer(parsed[idx])}
plus, it = parsed[3], 2
if (parsed[0] == "U") then it = 1
else
parsed[1] += (parsed[1] % 2 != ((parsed[0] != "A").object_id / 2)).object_id / 2;
end
while (parsed[1] <= parsed[2]) do
$cmpts[parsed[1]-1] += ((-1) **(it)) * plus
parsed[1] += it
end
if (it == 1) then QprintEnergy(0) end
end
m.downto(1){|iter|
Qparse_string()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment