89342024-02-05 18:29:42NagyLeoSzínes szobák (50 pont)python3Elfogadva 50/50234ms48880 KiB
from sys import stdin, stdout

input = stdin.readline

def print(x):
    stdout.write(str(x) + "\n")


def main():
    N, K, M = map(int, input().split())
    rooms_raw = list(map(int, input().split()))
    rooms = []

    for i in rooms_raw:
        rooms.append([i, 1])

    left_people = 0
    for i in range(M):
        color, direct = map(int, input().split())

        for j in range(N):
            if rooms[j][0] == color:
                if j + direct > N - 1 or j + direct < 0:
                    left_people += rooms[j][1]
                    rooms[j][1] = 0
                else:
                    rooms[j + direct][1] += rooms[j][1]
                    rooms[j][1] = 0
    print(left_people)


def main2():
    N, K, M = map(int, input().split())
    rooms = [int(x) for x in input().split()]

    left_people = 0
    rules=[0]*M
    for i in range(M):
        rules[i]=[int(x) for x in input().split()]

    def kijute(i):
        # az i. emberrel mi tortenik?
        # balra, nem jut ki , jobbra  -1, 0, 1

        for j in range(M):
            if rooms[i] == rules[j][0]:
                i += rules[j][1]
                if i > N - 1:
                    return 1
                elif i < 0:
                    return -1

        return 0

    elso = kijute(0)
    utolso = kijute(N - 1)
    # jobbra:
    lo = 0
    hi = N - 1
    if elso == 1:
        print(N)
        return
    if utolso != 1:
        pass
    else:
        while hi - lo > 1:
            half = (hi + lo) // 2
            if kijute(half) == 1:
                hi = half
            else:
                lo = half
        left_people += N - hi
    # balra:
    lo = 0
    hi = N - 1
    if utolso == -1:
        print(N)
        return
    if elso != -1:
        pass
    else:
        while hi - lo > 1:
            half = (hi + lo) // 2
            if kijute(half) == -1:
                lo = half
            else:
                hi = half
        left_people += hi

    print(left_people)


def main3():
    N, K, M = map(int, input().split())
    rooms = [0] + [int(x) for x in input().split()] + [0]

    left_people = 0
    rules = [0] * M
    for i in range(M):
        rules[i] = [int(x) for x in input().split()]

    left_pos = 0
    right_pos = N + 1
    for i in range(M - 1, -1, -1):
        if rules[i][1] == -1 and rules[i][0] == rooms[left_pos + 1]:
            left_pos += 1
        if rules[i][1] == 1 and rules[i][0] == rooms[left_pos]:
            left_pos -= 1
        if rules[i][1] == 1 and rules[i][0] == rooms[right_pos - 1]:
            right_pos -= 1
        if rules[i][1] == -1 and rules[i][0] == rooms[right_pos]:
            right_pos += 1
    print(left_pos + (N + 1 - right_pos))


main3()
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/018ms11888 KiB
2Elfogadva0/0231ms47260 KiB
3Elfogadva1/119ms12544 KiB
4Elfogadva1/119ms12556 KiB
5Elfogadva1/119ms12480 KiB
6Elfogadva1/119ms12492 KiB
7Elfogadva1/119ms13060 KiB
8Elfogadva1/120ms13156 KiB
9Elfogadva1/121ms13032 KiB
10Elfogadva1/124ms14032 KiB
11Elfogadva1/120ms13556 KiB
12Elfogadva1/123ms14092 KiB
13Elfogadva1/137ms16468 KiB
14Elfogadva1/125ms14936 KiB
15Elfogadva1/126ms14940 KiB
16Elfogadva1/135ms16284 KiB
17Elfogadva1/139ms16556 KiB
18Elfogadva1/139ms16600 KiB
19Elfogadva1/1122ms36368 KiB
20Elfogadva1/1231ms48804 KiB
21Elfogadva1/1155ms38880 KiB
22Elfogadva1/1172ms41480 KiB
23Elfogadva1/1214ms46256 KiB
24Elfogadva1/1232ms48880 KiB
25Elfogadva1/1232ms48656 KiB
26Elfogadva1/1231ms48788 KiB
27Elfogadva3/3229ms43136 KiB
28Elfogadva3/3231ms43104 KiB
29Elfogadva3/3230ms42896 KiB
30Elfogadva3/3231ms43148 KiB
31Elfogadva3/3234ms42876 KiB
32Elfogadva3/3231ms43004 KiB
33Elfogadva4/4122ms28516 KiB
34Elfogadva4/4216ms41100 KiB