156882025-02-21 18:20:2942Színes szobák (50 pont)python3Wrong answer 0/50136ms14704 KiB
from sys import stdin, stdout
input=stdin.readline

def s():
 N,K,M = map(int,input().split())
 szobak = tuple(map(int,input().split()))
 lepesek=(tuple(map(int,input().split())) for i in range(M))

 def test(start):
  for a,b in lepesek:
   if szobak[start]==a:
    start+=b
    if start==N:
     return 1
    elif start==-1:
     return -1
  return 0

 res=0
 first=test(0)
 last=test(N-1)
 if last==1:
  if first==1:return N 
  else:
   lo=0
   hi=N-1
   while hi-lo>1:
    mid=(hi+lo)//2
    if test(mid)==1:hi=mid
    else:lo=mid
   res+=N-hi
 if first==-1:
  if last==-1:return N
  else:
   lo=0
   hi=N-1
   while hi-lo>1:
    mid=(hi+lo)//2
    if test(mid)==-1:lo=mid
    else:hi=mid
   res+=hi
 return res

stdout.write(str(s())+'\n')
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/016ms3144 KiB
2Wrong answer0/0131ms14676 KiB
3Wrong answer0/117ms3124 KiB
4Wrong answer0/117ms3124 KiB
5Wrong answer0/117ms3312 KiB
6Wrong answer0/117ms3124 KiB
7Wrong answer0/117ms3320 KiB
8Wrong answer0/117ms3300 KiB
9Wrong answer0/117ms3124 KiB
10Wrong answer0/118ms3400 KiB
11Wrong answer0/117ms3260 KiB
12Wrong answer0/118ms3392 KiB
13Wrong answer0/127ms3380 KiB
14Wrong answer0/119ms3636 KiB
15Wrong answer0/119ms3892 KiB
16Wrong answer0/126ms3724 KiB
17Wrong answer0/128ms3904 KiB
18Wrong answer0/127ms3748 KiB
19Wrong answer0/178ms14676 KiB
20Wrong answer0/1136ms14704 KiB
21Wrong answer0/1100ms14636 KiB
22Wrong answer0/1108ms14576 KiB
23Wrong answer0/1123ms14676 KiB
24Wrong answer0/1130ms14612 KiB
25Wrong answer0/1136ms14676 KiB
26Wrong answer0/1134ms14676 KiB
27Wrong answer0/3128ms9904 KiB
28Wrong answer0/3128ms9904 KiB
29Wrong answer0/3128ms9988 KiB
30Wrong answer0/3129ms9780 KiB
31Wrong answer0/3128ms9904 KiB
32Wrong answer0/3127ms9936 KiB
33Wrong answer0/474ms6752 KiB
34Wrong answer0/4119ms6656 KiB