156482025-02-21 16:27:10999Színes szobák (50 pont)cpp17Wrong answer 31/5086ms2740 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF=1e12;

signed main() {
    int n,k,q;cin>>n>>k>>q;
    vector<int> v(n);
    for(int i = 0;i<n;i++){
        cin>>v[i];
    }
    vector<pair<int,int>> que(q);
    for(auto&[a,b]:que)cin>>a>>b;
    int l=-1,m,h=n;
    while(l<h-1){
        m=(l+h)/2;
        int ind=m;
        bool jo=false;
        for(auto[a,b]:que){
            if(v[ind]==a)ind+=b;
            if(ind==-1||ind==n){
                jo=ind==-1;
                break;
            }
        }
        if(jo){
            l=m;
        }
        else{
            h=m;
        }
    }
    int bal=l;
    h=-1,l=n;
    while(h+1<l){
        m=(l+h)/2;
        int ind=m;
        bool jo=false;
        for(auto[a,b]:que){
            if(v[ind]==a)ind+=b;
            if(ind==n||ind==-1){
                jo=ind==n;
                break;
            }
        }
        if(jo){
            l=m;
        }
        else{
            h=m;
        }
    }
    cout<<n-m+bal+1<<endl;
}
SubtaskSumTestVerdictTimeMemory
base31/50
1Accepted0/01ms316 KiB
2Wrong answer0/086ms2576 KiB
3Wrong answer0/12ms316 KiB
4Wrong answer0/12ms316 KiB
5Accepted1/11ms316 KiB
6Wrong answer0/12ms316 KiB
7Accepted1/12ms424 KiB
8Wrong answer0/11ms316 KiB
9Wrong answer0/11ms316 KiB
10Wrong answer0/12ms316 KiB
11Accepted1/12ms428 KiB
12Accepted1/12ms316 KiB
13Accepted1/17ms432 KiB
14Wrong answer0/14ms460 KiB
15Accepted1/14ms316 KiB
16Accepted1/17ms804 KiB
17Accepted1/18ms652 KiB
18Accepted1/18ms564 KiB
19Wrong answer0/150ms1708 KiB
20Accepted1/181ms2612 KiB
21Wrong answer0/163ms2136 KiB
22Wrong answer0/165ms2220 KiB
23Wrong answer0/175ms2612 KiB
24Wrong answer0/182ms2736 KiB
25Accepted1/181ms2728 KiB
26Accepted1/182ms2736 KiB
27Accepted3/375ms2612 KiB
28Accepted3/375ms2732 KiB
29Accepted3/375ms2740 KiB
30Wrong answer0/375ms2740 KiB
31Accepted3/375ms2736 KiB
32Accepted3/375ms2612 KiB
33Wrong answer0/437ms1572 KiB
34Accepted4/461ms2356 KiB