253892026-02-19 18:09:15miszorimarciSzínes szobák (50 pont)cpp17Accepted 50/5086ms1780 KiB
#include <bits/stdc++.h>
using namespace std;

int n, k, m;
vector<int>v;
vector<pair<int, int>>op;

bool check1(int pos)
{
    for(auto [c, x] : op)
    {
        if(c == v[pos])pos += x;
        if(pos == -1)return 1;
        if(pos == n)return 0;
    }
    return 0;
}
bool check2(int pos)
{
    for(auto [c, x] : op)
    {
        if(c == v[pos])pos += x;
        if(pos == -1)return 0;
        if(pos == n)return 1;
    }
    return 0;
}

int main() {
	cin >> n >> k >> m;
    int ans = 0;
    v.resize(n);
    op.resize(m);
    for(int &i : v)cin >> i;
    for(auto &p : op)cin >> p.first >> p.second;
    int l = -1, r = n;
    while(l < r-1)
    {
        int mid = (l+r)/2;
        if(check1(mid))l = mid;
        else r = mid;
    }
    ans += l+1;
    //cout << l << " ";
    l = -1, r = n;
    while(l < r-1)
    {
        int mid = (l+r)/2;
        if(check2(mid))r = mid;
        else l = mid;
    }
    //cout << r << " ";
    ans += n-r;
    cout << ans;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/086ms1604 KiB
3Accepted1/12ms316 KiB
4Accepted1/12ms316 KiB
5Accepted1/12ms316 KiB
6Accepted1/12ms508 KiB
7Accepted1/12ms316 KiB
8Accepted1/11ms316 KiB
9Accepted1/11ms316 KiB
10Accepted1/12ms316 KiB
11Accepted1/11ms316 KiB
12Accepted1/12ms420 KiB
13Accepted1/17ms316 KiB
14Accepted1/14ms444 KiB
15Accepted1/14ms508 KiB
16Accepted1/17ms504 KiB
17Accepted1/18ms588 KiB
18Accepted1/18ms520 KiB
19Accepted1/150ms1076 KiB
20Accepted1/182ms1588 KiB
21Accepted1/161ms1276 KiB
22Accepted1/167ms1348 KiB
23Accepted1/178ms1332 KiB
24Accepted1/182ms1588 KiB
25Accepted1/182ms1336 KiB
26Accepted1/182ms1332 KiB
27Accepted3/375ms1588 KiB
28Accepted3/375ms1388 KiB
29Accepted3/375ms1332 KiB
30Accepted3/375ms1780 KiB
31Accepted3/375ms1336 KiB
32Accepted3/375ms1332 KiB
33Accepted4/437ms996 KiB
34Accepted4/463ms1392 KiB