A

This problem asks you to handle a for loop properly.

First, let us consider how we can perform the operation against A=(A1,A2,,AN)A=(A_1,A_2,\cdots,A_N). Among various approaches, we think that updating AA in the following way is the naivest one.

  • For i=1,2,,N1i=1,2,…,N−1 in this order, “update AiAi by assigning Ai+1A_{i+1}.” (This can be implemented with a for loop with a variable ii.)
  • Update ANA_N by assigning 00.

All that left is to repeat the steps above KK times, which can also be implemented with a for loop to let the same process be executed KK times.

A sample code in Python:

N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(K):
  A = A[1:] + [0]
print(*A)

B

The theme of this problem is implementation. First, let us consider how to determine if the time hh:mm is confusing. It can be determined by the following procedure. (For more details, please refer to the sample code.)

  • Find the tens place AA and ones place BB of hh using a integral division (/ in C++ and // in Python) and a modulus operation (%).
  • Find the tens place CC and ones place DD of mm in the same way.
  • Find ACAC and BDBD using additions and multiplications.
  • Determine if AC:BDAC:BD is valid in the 2424-hour system. This can be determined by checking if 0AC230 \le AC \le 23 and 0BD590 \le BD \le 59.
  • The resulting boolean value (Yes or No) directly serves as the answer to “is h:mh:m confusing?”

Once you can determine if a time is confusing, this problem can be solved with a loop structure like a while statement. That is, it is sufficient to repeat incrementing the time by 11 as long as H:MH:M is not a confusing time. Note that, the one minute after H:MH:M is H:(M+1)H:(M+1) in most case, there may be carries, when it causes H=24H=24 or M=60M=60.

The time complexity is O((the number of distinct times represented by 24-hour clock system))$O((the number of distinct times represented by 24-hour clock system)). Since they are 1440$ such times, so we can determine it fast enough.

A sample code in Python follows.

def is_in_24_hours(h, m):
  return 0 <= h <= 23 and 0 <= m <= 59
def misjudged(h, m):
  A, B = h // 10, h % 10
  C, D = m // 10, m % 10
  AC = A * 10 + C
  BD = B * 10 + D
  return is_in_24_hours(AC, BD)
H, M = map(int, input().split())
while not misjudged(H, M):
  M += 1
  if M == 60:
    H, M = H + 1, 0
  if H == 24:
    H = 0
print(H, M)

C

Consider maintaining the follow network with a set SS. The given query can be rephrased as follows. Initially, S=S=∅.

  1. Append an ordered pair(A,B) (A,B) to the set SS. That is, let SS(A,B)S←S∪{(A,B)}.
  2. Remove an ordered pair (A,B)(A,B) from the set SS. That is, let SS(A,B)S←S∖{(A,B)}.
  3. Determine if the ordered pairs(A,B),(B,A) (A,B),(B,A) are both contained in SS.

There are N(N1)N(N−1) kinds of ordered pair that may be given from the input, but the size of the set SS is at most QQ throughout the queries, so we can manage SS with a data structure like an associative array to solve the problem.

Even if your library do not allows to use an ordered pair as the key, you may still correspond an ordered pair (A,B)(A,B) to an integer AN+BAN+B to solve this problem.

The time complexity is O(QlogQ)\mathcal{O}(Qlog⁡Q) if you use a data structure like a balanced binary search tree as an associative array, or expected O(Q)\mathcal{O}(Q)time if you use a hash table etc. .

A sample code in Python follows.

import sys

input = sys.stdin.readline
N, Q = map(int, input().split())
Set = set()
for _ in range(Q):
    t, a, b = map(int, input().split())
    if t == 1:
        Set.add((a, b))
    elif t == 2:
        if (a, b) in Set:
            Set.remove((a, b))
    else:
        if (a, b) in Set and (b, a) in Set:
            print("Yes")
        else:
            print("No")