Created
July 30, 2017 04:04
-
-
Save whatalnk/4c4cd32fe7763ce8f2490f3d5d4bef18 to your computer and use it in GitHub Desktop.
AtCoder Chokudai Speed Run #001
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
arr = gets.chomp.split(" ").map(&:to_i) | |
puts arr.max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
arr = gets.chomp.split(" ").map(&:to_i) | |
puts arr.inject(:+) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
arr = gets.chomp.split(" ").map(&:to_i) | |
puts arr.join(",") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
arr = gets.chomp.split(" ").map(&:to_i) | |
puts arr.sort.join(" ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
arr = gets.chomp.split(" ").map(&:to_i) | |
puts arr.index(1) + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
arr = gets.chomp.split(" ").map(&:to_i) | |
ret = 1 | |
amax = arr[0] | |
(1...n).each do |i| | |
ret += 1 if amax < arr[i] | |
amax = [amax, arr[i]].max | |
end | |
puts ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
arr = gets.chomp.split(" ").join("").to_i | |
puts arr % 1000000007 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
arr = gets.chomp.split(" ").map(&:to_i) | |
arr2 = Array.new(n+1, 10**6) | |
ret = 0 | |
arr.each do |a| | |
i = arr2.bsearch_index{|x| x > a} | |
if i.nil? then | |
i = 0 | |
end | |
arr2[i] = a | |
ret = [ret, i].max | |
end | |
puts ret + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
arr = gets.chomp.split(" ").map(&:to_i) | |
cumsum = [0] | |
n.times do |i| | |
cumsum << cumsum[i] + arr[i] | |
end | |
ret = 0 | |
n.times do |i| | |
((i+1)..n).each do |j| | |
asum = cumsum[j] - cumsum[i] | |
if asum > n then | |
break | |
elsif asum == n then | |
ret += 1 | |
end | |
end | |
end | |
puts ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
arr = gets.chomp.split(" ").map(&:to_i) | |
class BIT | |
attr_reader :bit | |
def initialize(n) | |
@n = n | |
@bit = Array.new(@n + 1, 0) | |
end | |
def sum(i) | |
s = 0 | |
while i > 0 | |
s += @bit[i] | |
i -= i & -i | |
end | |
return s | |
end | |
def add(i, x) | |
# i += 1 | |
while i <= @n | |
@bit[i] += x | |
i += i & -i | |
end | |
end | |
end | |
ans = 0 | |
bit = BIT.new(n) | |
n.times do |j| | |
ans += j - bit.sum(arr[j]) | |
bit.add(arr[j], 1) | |
end | |
puts ans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
arr = gets.chomp.split(" ").map(&:to_i) | |
class BIT | |
attr_reader :bit | |
def initialize(n) | |
@n = n | |
@bit = Array.new(@n + 1, 0) | |
end | |
def sum(i) | |
s = 0 | |
while i > 0 | |
s += @bit[i] | |
i -= i & -i | |
end | |
return s | |
end | |
def add(i, x) | |
i += 1 | |
while i <= @n | |
@bit[i] += x | |
i += i & -i | |
end | |
end | |
end | |
p_ = 10**9 + 7 | |
perm = Array.new(n+1, 1) | |
(1..n).each do |i| | |
perm[i] = perm[i-1] * i % p_ | |
end | |
result = 1 | |
bit = BIT.new(n) | |
arr.reverse.each_with_index do |a, i| | |
result += bit.sum(a) * perm[i] | |
result %= p_ | |
bit.add(a, 1) | |
end | |
puts result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
arr = gets.chomp.split(" ").map(&:to_i) | |
class BIT | |
attr_reader :bit | |
def initialize(n) | |
@n = n | |
@bit = Array.new(@n + 1, 0) | |
end | |
def sum(i) | |
s = 0 | |
while i > 0 | |
s += @bit[i] | |
i -= i & -i | |
end | |
return s | |
end | |
def add(i, x) | |
# i += 1 | |
while i <= @n | |
@bit[i] += x | |
i += i & -i | |
end | |
end | |
end | |
ans = 0 | |
bit = BIT.new(n) | |
n.times do |j| | |
ans += j - bit.sum(arr[j]) | |
bit.add(arr[j], 1) | |
end | |
if (n - ans).even? | |
puts "YES" | |
else | |
puts "NO" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment