LoginSignup
0
0

'I' の数 (paizaランク B 相当)

Posted at

やってることは累積和の差し引きをして、その数を比較するだけのもの。
もうすこし累積和の特徴を知っておかなくては。。。

N,K = map(int,input().split())
A = [int(input()) for _ in range(N)]
# 累積和を求める
ans = [0] + A[:]
for i in range(1,N+1):
    ans[i] += ans[i-1]

for _ in range(K):
    a_left,a_right,b_left,b_right = map(int,input().split())

    # 累積和の足し引きで可能。ただしleftは−1引く必要がある
    a = ans[a_right] - ans[a_left - 1]
    b = ans[b_right] - ans[b_left - 1]
    
    #ルール確認・相手も反則してなければ必ず負けるようにする
    if a_right - a_left + 1 >= N/3:
        a = -1 
    if b_right - b_left + 1 >= N/3:
        b = -1 
 
    #判定
    if a == b:
        print("DRAW")
    elif a > b:
        print("A")
    else:
        print("B")

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0