Skip to content

1807

Codeforces Round 859 (Div. 4)

TODO: F, G1, G2

A_Plus_or_Minus

1
2
3
4
5
t = int(input())

for _ in range(t):
    a, b, c = map(int, input().split())
    print("+" if a + b == c else "-")

B_Grab_the_Candies

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
t = int(input())

for _ in range(t):
    n = int(input())
    ar = list(map(int, input().split()))

    m = 0
    b = 0

    if n == 1:
        print("YES" if ar[0] % 2 == 0 else "NO")
    else:
        for x in ar:
            if x % 2 == 0:
                m += x
            else:
                b += x
        print("YES" if m > b else "NO")

C_Find_and_Replace

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
t = int(input())

for _ in range(t):
    n = int(input())
    s = input()

    reserved_binaries = {}
    binary_values = []

    for c in s:
        val = reserved_binaries.get(c, None)

        if not binary_values:
            binary_values.append(1)

        if val == binary_values[-1]:
            print("NO")
            break

        if not val:
            val = 1 if binary_values[-1] == 0 else 0
        reserved_binaries[c] = val

        binary_values.append(val)
    else:
        print("YES")

D_Odd_Queries

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
t = int(input())

for _ in range(t):
    n, q = map(int, input().split())
    array = list(map(int, input().split()))
    prefix_sum = [0] * (n + 1)

    for i, a in enumerate(array):
        prefix_sum[i + 1] = a + prefix_sum[i]

    results = []
    for _ in range(q):
        l, r, k = map(int, input().split())
        l -= 1
        r -= 1
        sum_modified = (
            prefix_sum[l] + (r - l + 1) * k + prefix_sum[-1] - prefix_sum[r + 1]
        )

        if sum_modified % 2 == 1:
            results.append("YES")
        else:
            results.append("NO")

    print("\n".join(results))

E_Interview

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
t = int(input())

for _ in range(t):
    n = int(input())
    piles = list(map(int, input().split()))

    prefix_sum = [0]
    for pile in piles:
        prefix_sum.append(prefix_sum[-1] + pile)

    left = 1
    right = n

    # Binary search to find the pile with the special stone
    while right > left:
        mid = (right + left) // 2

        query_piles = list(range(left, mid + 1))

        # Send the query and flush the output
        print("?", len(query_piles), *query_piles, flush=True)

        total_weight = int(input())

        # Check which half the special stone is in
        if total_weight == prefix_sum[mid] - prefix_sum[left - 1]:
            left = mid + 1
        else:
            right = mid

    # Output the index of the pile with the special stone
    print("!", (left + right) // 2, flush=True)

F_Bouncy_Ball

1

G_1_Subsequence_Addition_Easy_Version

1

G_2_Subsequence_Addition_Hard_Version

1