156582025-02-21 17:10:1742Színes szobák (50 pont)pypy3Runtime error 20/50108ms32000 KiB
from sys import stdin
input=stdin.readline

def s():
 N,K,M = map(int,input().split())
 szobak = list(map(int,input().split()))
 lepesek=[0]*M
 for i in range(M):
  lepesek[i]=list(map(int,input().split()))

 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:
   print(N)
   return
  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:
   print(N)
   return
  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
 print(res)

s()
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/045ms19876 KiB
2Runtime error0/068ms32000 KiB
3Accepted1/159ms21656 KiB
4Accepted1/154ms21452 KiB
5Accepted1/154ms21496 KiB
6Accepted1/163ms21512 KiB
7Accepted1/163ms21468 KiB
8Accepted1/161ms21588 KiB
9Accepted1/154ms21480 KiB
10Accepted1/168ms22160 KiB
11Accepted1/159ms21436 KiB
12Accepted1/159ms21948 KiB
13Accepted1/174ms23144 KiB
14Accepted1/157ms22376 KiB
15Accepted1/164ms22268 KiB
16Accepted1/161ms22636 KiB
17Accepted1/164ms23428 KiB
18Accepted1/179ms23524 KiB
19Runtime error0/174ms32000 KiB
20Runtime error0/165ms32000 KiB
21Runtime error0/165ms32000 KiB
22Runtime error0/179ms32000 KiB
23Runtime error0/165ms32000 KiB
24Runtime error0/175ms32000 KiB
25Runtime error0/176ms32000 KiB
26Runtime error0/168ms32000 KiB
27Runtime error0/365ms32000 KiB
28Runtime error0/375ms32000 KiB
29Runtime error0/367ms32000 KiB
30Runtime error0/378ms32000 KiB
31Runtime error0/376ms32000 KiB
32Runtime error0/378ms32000 KiB
33Accepted4/4108ms29948 KiB
34Runtime error0/497ms32000 KiB